home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / utility / misc / fileutil.lha / fileutils-3.3 / src / mkfifo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-02  |  2.4 KB  |  111 lines

  1. /* mkfifo -- make fifo's (named pipes)
  2.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Options:
  19.    -m, --mode=mode    Set the mode of created fifo's to MODE, which is
  20.             symbolic as in chmod and uses the umask as a point of
  21.             departure.
  22.  
  23.    David MacKenzie <djm@ai.mit.edu>  */
  24.  
  25. #include <stdio.h>
  26. #include <getopt.h>
  27. #include <sys/types.h>
  28. #include "system.h"
  29. #include "modechange.h"
  30.  
  31. void error ();
  32. void strip_trailing_slashes ();
  33. void usage ();
  34.  
  35. /* The name this program was run with. */
  36. char *program_name;
  37.  
  38. struct option longopts[] =
  39. {
  40.   {"mode", 1, NULL, 'm'},
  41.   {NULL, 0, NULL, 0}
  42. };
  43.  
  44. void
  45. main (argc, argv)
  46.      int argc;
  47.      char **argv;
  48. {
  49.   unsigned short newmode;
  50.   struct mode_change *change;
  51.   char *symbolic_mode;
  52.   int errors = 0;
  53.   int optc;
  54.  
  55.   program_name = argv[0];
  56.   symbolic_mode = NULL;
  57.  
  58. #ifndef S_ISFIFO
  59.   error (4, 0, "fifo files not supported");
  60. #else
  61.   while ((optc = getopt_long (argc, argv, "m:", longopts, (int *) 0)) != EOF)
  62.     {
  63.       switch (optc)
  64.     {
  65.     case 'm':
  66.       symbolic_mode = optarg;
  67.       break;
  68.     default:
  69.       usage ();
  70.     }
  71.     }
  72.  
  73.   if (optind == argc)
  74.     usage ();
  75.   
  76.   newmode = 0666 & ~umask (0);
  77.   if (symbolic_mode)
  78.     {
  79.       change = mode_compile (symbolic_mode, 0);
  80.       if (change == MODE_INVALID)
  81.     error (1, 0, "invalid mode");
  82.       else if (change == MODE_MEMORY_EXHAUSTED)
  83.     error (1, 0, "virtual memory exhausted");
  84.       newmode = mode_adjust (newmode, change);
  85.     }
  86.  
  87.   for (; optind < argc; ++optind)
  88.     {
  89.       strip_trailing_slashes (argv[optind]);
  90.       if (mkfifo (argv[optind], newmode))
  91.     {
  92.       error (0, errno, "cannot make fifo `%s'", argv[optind]);
  93.       errors = 1;
  94.     }
  95.     }
  96.  
  97.   exit (errors);
  98. #endif
  99. }
  100.  
  101. #ifdef S_ISFIFO
  102. void
  103. usage ()
  104. {
  105.   fprintf (stderr, "\
  106. Usage: %s [-m mode] [--mode=mode] path...\n",
  107.        program_name);
  108.   exit (1);
  109. }
  110. #endif
  111.