aboutsummaryrefslogtreecommitdiff
path: root/sys/libc/fopen.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/libc/fopen.c
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/libc/fopen.c')
-rw-r--r--sys/libc/fopen.c61
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));
+}