From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/libc/cwrite.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 sys/libc/cwrite.c (limited to 'sys/libc/cwrite.c') 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 + + +/* 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); +} -- cgit