aboutsummaryrefslogtreecommitdiff
path: root/sys/libc/cwrite.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/cwrite.c
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/libc/cwrite.c')
-rw-r--r--sys/libc/cwrite.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/sys/libc/cwrite.c b/sys/libc/cwrite.c
new file mode 100644
index 00000000..5ca7dab9
--- /dev/null
+++ b/sys/libc/cwrite.c
@@ -0,0 +1,51 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+*/
+
+#define import_spp
+#define import_libc
+#define import_xnames
+#define import_fset
+#define import_stdio
+#define import_error
+#include <iraf.h>
+
+
+/* C_WRITE -- FIO write to a file. Write exactly nbytes bytes from the buffer
+** buf to the stream fd. If the actual file is a text file C chars are output
+** as XCHARs. If the actual file is a binary file no conversion is performed,
+** but an integral number of XCHARs are always written.
+*/
+int
+c_write (
+ XINT fd, /* FIO file descriptor */
+ char *buf, /* buffer containing data to be written */
+ int nbytes /* nbytes to be written */
+)
+{
+ XINT x_fd = fd;
+
+ if (c_fstati (fd, F_TYPE) == TEXT_FILE) {
+ register FILE *fp = FDTOFP(fd);
+ register char *ip;
+ register int n = nbytes;
+
+ for (ip=buf; --n >= 0; ip++)
+ putc (*ip, fp);
+ if (ferror (fp))
+ c_erract (EA_ERROR);
+
+ } else {
+ XINT x_nchars = (nbytes + sizeof(XCHAR)-1) / sizeof(XCHAR);
+ XCHAR *bp = (XCHAR *)buf;
+
+ /* Verify that the pointer coercion char->XCHAR->char is legal,
+ * i.e., that the char pointer is aligned to an XCHAR word
+ * boundary if required on this machine.
+ */
+ if (buf != (char *) bp)
+ return (ERR);
+ WRITE (&x_fd, bp, &x_nchars);
+ }
+
+ return (nbytes);
+}