diff options
author | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
---|---|---|
committer | Joe Hunkeler <jhunkeler@gmail.com> | 2015-08-11 16:51:37 -0400 |
commit | 40e5a5811c6ffce9b0974e93cdd927cbcf60c157 (patch) | |
tree | 4464880c571602d54f6ae114729bf62a89518057 /sys/libc/fdopen.c | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/libc/fdopen.c')
-rw-r--r-- | sys/libc/fdopen.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/sys/libc/fdopen.c b/sys/libc/fdopen.c new file mode 100644 index 00000000..c9e2bc9f --- /dev/null +++ b/sys/libc/fdopen.c @@ -0,0 +1,76 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. +*/ + +#define import_spp +#define import_libc +#define import_stdio +#define import_fset +#include <iraf.h> + + +extern int c_fstati(); + + +/* FDOPEN -- Reopen a file for i/o with the STDIO package, after the file +** as already been opened by FIO. It is an error if the access modes are +** incompatible. +*/ +FILE * +fdopen ( + XINT fd, /* FIO file descriptor */ + char *mode /* STDIO access mode */ +) +{ + register int fio_mode = c_fstati (fd, F_MODE); + register int fio_type = c_fstati (fd, F_TYPE); + + + /* Verify file access mode. No mode checking is performed for the + * special file types. + */ + if (fio_type == TEXT_FILE || fio_type == BINARY_FILE) + switch (mode[0]) { + case 'r': + if (fio_mode != READ_ONLY && fio_mode != READ_WRITE) + return (NULL); + break; + + case 'w': + switch (fio_mode) { + case NEW_FILE: + case READ_WRITE: + case WRITE_ONLY: + break; + default: + return (NULL); + } + break; + + case 'a': + if (fio_mode != APPEND && fio_mode != NEW_FILE) + return (NULL); + break; + + default: + return (NULL); + } + + /* Verify file type. No checking is performed if no type is given. + */ + switch (mode[1]) { + case EOS: + break; + case 't': + if (fio_type != TEXT_FILE) + return (NULL); + break; + case 'b': + if (fio_type != BINARY_FILE) + return (NULL); + break; + default: + return (NULL); + } + + return (FDTOFP(fd)); +} |