home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / SMALL_C / FOPEN.C < prev    next >
Text File  |  1987-10-04  |  768b  |  27 lines

  1. #define NOCCARGC  /* no arg count passing */
  2. #include stdio.h
  3. #include clib.def
  4. /*
  5. ** Open file indicated by fn.
  6. ** Entry: fn   = ASCIIZ file name.
  7. **               May be prefixed by letter of drive.
  8. **               May be just CON:, RDR:, PUN:, or LST:.
  9. **        mode = "a"  - append
  10. **               "r"  - read
  11. **               "w"  - write
  12. **               "u"  - update
  13. ** Returns a file descriptor on success, else NULL.
  14. */
  15. fopen(fn, mode) char *fn, *mode; {
  16.   int fd;
  17.   fd = 0; /* skip stdin (= error return) */
  18.   while(++fd < MAXFILES) {
  19.     if(Umode(fd) == NULL) {
  20.       if((fd=Uopen(fn, mode, fd))!=ERR) return (fd);
  21.       break;
  22.       }
  23.     }
  24.   return (NULL);
  25.   }
  26.  
  27.