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/zfmkcp.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 unix/os/zfmkcp.c (limited to 'unix/os/zfmkcp.c') diff --git a/unix/os/zfmkcp.c b/unix/os/zfmkcp.c new file mode 100644 index 00000000..5ca393c4 --- /dev/null +++ b/unix/os/zfmkcp.c @@ -0,0 +1,71 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + */ + +#include +#include +#include +#include + +#define import_kernel +#define import_knames +#define import_protect +#define import_spp +#include + +/* ZFMKCP -- Make a null length copy of a file. The new file inherits all + * attributes of the original file except the file owner (the copy belongs to + * the owner of the process which called us), the file size (this will be 0 + * after the zfmkcp), and the owner write permission bit (the new file has + * to be writable by the owner to be useful). + * + * Since file protection is implemented by special techniques on UNIX, + * we must take special measures to pass the file protection attribute to + * the new copy. + */ +int +ZFMKCP ( + PKCHAR *osfn, + PKCHAR *new_osfn, + XINT *status +) +{ + struct stat statbuf; + int fd, mode; + XINT prot; + + extern int ZFPROT(); + + + /* Get directory information for the old file. Most of the file + * attributes reside in the st_mode field. + */ + if (stat ((char *)osfn, &statbuf) == ERR) { + *status = XERR; + return (XERR); + } + + mode = statbuf.st_mode; + + /* Create new file using mode bits from the existing file. + */ + if ((fd = creat ((char *)new_osfn, mode | 0600)) == ERR) { + *status = XERR; + return (XERR); + } else + close (fd); + + /* Add file protection if the original file is protected. If new file + * cannot be protected delete new file and return ERR. + */ + prot = QUERY_PROTECTION; + ZFPROT (osfn, &prot, status); + if (*status == XYES) { + prot = SET_PROTECTION; + ZFPROT (new_osfn, &prot, status); + } + + if (*status == XERR) + unlink ((char *)new_osfn); + + return (XOK); +} -- cgit