Merge Unix and RISC OS makefiles
[debian-nspark.git] / winnt.c
blobc6c6011c4d0a5a7c3e255cac9e3a211dad032f13
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>
20 * return the length of a file
22 Word
23 filesize(char *pathname)
25 struct stat statb;
27 if (stat(pathname, &statb) < 0)
28 return 0;
29 return (Word) statb.st_size;;
33 * test for the existance of a file or directory
35 Ftype
36 exist(char *pathname)
38 struct stat statb;
40 if (stat(pathname, &statb) < 0)
41 return NOEXIST;
43 if (statb.st_mode & S_IFDIR)
44 return ISDIR;
46 return (ISFILE);
50 * make a directory
52 int
53 makedir(char *pathname)
55 return mkdir(pathname);
59 * stamp a file with date and time
61 int
62 filestamp(Header *header, char *filename)
64 Date *date;
65 struct tm tm;
66 struct utimbuf utimbuf;
67 time_t filetime;
69 if (exist(filename) == ISDIR)
70 return (0); /* Win NT appears not to allow stamping dirs. */
72 if ((header->load & (Word) 0xfff00000) != (Word) 0xfff00000)
73 return (0); /* not a timestamp */
75 memset((char *) &tm, '\0', sizeof(tm));
77 if (!(date = makedate(header)))
78 return (-1);
80 tm.tm_sec = date->second;
81 tm.tm_min = date->minute;
82 tm.tm_hour = date->hour;
83 tm.tm_mday = date->day;
84 tm.tm_mon = date->month - 1;
85 tm.tm_year = date->year;
86 filetime = mktime(&tm);
88 utimbuf.actime = filetime;
89 utimbuf.modtime = filetime;
90 return (utime(filename, &utimbuf));