/* machine.c for System V */

/*
The contents of this file are hereby released to the public domain.

                                    -- Rahul Dhesi  1986/12/31
*/

/****************
function trunc() truncates a file.
*/

int trunc (handle)
int handle;
{
}

/****************
Date and time functions are standard UNIX-style functions.  "nixtime.i"
will be included by machine.c.
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>

/* Function isadir() returns 1 if the supplied handle is a directory, 
else it returns 0.  
*/

int isadir (handle)
int handle;
{
   struct stat buf;           /* buffer to hold file information */
   if (fstat (handle, &buf) == -1) {
      return (0);             /* inaccessible -- assume not dir */
   } else {
      if (buf.st_mode & S_IFDIR)
         return (1);
      else
         return (0);
   }
}

/****************
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 */
}

extern long timezone;   /* defined by library routine */
extern int daylight;

/* Function gettz(), returns the offset from GMT in seconds of the
local time, taking into account daylight savings time */
long gettz()
{
   tzset();
   return (timezone);
}

/* Standard UNIX-compatible time functions */
#include "nixtime.i"

/* 
Make a directory.  System V has no system accessible to ordinary
users to make a new directory.  Hence we spawn a shell and hope
/bin/mkdir is there.  Since /bin/mkdir gives a nasty error message
if it fails, we call it only if nothing already exists by the
name of the needed directory.
*/

int mkdir(dirname)
char *dirname;
{
   char cmd[PATHSIZE+7];
   if (!exists(dirname)) {
      strcpy(cmd, "/bin/mkdir ");
      strcat(cmd, dirname);
      return (system(cmd));
   }
}
