Merge pull request #8 from ccawley2011/includes
[debian-nspark.git] / msdos.c
blob989a53ee409b577c12633d337db474ac00335376
2 /*
3 * Operating System specific function (DOS)
5 * $Header: msdos.c 1.0 95/07/21 $
6 * $Log: msdos.c,v $
7 * Revision 1.0 95/07/21 xx:xx:xx BB
8 * Initial revision, based on winnt.c.
12 #include "spark.h"
13 #include "date.h"
14 #include <sys\stat.h>
15 #include <dir.h>
16 #include <time.h>
17 #include <utime.h>
18 #include <string.h> /* for memset */
19 #include "os.h"
22 * return the length of a file
24 Word
25 filesize(char *pathname)
27 struct stat statb;
29 if (stat(pathname, &statb) < 0)
30 return 0;
32 return (Word) statb.st_size;;
36 * test for the existance of a file or directory
38 Ftype
39 exist(char *pathname)
41 struct stat statb;
43 if (stat(pathname, &statb) < 0)
44 return NOEXIST;
46 if (statb.st_mode & S_IFDIR)
47 return ISDIR;
49 return (ISFILE);
53 * make a directory
55 int
56 makedir(char *pathname)
58 return mkdir(pathname);
62 * stamp a file with date and time
64 int
65 filestamp(Header *header, char *filename)
67 Date *date;
68 struct tm tm;
69 struct utimbuf utimbuf;
70 time_t filetime;
72 /* BB: DOS utime() cannot stamp directories.
73 It could be done by directly editing the directory entries
74 (simulate a disc editor) but since e.g. pkunzip does not
75 stamp extracted directories either, I did not bother and
76 kept the next line from winnt.c.
77 ``It is left as an exercice to the interested reader.''
78 NB: Do not forget to stamp the . entry in the directory
79 itself! */
80 if (exist(filename) == ISDIR)
81 return (0);
83 if ((header->load & (Word) 0xfff00000UL) != (Word) 0xfff00000UL)
84 return (0); /* not a timestamp */
86 memset((char *) &tm, '\0', sizeof(tm));
88 /* Borland C/C++ 4 is `a bit fuzzy' about the next line 8-( */
89 /* if (!(date = makedate(header))) */
90 if ((date = makedate(header)) == 0)
91 return (-1);
93 tm.tm_sec = date->second;
94 tm.tm_min = date->minute;
95 tm.tm_hour = date->hour;
96 tm.tm_mday = date->day;
97 tm.tm_mon = date->month - 1;
98 tm.tm_year = date->year;
99 filetime = mktime(&tm);
101 utimbuf.actime = filetime;
102 utimbuf.modtime = filetime;
103 return (utime(filename, &utimbuf));