File: arcdos.c

package info (click to toggle)
arc 5.21m-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny
  • size: 364 kB
  • ctags: 306
  • sloc: ansic: 4,078; makefile: 123
file content (213 lines) | stat: -rw-r--r-- 4,733 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * $Header: /cvsroot/arc/arc/arcdos.c,v 1.3 2003/10/31 02:32:19 highlandsun Exp $
 */

/*
 * ARC - Archive utility - ARCDOS
 * 
 * Version 1.44, created on 07/25/86 at 14:17:38
 * 
 * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
 * 
 * By:  Thom Henderson
 * 
 * Description: This file contains certain DOS level routines that assist in
 * doing fancy things with an archive, primarily reading and setting the date
 * and time last modified.
 * 
 * These are, by nature, system dependant functions.  But they are also, by
 * nature, very expendable.
 * 
 * Language: Computer Innovations Optimizing C86
 */
#include <stdio.h>
#include "arc.h"

#if	MSDOS
#include "fileio2.h"		/* needed for filehand */
#endif

#if	UNIX
#include <sys/types.h>
#include <sys/stat.h>
#if	BSD
#include <sys/time.h>
#else	
#include <time.h>		/* Sys V. Bleah. */
#if	NEED_TIMEVAL
struct	timeval {
	long	tv_sec;
	long	tv_usec;
};
#endif
#endif	/* BSD vs SYSV */
#endif

#if	GEMDOS
#include <osbind.h>
#endif

#include <string.h>
#ifndef	__STDC__
char	*malloc();
#endif

VOID
getstamp(f, date, time)		/* get a file's date/time stamp */
#if	!_MTS
	FILE           *f;	/* file to get stamp from */
#else
	char           *f;	/* filename "" "" */
#endif
	unsigned short   *date, *time;	/* storage for the stamp */
{
#if	MSDOS
	struct {
		int             ax, bx, cx, dx, si, di, ds, es;
	}               reg;

	reg.ax = 0x5700;	/* get date/time */
	reg.bx = filehand(f);	/* file handle */
	if (sysint21(&reg, &reg) & 1)	/* DOS call */
		printf("Get timestamp fail (%d)\n", reg.ax);

	*date = reg.dx;		/* save date/time */
	*time = reg.cx;
#endif
#if	GEMDOS
	int	fd, ret[2];

	fd = fileno(f);
	Fdatime(ret, fd, 0);
	*date = ret[1];
	*time = ret[0];
#endif
#if	UNIX
	struct stat	buf;
	struct tm	*localtime(), *t;

	fstat(fileno(f), &buf);
	t=localtime(&(buf.st_mtime));
	*date = (unsigned short) (((t->tm_year - 80) << 9) +
				((t->tm_mon + 1) << 5) + t->tm_mday);
	*time = (unsigned short) ((t->tm_hour << 11) +
				(t->tm_min << 5) + t->tm_sec / 2);
#endif
#if	_MTS
	fortran         timein(),
#if	USEGFINFO
	                gfinfo();
#else
	                fileinfo();
#endif
	int             stclk[2];
	char            name[24];
	struct bigtime {
		int             greg;
		int             year;
		int             mon;
		int             day;
		int             hour;
		int             min;
		int             sec;
		int             usec;
		int             week;
		int             toff;
		int             tzn1;
		int             tzn2;
	}               tvec;
#if	USEGFINFO
	static int      gfflag = 0x0009, gfdummy[2] = {
						       0, 0
	};
	int             gfcinfo[18];
#else
	static int      cattype = 2;
#endif

	strcpy(name, f);
	strcat(name, " ");
#if	USEGFINFO
	gfcinfo[0] = 18;
	gfinfo(name, name, &gfflag, gfcinfo, gfdummy, gfdummy);
	timein("*IBM MICROSECONDS*", &gfcinfo[16], &tvec);
#else
	fileinfo(name, &cattype, "CILCCT  ", stclk);
	timein("*IBM MICROSECONDS*", stclk, &tvec);
#endif

	*date = (unsigned short) (((tvec.year - 1980) << 9) + ((tvec.mon) << 5) + tvec.day);
	*time = (unsigned short) ((tvec.hour << 11) + (tvec.min << 5) + tvec.sec / 2);
#endif
}

VOID
setstamp(f, date, time)		/* set a file's date/time stamp */
	char           *f;	/* filename to stamp */
	unsigned short    date, time;	/* desired date, time */
{
#if	MSDOS
	FILE	*ff;
	struct {
		int             ax, bx, cx, dx, si, di, ds, es;
	}               reg;

	ff = fopen(f, "w+");	/* How else can I get a handle? */

	reg.ax = 0x5701;	/* set date/time */
	reg.bx = filehand(f);	/* file handle */
	reg.cx = time;		/* desired time */
	reg.dx = date;		/* desired date */
	if (sysint21(&reg, &reg) & 1)	/* DOS call */
		printf("Set timestamp fail (%d)\n", reg.ax);
	fclose(ff);
#endif
#if	GEMDOS
	int	fd, set[2];

	fd = Fopen(f, 0);
	set[0] = time;
	set[1] = date;
	Fdatime(set, fd, 1);
	Fclose(fd);
#endif
#if	UNIX
	struct tm	tm;
	struct timeval  tvp[2];
	int	utimes();
	long	tmclock();
	tm.tm_sec = (time & 31) * 2;
	tm.tm_min = (time >> 5) & 63;
	tm.tm_hour = (time >> 11);
	tm.tm_mday = date & 31;
	tm.tm_mon = ((date >> 5) & 15) - 1;
	tm.tm_year = (date >> 9) + 80;
	tvp[0].tv_sec = tmclock(&tm);
	tvp[1].tv_sec = tvp[0].tv_sec;
	tvp[0].tv_usec = tvp[1].tv_usec = 0;
	utimes(f, tvp);
#endif
}

#if	MSDOS
int
filehand(stream)		/* find handle on a file */
	struct bufstr  *stream;	/* file to grab onto */
{
	return stream->bufhand;	/* return DOS 2.0 file handle */
}
#endif

#if	UNIX
int
izadir(filename)		/* Is filename a directory? */
	char           *filename;
{
	struct stat     buf;

	if (stat(filename, &buf) != 0)
		return (0);	/* Ignore if stat fails since */
	else
		return (buf.st_mode & S_IFDIR);	/* bad files trapped later */
}
#endif