home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume30 / rc / part02 / open.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-30  |  703 b   |  30 lines

  1. /* open.c: to insulate <fcntl.h> from the rest of rc. */
  2.  
  3. #include <fcntl.h>
  4. #include "rc.h"
  5.  
  6. /* prototype for open() follows. comment out if necessary */
  7.  
  8. /*extern int open(const char *, int,...);*/
  9.  
  10. /*
  11.    Opens a file with the necessary flags. Assumes the following
  12.    declaration for redirtype:
  13.  
  14.     enum redirtype {
  15.         rFrom, rCreate, rAppend, rHeredoc, rHerestring
  16.     };
  17. */
  18.  
  19. static const int mode_masks[] = {
  20.     /* rFrom */    O_RDONLY,
  21.     /* rCreate */    O_TRUNC | O_CREAT | O_WRONLY,
  22.     /* rAppend */    O_APPEND | O_CREAT | O_WRONLY
  23. };
  24.  
  25. extern int rc_open(const char *name, redirtype m) {
  26.     if ((unsigned) m >= arraysize(mode_masks))
  27.         panic("bad mode passed to rc_open");
  28.     return open(name, mode_masks[m], 0666);
  29. }
  30.