aboutsummaryrefslogtreecommitdiff
path: root/unix/os/zfutim.c
diff options
context:
space:
mode:
authorJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
committerJoe Hunkeler <jhunkeler@gmail.com>2015-08-11 16:51:37 -0400
commit40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch)
tree4464880c571602d54f6ae114729bf62a89518057 /unix/os/zfutim.c
downloadiraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'unix/os/zfutim.c')
-rw-r--r--unix/os/zfutim.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/unix/os/zfutim.c b/unix/os/zfutim.c
new file mode 100644
index 00000000..4c074f27
--- /dev/null
+++ b/unix/os/zfutim.c
@@ -0,0 +1,68 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#ifdef SYSV
+#include <time.h>
+#else
+#include <sys/time.h>
+#include <sys/timeb.h>
+#endif
+#include <utime.h>
+
+#define import_kernel
+#define import_knames
+#define import_spp
+#include <iraf.h>
+
+#define SECONDS_1970_TO_1980 315532800L
+
+
+/* ZFUTIM -- Set the file access/modification times. Times are set in
+ * in units of seconds since 00:00:00 01-Jan-80, local time, as returned
+ * by ZFINFO. A NULL time value will not modify the field.
+ */
+int
+ZFUTIM (
+ PKCHAR *fname,
+ XLONG *atime,
+ XLONG *mtime,
+ XINT *status
+)
+{
+ struct stat osfile;
+ struct utimbuf time;
+ int offset = 0;
+ int stat(), utime();
+
+ extern int ZGMTCO ();
+
+
+ /* Get UNIX file info.
+ */
+ if (stat ((char *)fname, &osfile) == ERR) {
+ *status = XERR;
+ return (XERR);
+ }
+
+ /* Get the timezone offset. Correct for daylight savings time,
+ * if in effect.
+ */
+ ZGMTCO (&offset);
+ offset += SECONDS_1970_TO_1980;
+
+ /* Set file access times. If time is NULL use the current value.
+ */
+ time.actime = ((*atime == 0) ? osfile.st_atime : (*atime+offset));
+ time.modtime = ((*mtime == 0) ? osfile.st_mtime : (*mtime+offset));
+
+ if (utime ((char *)fname, &time) == ERR) {
+ *status = XERR;
+ return (XERR);
+ }
+ *status = XOK;
+
+ return (*status);
+}