Merge pull request #12 from davel/davel/sqsh
[debian-nspark.git] / msdos.c
blob8e6667d968d710cd2486d25eda30c21604e3cfa5
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 #ifdef __WATCOMC__
16 #include <direct.h>
17 #else
18 #include <dir.h>
19 #endif
20 #include <time.h>
21 #include <utime.h>
22 #include <string.h> /* for memset */
23 #include "os.h"
26 * return the length of a file
28 Word
29 filesize(char *pathname)
31 struct stat statb;
33 if (stat(pathname, &statb) < 0)
34 return 0;
36 return (Word) statb.st_size;;
40 * test for the existance of a file or directory
42 Ftype
43 exist(char *pathname)
45 struct stat statb;
47 if (stat(pathname, &statb) < 0)
48 return NOEXIST;
50 if (statb.st_mode & S_IFDIR)
51 return ISDIR;
53 return (ISFILE);
57 * make a directory
59 int
60 makedir(char *pathname)
62 return mkdir(pathname);
66 * stamp a file with date and time
68 int
69 filestamp(Header *header, char *filename)
71 Date *date;
72 struct tm tm;
73 struct utimbuf utimbuf;
74 time_t filetime;
76 /* BB: DOS utime() cannot stamp directories.
77 It could be done by directly editing the directory entries
78 (simulate a disc editor) but since e.g. pkunzip does not
79 stamp extracted directories either, I did not bother and
80 kept the next line from winnt.c.
81 ``It is left as an exercice to the interested reader.''
82 NB: Do not forget to stamp the . entry in the directory
83 itself! */
84 if (exist(filename) == ISDIR)
85 return (0);
87 if ((header->load & (Word) 0xfff00000UL) != (Word) 0xfff00000UL)
88 return (0); /* not a timestamp */
90 memset((char *) &tm, '\0', sizeof(tm));
92 /* Borland C/C++ 4 is `a bit fuzzy' about the next line 8-( */
93 /* if (!(date = makedate(header))) */
94 if ((date = makedate(header)) == 0)
95 return (-1);
97 tm.tm_sec = date->second;
98 tm.tm_min = date->minute;
99 tm.tm_hour = date->hour;
100 tm.tm_mday = date->day;
101 tm.tm_mon = date->month - 1;
102 tm.tm_year = date->year;
103 filetime = mktime(&tm);
105 utimbuf.actime = filetime;
106 utimbuf.modtime = filetime;
107 return (utime(filename, &utimbuf));