-
Notifications
You must be signed in to change notification settings - Fork 1
/
bsd.c
119 lines (102 loc) · 2.78 KB
/
bsd.c
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
#ifndef LINT
static char bsdid[]="@(#) bsd.c 2.3 88/01/10 14:45:19";
#endif /* LINT */
/* machine.c for 4.3BSD. */
/*
The contents of this file are hereby released to the public domain.
-- Rahul Dhesi 1987/07/23
*/
/*
WARNING: This file assumes that ZOOFILE is a standard buffered
file. It will have to be modified if ZOOFILE is changed to
be an unbuffered file descriptor or to any other kind of file.
*/
#ifdef UNBUF_IO
/*
Function tell() returns the current seek position for a file
descriptor. 4.3BSD on VAX-11/785 has an undocumented tell() function
but it may not exist on all implementations, so we code one here
to be on the safe side. It is needed for unbuffered I/O only.
*/
long lseek PARMS ((int, long, int));
long tell (fd)
int fd;
{ return (lseek (fd, 0L, 1)); }
#endif
long ftell();
/****************
Function fixfname() converts the supplied filename to a syntax
legal for the host system. It is used during extraction.
*/
char *fixfname(fname)
char *fname;
{
return fname; /* default is no-op */
}
/****************
Date and time functions are standard UNIX-style functions.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
/* Function isadir() returns 1 if the supplied handle is a directory,
else it returns 0.
*/
int isadir (f)
ZOOFILE f;
{
struct stat buf; /* buffer to hold file information */
if (fstat (fileno (f), &buf) == -1) {
return (0); /* inaccessible -- assume not dir */
} else {
if (buf.st_mode & S_IFDIR)
return (1);
else
return (0);
}
}
/* Function gettz() returns the offset from GMT in seconds */
long gettz()
{
#define SEC_IN_DAY (24L * 60L * 60L)
#define INV_VALUE (SEC_IN_DAY + 1L)
static long retval = INV_VALUE; /* cache, init to impossible value */
#ifndef __386BSD__
struct timeval tp;
struct timezone tzp;
#else
time_t lt;
struct tm *tm;
#endif
if (retval != INV_VALUE) /* if have cached value, return it */
return retval;
#ifndef __386BSD__
gettimeofday (&tp, &tzp); /* specific to 4.3BSD */
/* return (tzp.tz_minuteswest * 60); */ /* old incorrect code */
/* Timezone fix thanks to Bill Davidsen <wedu@ge-crd.ARPA> */
/* !! - ache@hq.demos.su */
retval = tzp.tz_minuteswest * 60 - (tzp.tz_dsttime != 0) * 3600L;
#else
time(<);
tm = localtime(<);
retval = -tm->tm_gmtoff;
#endif
return retval;
}
/* Standard UNIX-compatible time routines */
#include "nixtime.i"
/* Standard UNIX-specific file attribute routines */
#include "nixmode.i"
#ifndef SEEK_CUR
# define SEEK_CUR 1
#endif
/* Truncate a file. */
int zootrunc(f) FILE *f;
{
extern long lseek();
long seekpos;
int fd = fileno(f);
seekpos = lseek(fd, 0L, SEEK_CUR);
if (seekpos >= 0)
return ftruncate(fd, seekpos);
}