diff options
author | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
---|---|---|
committer | stevel@tonic-gate <none@none> | 2005-06-14 00:00:00 -0700 |
commit | 7c478bd95313f5f23a4c958a745db2134aa03244 (patch) | |
tree | c871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/lib/libbc/libc/stdio/sys5 | |
download | illumos-gate-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz |
OpenSolaris Launch
Diffstat (limited to 'usr/src/lib/libbc/libc/stdio/sys5')
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/filbuf.c | 92 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/flsbuf.c | 295 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/fopen.c | 91 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/fprintf.c | 74 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/printf.c | 61 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/setbuf.c | 63 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/sprintf.c | 52 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/vfprintf.c | 71 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/vprintf.c | 63 | ||||
-rw-r--r-- | usr/src/lib/libbc/libc/stdio/sys5/vsprintf.c | 59 |
10 files changed, 921 insertions, 0 deletions
diff --git a/usr/src/lib/libbc/libc/stdio/sys5/filbuf.c b/usr/src/lib/libbc/libc/stdio/sys5/filbuf.c new file mode 100644 index 0000000000..aa247dab34 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/filbuf.c @@ -0,0 +1,92 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1998 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern _findbuf(); +extern int read(); +extern int fflush(); + +int +__filbuf(iop) +register FILE *iop; +{ + return (_filbuf(iop)); +} + +int +_filbuf(iop) +register FILE *iop; +{ + static void lbfflush(); + + if ( !(iop->_flag & _IOREAD) ) + if (iop->_flag & _IORW) + iop->_flag |= _IOREAD; + else + return(EOF); + + if (iop->_flag&_IOSTRG) + return(EOF); + + if (iop->_base == NULL) /* get buffer if we don't have one */ + _findbuf(iop); + + /* if this device is a terminal (line-buffered) or unbuffered, then */ + /* flush buffers of all line-buffered devices currently writing */ + + if (iop->_flag & (_IOLBF | _IONBF)) + _fwalk(lbfflush); + + iop->_ptr = iop->_base; + iop->_cnt = read(fileno(iop), (char *)iop->_base, + (unsigned)((iop->_flag & _IONBF) ? 1 : iop->_bufsiz )); + if (--iop->_cnt >= 0) /* success */ + return (*iop->_ptr++); + if (iop->_cnt != -1) /* error */ + iop->_flag |= _IOERR; + else { /* end-of-file */ + iop->_flag |= _IOEOF; + if (iop->_flag & _IORW) + iop->_flag &= ~_IOREAD; + } + iop->_cnt = 0; + return (EOF); +} + +static void +lbfflush(iop) +FILE *iop; +{ + if (iop->_flag & _IOLBF) + (void) fflush(iop); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/flsbuf.c b/usr/src/lib/libbc/libc/stdio/sys5/flsbuf.c new file mode 100644 index 0000000000..635b1ff2ba --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/flsbuf.c @@ -0,0 +1,295 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from ../4.2/flsbuf.c */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <sys/errno.h> +#include "../common/stdiom.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +extern void free(); +extern int errno, write(), close(), isatty(); +extern char *malloc(); +extern unsigned char (*_smbuf)[_SBFSIZ]; + +void _getsmbuf(); + +/* + * Flush buffers on exit + */ + +void +_cleanup() +{ + extern int fclose(); + + _fwalk(fclose); +} +/* + fclose() will flush (output) buffers for a buffered open + FILE and then issue a system close on the _fileno. The + _base field will be reset to NULL for any but stdin and + stdout, the _ptr field will be set the same as the _base + field. The _flags and the _cnt field will be zeroed. + If buffers had been obtained via malloc(), the space will + be free()'d. In case the FILE was not open, or fflush() + or close() failed, an EOF will be returned, otherwise the + return value is 0. + */ + +int +fclose(iop) +register FILE *iop; +{ + register int rtn=EOF; + + if(iop == NULL) + return(rtn); + if(iop->_flag & (_IOREAD | _IOWRT | _IORW) + && (iop->_flag & _IOSTRG) == 0) { + rtn = (iop->_flag & _IONBF)? 0: fflush(iop); + if(close(fileno(iop)) < 0) + rtn = EOF; + } + if(iop->_flag & _IOMYBUF) { + free((char*)iop->_base); + iop->_base = NULL; + } + iop->_flag = 0; + iop->_cnt = 0; + iop->_ptr = iop->_base; + iop->_bufsiz = 0; + return(rtn); +} + +/* + The fflush() routine must take care because of the + possibility for recursion. The calling program might + do IO in an interupt catching routine that is likely + to interupt the write() call within fflush() + */ + +int +fflush(iop) +register FILE *iop; +{ + if (!(iop->_flag & _IOWRT)) { + if ((iop->_base != NULL) && iop->_cnt) { + lseek(iop->_file, -(iop->_cnt), SEEK_CUR); + iop->_cnt = 0; + } + return(0); + } + while(!(iop->_flag & _IONBF) && (iop->_flag & _IOWRT) && + (iop->_base != NULL) && (iop->_ptr > iop->_base) ) + (void) _xflsbuf(iop); + return(ferror(iop) ? EOF : 0); +} + +/* The routine _flsbuf may or may not actually flush the output buffer. If + * the file is line-buffered, the fact that iop->_cnt has run below zero + * is meaningless: it is always kept below zero so that invocations of putc + * will consistently give control to _flsbuf, even if the buffer is far from + * full. _flsbuf, on seeing the "line-buffered" flag, determines whether the + * buffer is actually full by comparing iop->_ptr to the end of the buffer + * iop->_base + iop->_bufsiz. If it is full, or if an output line is + * completed (with a newline), the buffer is flushed. (Note: the character + * argument to _flsbuf is not flushed with the current buffer if the buffer + * is actually full -- it goes into the buffer after flushing.) + */ + +int +_flsbuf(c, iop) +unsigned char c; +register FILE *iop; +{ + unsigned char c1; + + do { + /* check for linebuffered with write perm, but no EOF */ + if ( (iop->_flag & (_IOLBF | _IOWRT | _IOEOF)) == (_IOLBF | _IOWRT) ) { + if ( iop->_ptr >= iop->_base + iop->_bufsiz ) /* if buffer full, */ + break; /* exit do-while, and flush buf. */ + if ( (*iop->_ptr++ = c) != '\n' ) + return(c); + return(_xflsbuf(iop) == EOF ? EOF : c); + } + /* write out an unbuffered file, if have write perm, but no EOF */ + if ( (iop->_flag & (_IONBF | _IOWRT | _IOEOF)) == (_IONBF | _IOWRT) ) { + c1 = c; + iop->_cnt = 0; + if (write(fileno(iop), (char *) &c1, 1) == 1) + return(c); + iop->_flag |= _IOERR; + return(EOF); + } + /* The _wrtchk call is here rather than at the top of _flsbuf to re- */ + /* duce overhead for line-buffered I/O under normal circumstances. */ + + if (_WRTCHK(iop)) /* is writing legitimate? */ + return(EOF); + } while ( (iop->_flag & (_IONBF | _IOLBF)) ); + + + (void) _xflsbuf(iop); /* full buffer: flush buffer */ + (void) putc((char) c, iop); /* then put "c" in newly emptied buf */ + /* (which, because of signals, may NOT be empty) */ + return( ferror(iop) ? EOF : c); +} + +/* The function _xflsbuf writes out the current contents of the output + * buffer delimited by iop->_base and iop->_ptr. + * iop->_cnt is reset appropriately, but its value on entry to _xflsbuf + * is ignored. + * + * The following code is not strictly correct. If a signal is raised, + * invoking a signal-handler which generates output into the same buffer + * being flushed, a peculiar output sequence may result (for example, + * the output generated by the signal-handler may appear twice). At + * present no means has been found to guarantee correct behavior without + * resorting to the disabling of signals, a means considered too expensive. + * For now the code has been written with the intent of reducing the + * probability of strange effects and, when they do occur, of confining + * the damage. Except under extremely pathological circumstances, this + * code should be expected to respect buffer boundaries even in the face + * of interrupts and other signals. + */ + +int +_xflsbuf(iop) +register FILE *iop; +{ + register unsigned char *base; + register int n; + + n = iop->_ptr - (base = iop->_base); + iop->_ptr = base; + iop->_cnt = (iop->_flag &(_IONBF | _IOLBF)) ? 0 : iop->_bufsiz; + _BUFSYNC(iop); + if (n > 0 && n != write(fileno(iop),(char*)base,(unsigned)n) ) { + iop->_flag |= _IOERR; + return(EOF); + } + return(0); +} + +/* The function _wrtchk checks to see whether it is legitimate to write + * to the specified device. If it is, _wrtchk sets flags in iop->_flag for + * writing, assures presence of a buffer, and returns 0. If writing is not + * legitimate, EOF is returned. + */ + +int +_wrtchk(iop) +register FILE *iop; +{ + if ( (iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT ) { + if (!(iop->_flag & (_IOWRT | _IORW))) + return(EOF); /* bogus call--read-only file */ + iop->_flag = iop->_flag & ~_IOEOF | _IOWRT; /* fix flags */ + } + if (iop->_flag & _IOSTRG) + return(0); /* not our business to monkey with buffers or counts */ + if (iop->_base == NULL) /* this is first I/O to file--get buffer */ + _findbuf(iop); + if (iop->_ptr == iop->_base && !(iop->_flag & (_IONBF | _IOLBF)) ) { + iop->_cnt = iop->_bufsiz; /* first write since seek--set cnt */ + _BUFSYNC(iop); + } + return(0); +} + +/* + * _findbuf, called only when iop->_base == NULL, locates a predefined buffer + * or allocates a buffer using malloc. If a buffer is obtained from malloc, + * the _IOMYBUF flag is set in iop->_flag. + */ + +_findbuf(iop) +register FILE *iop; +{ + register int fno = fileno(iop); /* file number */ + struct stat statb; + register int size; + + /* allocate a small block for unbuffered, large for buffered */ + if (iop->_flag & _IONBF) { + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + } else { + + if ( isatty(fno) ) { + iop->_flag |= _IOLBF; + size = 128; + } else { + if (fstat(fno, &statb) < 0) + size = BUFSIZ; + else { + if ((size = statb.st_blksize) <= 0) + size = BUFSIZ; + } + } + if ((iop->_base = (unsigned char *) malloc(size+8)) != NULL) { + /* if we got a buffer */ + iop->_flag |= _IOMYBUF; + iop->_bufsiz = size; + } else { + /* if no room for buffer, use small buffer */ + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + iop->_flag &= ~_IOLBF; + iop->_flag |= _IONBF; + } + } + iop->_ptr = iop->_base; +} + +/* The function _bufsync is called because interrupts and other signals + * which occur in between the decrementing of iop->_cnt and the incrementing + * of iop->_ptr, or in other contexts as well, may upset the synchronization + * of iop->_cnt and iop->ptr. If this happens, calling _bufsync should + * resynchronize the two quantities (this is not always possible). Resyn- + * chronization guarantees that putc invocations will not write beyond + * the end of the buffer. Note that signals during _bufsync can cause + * _bufsync to do the wrong thing, but usually with benign effects. + */ + +_bufsync(iop) +register FILE *iop; +{ + register int spaceleft; + register unsigned char *bufend = iop->_base + iop->_bufsiz; + + if ((spaceleft = bufend - iop->_ptr) < 0) + iop->_ptr = bufend; + else if (spaceleft < iop->_cnt) + iop->_cnt = spaceleft; +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/fopen.c b/usr/src/lib/libbc/libc/stdio/sys5/fopen.c new file mode 100644 index 0000000000..d7cb1ee876 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/fopen.c @@ -0,0 +1,91 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.8 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <fcntl.h> + +extern int open(), fclose(); +extern FILE *_findiop(), *_endopen(); + +FILE * +fopen(file, mode) +char *file, *mode; +{ + return (_endopen(file, mode, _findiop())); +} + +FILE * +freopen(file, mode, iop) +char *file, *mode; +register FILE *iop; +{ + (void) fclose(iop); /* doesn't matter if this fails */ + return (_endopen(file, mode, iop)); +} + +static FILE * +_endopen(file, mode, iop) +char *file, *mode; +register FILE *iop; +{ + register int plus, oflag, fd; + + if (iop == NULL || file == NULL || file[0] == '\0') + return (NULL); + plus = (mode[1] == '+'); + switch (mode[0]) { + case 'w': + oflag = (plus ? O_RDWR : O_WRONLY) | O_TRUNC | O_CREAT; + break; + case 'a': + oflag = (plus ? O_RDWR : O_WRONLY) | O_APPEND | O_CREAT; + break; + case 'r': + oflag = plus ? O_RDWR : O_RDONLY; + break; + default: + return (NULL); + } + if ((fd = open(file, oflag, 0666)) < 0) + return (NULL); + iop->_cnt = 0; + iop->_file = fd; + iop->_flag = plus ? _IORW : (mode[0] == 'r') ? _IOREAD : _IOWRT; + if (mode[0] == 'a') { + if (!plus) { + /* if update only mode, move file pointer to the end + of the file */ + if ((lseek(fd,0L,2)) < 0) { + (void) close(fd); + return NULL; + } + } + } + iop->_base = iop->_ptr = NULL; + iop->_bufsiz = 0; + return (iop); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/fprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/fprintf.c new file mode 100644 index 0000000000..8daed9d391 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/fprintf.c @@ -0,0 +1,74 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +fprintf(iop, format, va_alist) +FILE *iop; +char *format; +va_dcl +{ + unsigned char localbuf[BUFSIZ]; + register int count; + va_list ap; + + va_start(ap); + if (!(iop->_flag & _IOWRT)) { + /* if no write flag */ + if (iop->_flag & _IORW) { + /* if ok, cause read-write */ + iop->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + if (iop->_flag & _IONBF) { + iop->_flag &= ~_IONBF; + iop->_ptr = iop->_base = localbuf; + iop->_bufsiz = BUFSIZ; + count = _doprnt(format, ap, iop); + fflush(iop); + iop->_flag |= _IONBF; + iop->_base = NULL; + iop->_bufsiz = 0; + iop->_cnt = 0; + } else + count = _doprnt(format, ap, iop); + va_end(ap); + return(ferror(iop)? EOF: count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/printf.c b/usr/src/lib/libbc/libc/stdio/sys5/printf.c new file mode 100644 index 0000000000..0a320e4d86 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/printf.c @@ -0,0 +1,61 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS1*/ +int +printf(format, va_alist) +char *format; +va_dcl +{ + register int count; + va_list ap; + + va_start(ap); + if (!(stdout->_flag & _IOWRT)) { + /* if no write flag */ + if (stdout->_flag & _IORW) { + /* if ok, cause read-write */ + stdout->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + count = _doprnt(format, ap, stdout); + va_end(ap); + return(ferror(stdout)? EOF: count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/setbuf.c b/usr/src/lib/libbc/libc/stdio/sys5/setbuf.c new file mode 100644 index 0000000000..3ad6092e4d --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/setbuf.c @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern void free(); +extern int isatty(); +extern unsigned char (*_smbuf)[_SBFSIZ]; +extern void _getsmbuf(); + +void +setbuf(iop, buf) +register FILE *iop; +char *buf; +{ + register int fno = fileno(iop); /* file number */ + + if(iop->_base != NULL && iop->_flag & _IOMYBUF) + free((char*)iop->_base); + iop->_flag &= ~(_IOMYBUF | _IONBF | _IOLBF); + if((iop->_base = (unsigned char*)buf) == NULL) { + iop->_flag |= _IONBF; /* file unbuffered except in fastio */ + /* use small buffers reserved for this */ + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + } + else { /* regular buffered I/O, standard buffer size */ + if (isatty(fno)) + iop->_flag |= _IOLBF; + iop->_bufsiz = BUFSIZ; + } + iop->_ptr = iop->_base; + iop->_cnt = 0; +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/sprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/sprintf.c new file mode 100644 index 0000000000..a86dbc8be5 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/sprintf.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> +#include <values.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +sprintf(string, format, va_alist) +char *string, *format; +va_dcl +{ + register int count; + FILE siop; + va_list ap; + + siop._cnt = MAXINT; + siop._base = siop._ptr = (unsigned char *)string; + siop._flag = _IOWRT+_IOSTRG; + va_start(ap); + count = _doprnt(format, ap, &siop); + va_end(ap); + *siop._ptr = '\0'; /* plant terminating null character */ + return(count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/vfprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/vfprintf.c new file mode 100644 index 0000000000..502add53e5 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/vfprintf.c @@ -0,0 +1,71 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +vfprintf(iop, format, ap) +FILE *iop; +char *format; +va_list ap; +{ + unsigned char localbuf[BUFSIZ]; + register int count; + + if (!(iop->_flag & _IOWRT)) { + /* if no write flag */ + if (iop->_flag & _IORW) { + /* if ok, cause read-write */ + iop->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + if (iop->_flag & _IONBF) { + iop->_flag &= ~_IONBF; + iop->_ptr = iop->_base = localbuf; + iop->_bufsiz = BUFSIZ; + count = _doprnt(format, ap, iop); + fflush(iop); + iop->_flag |= _IONBF; + iop->_base = NULL; + iop->_bufsiz = 0; + iop->_cnt = 0; + } else + count = _doprnt(format, ap, iop); + return(ferror(iop)? EOF: count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/vprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/vprintf.c new file mode 100644 index 0000000000..442c95cb5f --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/vprintf.c @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +/* + * Portions of this source code were derived from Berkeley 4.3 BSD + * under license from the Regents of the University of California. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS1*/ +int +vprintf(format, ap) +char *format; +va_list ap; +{ + register int count; + + if (!(stdout->_flag & _IOWRT)) { + /* if no write flag */ + if (stdout->_flag & _IORW) { + /* if ok, cause read-write */ + stdout->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + count = _doprnt(format, ap, stdout); + return(ferror(stdout)? EOF: count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/vsprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/vsprintf.c new file mode 100644 index 0000000000..c86412d4fb --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/vsprintf.c @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +/* + * Portions of this source code were derived from Berkeley 4.3 BSD + * under license from the Regents of the University of California. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> +#include <values.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +vsprintf(string, format, ap) +char *string, *format; +va_list ap; +{ + register int count; + FILE siop; + + siop._cnt = MAXINT; + siop._base = siop._ptr = (unsigned char *)string; + siop._flag = _IOWRT+_IOSTRG; + count = _doprnt(format, ap, &siop); + *siop._ptr = '\0'; /* plant terminating null character */ + return(count); +} |