home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 December / simtel1292_SIMTEL_1292_Walnut_Creek.iso / msdos / sysutl / picnix32.arc / MAKE.ARC / TOUCH.C < prev   
Text File  |  1986-01-30  |  2KB  |  46 lines

  1. #include <fcntl.h>
  2. #include <stdio.h>
  3. #include <sys/types.h>
  4. #include <sys/stat.h>
  5. #include <io.h>
  6. #define ERROR -1
  7.  
  8. usage(){
  9.         puts("usage :    touch file ...");
  10.         exit (1);
  11.         }
  12.  
  13. main(argc,argv)
  14.         char **argv;{
  15.         int f,i;
  16.         char ch[1];
  17.         if (argc == 1) usage();
  18.         for (i=1; i<argc; i++) {
  19.             if (ERROR != (f = open(argv[i], O_CREAT | O_EXCL, S_IWRITE | S_IREAD))) {
  20.                  /* we've created it */
  21.                  if (ERROR != close(f)) continue;
  22.                  puts("Can't close file"), exit(3);
  23.                  }
  24.             if (ERROR != (f = open(argv[i], O_RDWR | O_BINARY)))
  25.                  /* we've opened it */
  26.                  if (1 == read(f,ch,1)) {
  27.                       /* we've read one character */
  28.                       lseek(f,0L,0);    /* rewind */
  29.                       if (1 == write(f,ch,1)) { close(f); continue; }
  30.                       puts("Can't write to file."), exit(5);
  31.                       }
  32.                  else {
  33.                       /* we know the file has length 0 */
  34.                       close(f);
  35.                       if (ERROR != (f = open(argv[i], O_TRUNC, S_IWRITE | S_IREAD))) { close(f); continue; }
  36.                       puts("Can't truncate file"), exit(7);
  37.                       }
  38.             else puts("Can't open file"), exit(4);
  39.             }
  40.         exit(0);
  41.         }
  42.  
  43. _setenvp(){}  /* don't use envp arg */
  44.  
  45. _nullcheck(){}  /* don't check for null pointer assignments */
  46.