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/fopen.c | |
download | iraf-osx-40e5a5811c6ffce9b0974e93cdd927cbcf60c157.tar.gz |
Repatch (from linux) of OSX IRAF
Diffstat (limited to 'sys/libc/fopen.c')
-rw-r--r-- | sys/libc/fopen.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/sys/libc/fopen.c b/sys/libc/fopen.c new file mode 100644 index 00000000..f9fe16ae --- /dev/null +++ b/sys/libc/fopen.c @@ -0,0 +1,61 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. +*/ + +#define import_spp +#define import_libc +#define import_xnames +#define import_stdio +#include <iraf.h> + + +/* FOPEN -- Open a file with the given access mode and file type. The file type +** (text or binary) is specified with an optional, non UNIX standard character +** "t" or "b" in the modestring. The default is text file if no type is given. +*/ +FILE * +fopen ( + char *fname, /* vfn of file */ + char *modestr /* access mode [and type] */ +) +{ + XINT x_filetype, x_filemode; + int fd; + + + /* Get file type. + */ + switch (modestr[1]) { + case 't': + case EOS: + x_filetype = TEXT_FILE; + break; + case 'b': + x_filetype = BINARY_FILE; + break; + default: + return (NULL); + } + + /* Determine file access mode. + */ + switch (modestr[0]) { + case 'r': + x_filemode = READ_ONLY; + break; + case 'w': + x_filemode = NEW_FILE; + break; + case 'a': + x_filemode = APPEND; + break; + default: + return (NULL); + } + + /* Open file. + */ + iferr (fd = OPEN (c_sppstr(fname), &x_filemode, &x_filetype)) + return (NULL); + else + return (FDTOFP(fd)); +} |