From 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Tue, 11 Aug 2015 16:51:37 -0400 Subject: Repatch (from linux) of OSX IRAF --- unix/os/zfinfo.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 unix/os/zfinfo.c (limited to 'unix/os/zfinfo.c') diff --git a/unix/os/zfinfo.c b/unix/os/zfinfo.c new file mode 100644 index 00000000..db5803fb --- /dev/null +++ b/unix/os/zfinfo.c @@ -0,0 +1,99 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + */ + +#include +#include +#include +#include + +#define import_kernel +#define import_knames +#define import_spp +#define import_finfo +#include + +/* ZFINFO -- Get information describing the named file. Access times + * are returned in units of seconds since 00:00:00 01-Jan-80, local time. + */ +int +ZFINFO ( + PKCHAR *fname, + XLONG *finfo_struct, + XINT *status +) +{ + struct stat osfile; + struct _finfo *fs; + struct passwd *getpwuid(); + time_t gmt_to_lst(); + int stat(); + + /* Get UNIX file info. + */ + fs = (struct _finfo *)finfo_struct; + if (stat ((char *)fname, &osfile) == ERR) { + *status = XERR; + return (XERR); + } + + /* Determine file type. + */ + if (osfile.st_mode & S_IFDIR) + fs->fi_type = FI_DIRECTORY; + else if (osfile.st_mode & S_IEXEC) + fs->fi_type = FI_EXECUTABLE; + else if (osfile.st_mode & S_IFREG) + fs->fi_type = FI_REGULAR; + else + fs->fi_type = FI_SPECIAL; + + /* Set file size (in bytes), access times, and file permission bits. + * Times must be converted from GMT epoch 1970 to local standard time, + * epoch 1980. + */ + fs->fi_size = osfile.st_size; + fs->fi_atime = gmt_to_lst (osfile.st_atime); + fs->fi_mtime = gmt_to_lst (osfile.st_mtime); + fs->fi_ctime = gmt_to_lst (osfile.st_ctime); + + /* Encode file access permission bits. + */ + { + static int osbits[] = { 0400, 0200, 040, 020, 04, 02 }; + int bit; + + for (bit=0, fs->fi_perm=0; bit < 6; bit++) + fs->fi_perm |= (osfile.st_mode & osbits[bit]) ? 1<fi_owner, owner, SZ_OWNERSTR); + else { + setpwent(); + pw = getpwuid (osfile.st_uid); + endpwent(); + + if (pw == NULL) + sprintf ((char *)fs->fi_owner, "%d", osfile.st_uid); + else { + strncpy (owner, pw->pw_name, SZ_OWNERSTR); + strncpy ((char *)fs->fi_owner, owner, SZ_OWNERSTR); + uid = osfile.st_uid; + } + } + ((char *)fs->fi_owner)[SZ_OWNERSTR] = EOS; + } + + *status = XOK; + + return (*status); +} -- cgit