File: linux.c

package info (click to toggle)
zoo 2.10-9
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 780 kB
  • ctags: 1,288
  • sloc: ansic: 9,041; asm: 793; makefile: 211
file content (74 lines) | stat: -rw-r--r-- 1,679 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
/* machine.c for Linux. */

/* Basically code stolen from bsd.c, and adjusted for Linux. */

#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>

/* Function isadir() returns 1 if the supplied handle is a directory,
 * else it returns 0. */

int isadir (ZOOFILE f)
{
  struct stat buffer;           /* buffer to hold file information */

  if (fstat (fileno (f), &buffer) == -1) 
    return (0);                 /* inaccessible -- assume not dir */
  else
    {
      if (buffer.st_mode & S_IFDIR)
	return (1);
      else
	return (0);
    }
}


/* Standard UNIX-compatible time routines */
#include "nixtime.i"

/* Standard UNIX-specific file attribute routines */
#include "nixmode.i"

/* 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 */
  struct timeval tp;
  struct timezone tzp;

  if (retval != INV_VALUE)           /* if have cached value, return it */
    return retval;
  
   gettimeofday (&tp, &tzp);            

   retval = tzp.tz_minuteswest * 60 - tzp.tz_dsttime * 3600L;
   return retval;
}

/* Function fixfname() converts the supplied filename to a syntax
 * legal for the host system.  It is used during extraction.
 * Undocumented */

char *fixfname(char *fname)
{
  return fname; /* default is no-op */
}

/* Function zootrunc() truncates the file passed to it.
 * Undocumented. */

int zootrunc(FILE *f)
{
  extern long lseek();
  long seekpos;
  int fd = fileno(f);

  seekpos = lseek(fd, 0L, SEEK_CUR);
  if (seekpos >= 0)
    return ftruncate(fd, seekpos);
}