Merge pull request #12 from davel/davel/sqsh
[debian-nspark.git] / winnt.c
blob3f090c8922ba65c8dacbe194eb86da0b5c33b496
2 /*
3 * Operating System specific function (Windows NT)
5 * $Header: winnt.c 1.0 94/11/09 $
6 * $Log: winnt.c,v $
7 * Revision 1.0 94/11/09 10:04:00 auj
8 * Initial revision
9 *
12 #include "spark.h"
13 #include "date.h"
14 #include <sys/stat.h>
15 #include <sys/utime.h>
16 #include <time.h>
17 #include <direct.h>
18 #include <string.h>
21 * return the length of a file
23 Word
24 filesize(char *pathname)
26 struct stat statb;
28 if (stat(pathname, &statb) < 0)
29 return 0;
30 return (Word) statb.st_size;;
34 * test for the existance of a file or directory
36 Ftype
37 exist(char *pathname)
39 struct stat statb;
41 if (stat(pathname, &statb) < 0)
42 return NOEXIST;
44 if (statb.st_mode & S_IFDIR)
45 return ISDIR;
47 return (ISFILE);
51 * make a directory
53 int
54 makedir(char *pathname)
56 return _mkdir(pathname);
60 * stamp a file with date and time
62 int
63 filestamp(Header *header, char *filename)
65 Date *date;
66 struct tm tm;
67 struct utimbuf utimbuf;
68 time_t filetime;
70 if (exist(filename) == ISDIR)
71 return (0); /* Win NT appears not to allow stamping dirs. */
73 if ((header->load & (Word) 0xfff00000) != (Word) 0xfff00000)
74 return (0); /* not a timestamp */
76 memset((char *) &tm, '\0', sizeof(tm));
78 if (!(date = makedate(header)))
79 return (-1);
81 tm.tm_sec = date->second;
82 tm.tm_min = date->minute;
83 tm.tm_hour = date->hour;
84 tm.tm_mday = date->day;
85 tm.tm_mon = date->month - 1;
86 tm.tm_year = date->year;
87 filetime = mktime(&tm);
89 utimbuf.actime = filetime;
90 utimbuf.modtime = filetime;
91 return (utime(filename, &utimbuf));