home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / utils / dtou.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-12  |  1.1 KB  |  60 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3. #include <dir.h>
  4. #include <dos.h>
  5. #include <fcntl.h>
  6. #include <sys/stat.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10.  
  11. typedef struct F {
  12.     char *name;
  13.     struct F *next;
  14.     } F;
  15.  
  16. static int
  17. dtou(char *fname)
  18. {
  19.   int sf, df, l;
  20.   char buf[16384];
  21.   char tfname[80], drive[3], path[80];
  22.   struct ftime ftime;
  23.   sf = open(fname, O_RDONLY|O_TEXT);
  24.   if (sf < 1)
  25.   {
  26.     perror(fname);
  27.     return 1;
  28.   }
  29.   fnsplit(fname, drive, path, NULL, NULL);
  30.   fnmerge(tfname, drive, path, "utod", "tm$");
  31.   df = open(tfname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
  32.   if (df < 1)
  33.   {
  34.     perror(tfname);
  35.     close(sf);
  36.     return 1;
  37.   }
  38.  
  39.   while ((l=read(sf, buf, 16384)) > 0)
  40.     write(df, buf, l);
  41.  
  42.   getftime(sf, &ftime);
  43.   setftime(df, &ftime);
  44.   close(sf);
  45.   close(df);
  46.  
  47.   remove(fname);
  48.   rename(tfname, fname);
  49.   return 0;
  50. }
  51.  
  52. int
  53. main(int argc, char **argv)
  54. {
  55.   int rv = 0;
  56.   for (argc--, argv++; argc; argc--, argv++)
  57.     rv += dtou(*argv);
  58.   return rv;
  59. }
  60.