home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / nspark / winnt_c < prev   
Encoding:
Text File  |  1994-12-13  |  1.7 KB  |  100 lines

  1. /*
  2.  * Operating System specific function (Windows NT)
  3.  *
  4.  * $Header: winnt.c 1.0 94/11/09 $
  5.  * $Log:    winnt.c,v $
  6.  * Revision 1.0  94/11/09  10:04:00  auj
  7.  * Initial revision
  8.  * 
  9.  */
  10.  
  11. #include "spark.h"
  12. #include "date.h"
  13. #include <sys/stat.h>
  14. #include <sys/utime.h>
  15. #include <time.h>
  16. #include <direct.h>
  17.  
  18. #ifdef UNIX
  19. static char rcsid[] = "$Header: winnt.c 1.0 94/11/09 $";
  20. #endif
  21.  
  22. /*
  23.  * return the length of a file
  24.  */
  25. Word
  26. filesize(pathname)
  27.     char *pathname;
  28. {
  29.     struct stat statb;
  30.  
  31.     if (stat(pathname, &statb) < 0)
  32.         return 0;
  33.     return (Word)statb.st_size;;
  34. }
  35.  
  36. /*
  37.  * test for the existance of a file or directory
  38.  */
  39. Ftype
  40. exist(pathname)
  41.     char *pathname;
  42. {
  43.     struct stat statb;
  44.  
  45.     if (stat(pathname, &statb) < 0)
  46.         return NOEXIST;
  47.  
  48.     if (statb.st_mode & S_IFDIR)
  49.         return ISDIR;
  50.  
  51.     return (ISFILE);
  52. }
  53.     
  54. /*
  55.  * make a directory
  56.  */
  57. int
  58. makedir(pathname)
  59.     char *pathname;
  60. {
  61.     return mkdir(pathname);
  62. }
  63.  
  64. /*
  65.  * stamp a file with date and time
  66.  */
  67. int
  68. filestamp(header, filename)
  69.     Header *header;
  70.     char *filename;
  71. {
  72.     Date *date;
  73.     struct tm tm;
  74.     struct utimbuf utimbuf;
  75.     time_t filetime;
  76.  
  77.     if (exist(filename) == ISDIR)
  78.         return (0); /* Win NT appears not to allow stamping dirs. */
  79.  
  80.     if ((header->load & (Word)0xfff00000) != (Word)0xfff00000)
  81.         return (0);    /* not a timestamp */
  82.  
  83.     memset((char *)&tm, '\0', sizeof(tm));
  84.  
  85.     if (!(date = makedate(header)))
  86.         return (-1);
  87.  
  88.     tm.tm_sec = date->second;
  89.     tm.tm_min = date->minute;
  90.     tm.tm_hour = date->hour;
  91.     tm.tm_mday = date->day;
  92.     tm.tm_mon = date->month - 1;
  93.     tm.tm_year = date->year;
  94.     filetime = mktime(&tm);
  95.  
  96.     utimbuf.actime = filetime;
  97.     utimbuf.modtime = filetime;
  98.     return (utime(filename, &utimbuf));
  99. }
  100.