diff options
Diffstat (limited to 'lib/libc/stdio')
92 files changed, 0 insertions, 12090 deletions
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc deleted file mode 100644 index 97b403a..0000000 --- a/lib/libc/stdio/Makefile.inc +++ /dev/null @@ -1,43 +0,0 @@ -# @(#)Makefile.inc 8.3 (Berkeley) 4/17/94 -# $Id: Makefile.inc,v 1.10 1997/10/15 16:16:07 bde Exp $ - -# stdio sources -.PATH: ${.CURDIR}/../libc/stdio - -SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c \ - fgetc.c fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c fopen.c \ - fprintf.c fpurge.c fputc.c fputs.c fread.c freopen.c fscanf.c \ - fseek.c fsetpos.c ftell.c funopen.c fvwrite.c fwalk.c fwrite.c \ - getc.c getchar.c gets.c getw.c makebuf.c mktemp.c perror.c \ - printf.c putc.c putchar.c puts.c putw.c refill.c remove.c rewind.c \ - rget.c scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c \ - sscanf.c stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vasprintf.c \ - vfprintf.c vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c \ - vsscanf.c wbuf.c wsetup.c - -.if ${LIB} == "c" -MAN3+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fopen.3 fputs.3 \ - fread.3 fseek.3 funopen.3 getc.3 mktemp.3 printf.3 putc.3 remove.3 \ - scanf.3 setbuf.3 stdio.3 tmpnam.3 ungetc.3 - -MLINKS+=ferror.3 clearerr.3 ferror.3 feof.3 ferror.3 fileno.3 -MLINKS+=fflush.3 fpurge.3 -MLINKS+=fgets.3 gets.3 -MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3 -MLINKS+=fputs.3 puts.3 -MLINKS+=fread.3 fwrite.3 -MLINKS+=fseek.3 fgetpos.3 fseek.3 fsetpos.3 fseek.3 ftell.3 fseek.3 rewind.3 -MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3 -MLINKS+=getc.3 fgetc.3 getc.3 getchar.3 getc.3 getw.3 -MLINKS+=mktemp.3 mkstemp.3 -MLINKS+=printf.3 asprintf.3 printf.3 fprintf.3 \ - printf.3 snprintf.3 printf.3 sprintf.3 \ - printf.3 vasprintf.3 \ - printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \ - printf.3 vsprintf.3 -MLINKS+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3 -MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \ - scanf.3 vsscanf.3 -MLINKS+=setbuf.3 setbuffer.3 setbuf.3 setlinebuf.3 setbuf.3 setvbuf.3 -MLINKS+=tmpnam.3 tempnam.3 tmpnam.3 tmpfile.3 -.endif diff --git a/lib/libc/stdio/asprintf.c b/lib/libc/stdio/asprintf.c deleted file mode 100644 index 9b4d05b..0000000 --- a/lib/libc/stdio/asprintf.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * Copyright (c) 1996 Peter Wemm <peter@freebsd.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_RCS) && !defined(lint) -static char rcsid[] = "$Id$"; -#endif /* LIBC_RCS and not lint */ - -#include <stdio.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -#if __STDC__ -int -asprintf(char **str, char const *fmt, ...) -#else -int -asprintf(str, fmt, va_alist) - char **str; - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = vasprintf(str, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c deleted file mode 100644 index a230119..0000000 --- a/lib/libc/stdio/clrerr.c +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#undef clearerr -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -void -clearerr(fp) - FILE *fp; -{ -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - __sclearerr(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif -} diff --git a/lib/libc/stdio/fclose.3 b/lib/libc/stdio/fclose.3 deleted file mode 100644 index 77f3316..0000000 --- a/lib/libc/stdio/fclose.3 +++ /dev/null @@ -1,93 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)fclose.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt FCLOSE 3 -.Os -.Sh NAME -.Nm fclose -.Nd close a stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn fclose "FILE *stream" -.Sh DESCRIPTION -The -.Fn fclose -function -dissociates the named -.Fa stream -from its underlying file or set of functions. -If the stream was being used for output, any buffered data is written -first, using -.Xr fflush 3 . -.Sh RETURN VALUES -Upon successful completion 0 is returned. -Otherwise, -.Dv EOF -is returned and the global variable -.Va errno -is set to indicate the error. -In either case no further access to the stream is possible. -.Sh ERRORS -.Bl -tag -width [EBADF] -.It Bq Er EBADF -The argument -.Fa stream -is not an open stream. -.El -.Pp -The -.Fn fclose -function -may also fail and set -.Va errno -for any of the errors specified for the routines -.Xr close 2 -or -.Xr fflush 3 . -.Sh SEE ALSO -.Xr close 2 , -.Xr fflush 3 , -.Xr fopen 3 , -.Xr setbuf 3 -.Sh STANDARDS -The -.Fn fclose -function -conforms to -.St -ansiC . diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c deleted file mode 100644 index 1104bd0..0000000 --- a/lib/libc/stdio/fclose.c +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -int -fclose(fp) - register FILE *fp; -{ - register int r; - - if (fp->_flags == 0) { /* not open! */ - errno = EBADF; - return (EOF); - } -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - r = fp->_flags & __SWR ? __sflush(fp) : 0; - if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) - r = EOF; - if (fp->_flags & __SMBF) - free((char *)fp->_bf._base); - if (HASUB(fp)) - FREEUB(fp); - if (HASLB(fp)) - FREELB(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - fp->_flags = 0; /* Release this FILE for reuse. */ - fp->_file = -1; - fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ - return (r); -} diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c deleted file mode 100644 index 48ea401..0000000 --- a/lib/libc/stdio/fdopen.c +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <fcntl.h> -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include "local.h" - -FILE * -fdopen(fd, mode) - int fd; - const char *mode; -{ - register FILE *fp; - static int nofile; - int flags, oflags, fdflags, tmp; - - if (nofile == 0) - nofile = getdtablesize(); - - if ((flags = __sflags(mode, &oflags)) == 0) - return (NULL); - - /* Make sure the mode the user wants is a subset of the actual mode. */ - if ((fdflags = fcntl(fd, F_GETFL, 0)) < 0) - return (NULL); - tmp = fdflags & O_ACCMODE; - if (tmp != O_RDWR && (tmp != (oflags & O_ACCMODE))) { - errno = EINVAL; - return (NULL); - } - - if ((fp = __sfp()) == NULL) - return (NULL); - fp->_flags = flags; - /* - * If opened for appending, but underlying descriptor does not have - * O_APPEND bit set, assert __SAPP so that __swrite() will lseek to - * end before each write. - */ - if ((oflags & O_APPEND) && !(fdflags & O_APPEND)) - fp->_flags |= __SAPP; - fp->_file = fd; - fp->_cookie = fp; - fp->_read = __sread; - fp->_write = __swrite; - fp->_seek = __sseek; - fp->_close = __sclose; - return (fp); -} diff --git a/lib/libc/stdio/feof.c b/lib/libc/stdio/feof.c deleted file mode 100644 index e42df61..0000000 --- a/lib/libc/stdio/feof.c +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)feof.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> - -/* - * A subroutine version of the macro feof. - */ -#undef feof - -int -feof(fp) - FILE *fp; -{ - return (__sfeof(fp)); -} diff --git a/lib/libc/stdio/ferror.3 b/lib/libc/stdio/ferror.3 deleted file mode 100644 index 411999d..0000000 --- a/lib/libc/stdio/ferror.3 +++ /dev/null @@ -1,100 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)ferror.3 8.2 (Berkeley) 4/19/94 -.\" -.Dd April 19, 1994 -.Dt FERROR 3 -.Os -.Sh NAME -.Nm clearerr , -.Nm feof , -.Nm ferror , -.Nm fileno -.Nd check and reset stream status -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft void -.Fn clearerr "FILE *stream" -.Ft int -.Fn feof "FILE *stream" -.Ft int -.Fn ferror "FILE *stream" -.Ft int -.Fn fileno "FILE *stream" -.Sh DESCRIPTION -The function -.Fn clearerr -clears the end-of-file and error indicators for the stream pointed -to by -.Fa stream . -.Pp -The function -.Fn feof -tests the end-of-file indicator for the stream pointed to by -.Fa stream , -returning non-zero if it is set. -The end-of-file indicator can only be cleared by the function -.Fn clearerr . -.Pp -The function -.Fn ferror -tests the error indicator for the stream pointed to by -.Fa stream , -returning non-zero if it is set. -The error indicator can only be reset by the -.Fn clearerr -function. -.Pp -The function -.Fn fileno -examines the argument -.Fa stream -and returns its integer descriptor. -.Sh ERRORS -These functions should not fail and do not set the external -variable -.Va errno . -.Sh SEE ALSO -.Xr open 2 , -.Xr stdio 3 -.Sh STANDARDS -The functions -.Fn clearerr , -.Fn feof , -and -.Fn ferror -conform to -.St -ansiC . diff --git a/lib/libc/stdio/ferror.c b/lib/libc/stdio/ferror.c deleted file mode 100644 index 8a68500..0000000 --- a/lib/libc/stdio/ferror.c +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)ferror.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> - -/* - * A subroutine version of the macro ferror. - */ -#undef ferror - -int -ferror(fp) - FILE *fp; -{ - return (__sferror(fp)); -} diff --git a/lib/libc/stdio/fflush.3 b/lib/libc/stdio/fflush.3 deleted file mode 100644 index abc8c67..0000000 --- a/lib/libc/stdio/fflush.3 +++ /dev/null @@ -1,110 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)fflush.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt FFLUSH 3 -.Os -.Sh NAME -.Nm fflush , -.Nm fpurge -.Nd flush a stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn fflush "FILE *stream" -.Ft int -.Fn fpurge "FILE *stream" -.Sh DESCRIPTION -The function -.Fn fflush -forces a write of all buffered data for the given output or update -.Fa stream -via the stream's underlying write function. -The open status of the stream is unaffected. -.Pp -If the -.Fa stream -argument is -.Dv NULL , -.Fn fflush -flushes -.Em all -open output streams. -.Pp -The function -.Fn fpurge -erases any input or output buffered in the given -.Fa stream . -For output streams this discards any unwritten output. -For input streams this discards any input read from the underlying object -but not yet obtained via -.Xr getc 3 ; -this includes any text pushed back via -.Xr ungetc . -.Sh RETURN VALUES -Upon successful completion 0 is returned. -Otherwise, -.Dv EOF -is returned and the global variable -.Va errno -is set to indicate the error. -.Sh ERRORS -.Bl -tag -width [EBADF] -.It Bq Er EBADF -.Fa Stream -is not an open stream, or, in the case of -.Fn fflush , -not a stream open for writing. -.El -.Pp -The function -.Fn fflush -may also fail and set -.Va errno -for any of the errors specified for the routine -.Xr write 2 . -.Sh SEE ALSO -.Xr write 2 , -.Xr fclose 3 , -.Xr fopen 3 , -.Xr setbuf 3 -.Sh STANDARDS -The -.Fn fflush -function -conforms to -.St -ansiC . diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c deleted file mode 100644 index aed57ec..0000000 --- a/lib/libc/stdio/fflush.c +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <errno.h> -#include <stdio.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* Flush a single file, or (if fp is NULL) all files. */ -int -fflush(fp) - register FILE *fp; -{ - int retval; - - if (fp == NULL) - return (_fwalk(__sflush)); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - if ((fp->_flags & (__SWR | __SRW)) == 0) { - errno = EBADF; - retval = EOF; - } else { - retval = __sflush(fp); - } -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); -} - -int -__sflush(fp) - register FILE *fp; -{ - register unsigned char *p; - register int n, t; - - t = fp->_flags; - if ((t & __SWR) == 0) - return (0); - - if ((p = fp->_bf._base) == NULL) - return (0); - - n = fp->_p - p; /* write this much */ - - /* - * Set these immediately to avoid problems with longjmp and to allow - * exchange buffering (via setvbuf) in user write function. - */ - fp->_p = p; - fp->_w = t & (__SLBF|__SNBF) ? 0 : fp->_bf._size; - - for (; n > 0; n -= t, p += t) { - t = (*fp->_write)(fp->_cookie, (char *)p, n); - if (t <= 0) { - fp->_flags |= __SERR; - return (EOF); - } - } - return (0); -} diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c deleted file mode 100644 index f93a004..0000000 --- a/lib/libc/stdio/fgetc.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -int -fgetc(fp) - FILE *fp; -{ - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sgetc(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); -} diff --git a/lib/libc/stdio/fgetln.3 b/lib/libc/stdio/fgetln.3 deleted file mode 100644 index e6c395d..0000000 --- a/lib/libc/stdio/fgetln.3 +++ /dev/null @@ -1,124 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94 -.\" -.Dd April 19, 1994 -.Dt FGETLN 3 -.Os -.Sh NAME -.Nm fgetln -.Nd get a line from a stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft char * -.Fn fgetln "FILE *stream" "size_t *len" -.Sh DESCRIPTION -The -.Fn fgetln -function -returns a pointer to the next line from the stream referenced by -.Fa stream . -This line is -.Em not -a C string as it does not end with a terminating -.Dv NUL -character. -The length of the line, including the final newline, -is stored in the memory location to which -.Fa len -points. -(Note, however, that if the line is the last -in a file that does not end in a newline, -the returned text will not contain a newline.) -.Sh RETURN VALUES -Upon successful completion a pointer is returned; -this pointer becomes invalid after the next -.Tn I/O -operation on -.Fa stream -(whether successful or not) -or as soon as the stream is closed. -Otherwise, -.Dv NULL -is returned. -The -.Fn fgetln -function -does not distinguish between end-of-file and error; the routines -.Xr feof 3 -and -.Xr ferror 3 -must be used -to determine which occurred. -If an error occurs, the global variable -.Va errno -is set to indicate the error. -The end-of-file condition is remembered, even on a terminal, and all -subsequent attempts to read will return -.Dv NULL -until the condition is -cleared with -.Xr clearerr 3 . -.Pp -The text to which the returned pointer points may be modified, -provided that no changes are made beyond the returned size. -These changes are lost as soon as the pointer becomes invalid. -.Sh ERRORS -.Bl -tag -width [EBADF] -.It Bq Er EBADF -The argument -.Fa stream -is not a stream open for reading. -.El -.Pp -The -.Fn fgetln -function -may also fail and set -.Va errno -for any of the errors specified for the routines -.Xr fflush 3 , -.Xr malloc 3 , -.Xr read 2 , -.Xr stat 2 , -or -.Xr realloc 3 . -.Sh SEE ALSO -.Xr ferror 3 , -.Xr fgets 3 , -.Xr fopen 3 , -.Xr putc 3 -.Sh HISTORY -The -.Fn fgetln -function first appeared in -.Bx 4.4 . diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c deleted file mode 100644 index 7c5742b..0000000 --- a/lib/libc/stdio/fgetln.c +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fgetln.c 8.2 (Berkeley) 1/2/94"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "local.h" - -/* - * Expand the line buffer. Return -1 on error. -#ifdef notdef - * The `new size' does not account for a terminating '\0', - * so we add 1 here. -#endif - */ -int -__slbexpand(fp, newsize) - FILE *fp; - size_t newsize; -{ - void *p; - -#ifdef notdef - ++newsize; -#endif - if (fp->_lb._size >= newsize) - return (0); - if ((p = realloc(fp->_lb._base, newsize)) == NULL) - return (-1); - fp->_lb._base = p; - fp->_lb._size = newsize; - return (0); -} - -/* - * Get an input line. The returned pointer often (but not always) - * points into a stdio buffer. Fgetln does not alter the text of - * the returned line (which is thus not a C string because it will - * not necessarily end with '\0'), but does allow callers to modify - * it if they wish. Thus, we set __SMOD in case the caller does. - */ -char * -fgetln(fp, lenp) - register FILE *fp; - size_t *lenp; -{ - register unsigned char *p; - register size_t len; - size_t off; - - /* make sure there is input */ - if (fp->_r <= 0 && __srefill(fp)) { - *lenp = 0; - return (NULL); - } - - /* look for a newline in the input */ - if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) != NULL) { - register char *ret; - - /* - * Found one. Flag buffer as modified to keep fseek from - * `optimising' a backward seek, in case the user stomps on - * the text. - */ - p++; /* advance over it */ - ret = (char *)fp->_p; - *lenp = len = p - fp->_p; - fp->_flags |= __SMOD; - fp->_r -= len; - fp->_p = p; - return (ret); - } - - /* - * We have to copy the current buffered data to the line buffer. - * As a bonus, though, we can leave off the __SMOD. - * - * OPTIMISTIC is length that we (optimistically) expect will - * accomodate the `rest' of the string, on each trip through the - * loop below. - */ -#define OPTIMISTIC 80 - - for (len = fp->_r, off = 0;; len += fp->_r) { - register size_t diff; - - /* - * Make sure there is room for more bytes. Copy data from - * file buffer to line buffer, refill file and look for - * newline. The loop stops only when we find a newline. - */ - if (__slbexpand(fp, len + OPTIMISTIC)) - goto error; - (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, - len - off); - off = len; - if (__srefill(fp)) - break; /* EOF or error: return partial line */ - if ((p = memchr((void *)fp->_p, '\n', (size_t)fp->_r)) == NULL) - continue; - - /* got it: finish up the line (like code above) */ - p++; - diff = p - fp->_p; - len += diff; - if (__slbexpand(fp, len)) - goto error; - (void)memcpy((void *)(fp->_lb._base + off), (void *)fp->_p, - diff); - fp->_r -= diff; - fp->_p = p; - break; - } - *lenp = len; -#ifdef notdef - fp->_lb._base[len] = 0; -#endif - return ((char *)fp->_lb._base); - -error: - *lenp = 0; /* ??? */ - return (NULL); /* ??? */ -} diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c deleted file mode 100644 index ab8a9e5..0000000 --- a/lib/libc/stdio/fgetpos.c +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -int -fgetpos(fp, pos) - FILE *fp; - fpos_t *pos; -{ - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = (*pos = ftell(fp)) == (fpos_t)-1; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return(retval); -} diff --git a/lib/libc/stdio/fgets.3 b/lib/libc/stdio/fgets.3 deleted file mode 100644 index 22ce5e6..0000000 --- a/lib/libc/stdio/fgets.3 +++ /dev/null @@ -1,156 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)fgets.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt FGETS 3 -.Os -.Sh NAME -.Nm fgets , -.Nm gets -.Nd get a line from a stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft char * -.Fn fgets "char *str" "int size" "FILE *stream" -.Ft char * -.Fn gets "char *str" -.Sh DESCRIPTION -The -.Fn fgets -function -reads at most one less than the number of characters specified by -.Fa size -from the given -.Fa stream -and stores them in the string -.Fa str . -Reading stops when a newline character is found, -at end-of-file or error. -The newline, if any, is retained. -If any characters are read and there is no error, a -.Ql \e0 -character is appended to end the string. -.Pp -The -.Fn gets -function -is equivalent to -.Fn fgets -with an infinite -.Fa size -and a -.Fa stream -of -.Em stdin , -except that the newline character (if any) is not stored in the string. -It is the caller's responsibility to ensure that the input line, -if any, is sufficiently short to fit in the string. -.Sh RETURN VALUES -.Pp -Upon successful completion, -.Fn fgets -and -.Fn gets -return -a pointer to the string. -If end-of-file occurs before any characters are read, -they return -.Dv NULL -and the buffer contents is unchanged. -If an error occurs, -they return -.Dv NULL -and the buffer contents is indeterminate. -The -.Fn fgets -and -.Fn gets -functions -do not distinguish between end-of-file and error, and callers must use -.Xr feof 3 -and -.Xr ferror 3 -to determine which occurred. -.Sh ERRORS -.Bl -tag -width [EBADF] -.It Bq Er EBADF -The given -.Fa stream -is not a readable stream. -.El -.Pp -The function -.Fn fgets -may also fail and set -.Va errno -for any of the errors specified for the routines -.Xr fflush 3 , -.Xr fstat 2 , -.Xr read 2 , -or -.Xr malloc 3 . -.Pp -The function -.Fn gets -may also fail and set -.Va errno -for any of the errors specified for the routine -.Xr getchar 3 . -.Sh SEE ALSO -.Xr feof 3 , -.Xr ferror 3 , -.Xr fgetln 3 -.Sh STANDARDS -The functions -.Fn fgets -and -.Fn gets -conform to -.St -ansiC . -.Sh BUGS -Since it is usually impossible to ensure that the next input line -is less than some arbitrary length, and because overflowing the -input buffer is almost invariably a security violation, programs -should -.Em NEVER -use -.Fn gets . -The -.Fn gets -function -exists purely to conform to -.St -ansiC . diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c deleted file mode 100644 index 434fc07..0000000 --- a/lib/libc/stdio/fgets.c +++ /dev/null @@ -1,126 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <string.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * Read at most n-1 characters from the given file. - * Stop when a newline has been read, or the count runs out. - * Return first argument, or NULL if no characters were read. - */ -char * -fgets(buf, n, fp) - char *buf; - register int n; - register FILE *fp; -{ - register size_t len; - register char *s; - register unsigned char *p, *t; - - if (n <= 0) /* sanity check */ - return (NULL); - -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - s = buf; - n--; /* leave space for NUL */ - while (n != 0) { - /* - * If the buffer is empty, refill it. - */ - if ((len = fp->_r) <= 0) { - if (__srefill(fp)) { - /* EOF/error: stop with partial or no line */ - if (s == buf) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (NULL); - } - break; - } - len = fp->_r; - } - p = fp->_p; - - /* - * Scan through at most n bytes of the current buffer, - * looking for '\n'. If found, copy up to and including - * newline, and stop. Otherwise, copy entire chunk - * and loop. - */ - if (len > n) - len = n; - t = memchr((void *)p, '\n', len); - if (t != NULL) { - len = ++t - p; - fp->_r -= len; - fp->_p = t; - (void)memcpy((void *)s, (void *)p, len); - s[len] = 0; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (buf); - } - fp->_r -= len; - fp->_p += len; - (void)memcpy((void *)s, (void *)p, len); - s += len; - n -= len; - } - *s = 0; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (buf); -} diff --git a/lib/libc/stdio/fileno.c b/lib/libc/stdio/fileno.c deleted file mode 100644 index 6ceac0c..0000000 --- a/lib/libc/stdio/fileno.c +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> - -/* - * A subroutine version of the macro fileno. - */ -#undef fileno - -int -fileno(fp) - FILE *fp; -{ - return (__sfileno(fp)); -} diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c deleted file mode 100644 index 8a6cddd..0000000 --- a/lib/libc/stdio/findfp.c +++ /dev/null @@ -1,175 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)findfp.c 8.2 (Berkeley) 1/4/94"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include <stdlib.h> -#include <string.h> -#include "local.h" -#include "glue.h" - -int __sdidinit; - -#define NDYNAMIC 10 /* add ten more whenever necessary */ - -#define std(flags, file) \ - {0,0,0,flags,file,{0},0,__sF+file,__sclose,__sread,__sseek,__swrite} -/* p r w flags file _bf z cookie close read seek write */ - - /* the usual - (stdin + stdout + stderr) */ -static FILE usual[FOPEN_MAX - 3]; -static struct glue uglue = { 0, FOPEN_MAX - 3, usual }; - -FILE __sF[3] = { - std(__SRD, STDIN_FILENO), /* stdin */ - std(__SWR, STDOUT_FILENO), /* stdout */ - std(__SWR|__SNBF, STDERR_FILENO) /* stderr */ -}; -struct glue __sglue = { &uglue, 3, __sF }; - -static struct glue * moreglue __P((int)); - -static struct glue * -moreglue(n) - register int n; -{ - register struct glue *g; - register FILE *p; - static FILE empty; - - g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); - if (g == NULL) - return (NULL); - p = (FILE *)ALIGN(g + 1); - g->next = NULL; - g->niobs = n; - g->iobs = p; - while (--n >= 0) - *p++ = empty; - return (g); -} - -/* - * Find a free FILE for fopen et al. - */ -FILE * -__sfp() -{ - register FILE *fp; - register int n; - register struct glue *g; - - if (!__sdidinit) - __sinit(); - for (g = &__sglue;; g = g->next) { - for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) - if (fp->_flags == 0) - goto found; - if (g->next == NULL && (g->next = moreglue(NDYNAMIC)) == NULL) - break; - } - return (NULL); -found: - fp->_flags = 1; /* reserve this slot; caller sets real flags */ - fp->_p = NULL; /* no current pointer */ - fp->_w = 0; /* nothing to read or write */ - fp->_r = 0; - fp->_bf._base = NULL; /* no buffer */ - fp->_bf._size = 0; - fp->_lbfsize = 0; /* not line buffered */ - fp->_file = -1; /* no file */ -/* fp->_cookie = <any>; */ /* caller sets cookie, _read/_write etc */ - fp->_ub._base = NULL; /* no ungetc buffer */ - fp->_ub._size = 0; - fp->_lb._base = NULL; /* no line buffer */ - fp->_lb._size = 0; - return (fp); -} - -/* - * XXX. Force immediate allocation of internal memory. Not used by stdio, - * but documented historically for certain applications. Bad applications. - */ -__warn_references(f_prealloc, - "warning: this program uses f_prealloc(), which is stupid."); - -void -f_prealloc() -{ - register struct glue *g; - int n; - - n = getdtablesize() - FOPEN_MAX + 20; /* 20 for slop. */ - for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next) - /* void */; - if (n > 0) - g->next = moreglue(n); -} - -/* - * exit() calls _cleanup() through *__cleanup, set whenever we - * open or buffer a file. This chicanery is done so that programs - * that do not use stdio need not link it all in. - * - * The name `_cleanup' is, alas, fairly well known outside stdio. - */ -void -_cleanup() -{ - /* (void) _fwalk(fclose); */ - (void) _fwalk(__sflush); /* `cheating' */ -} - -/* - * __sinit() is called whenever stdio's internal variables must be set up. - */ -void -__sinit() -{ - /* make sure we clean up on exit */ - __cleanup = _cleanup; /* conservative */ - __sdidinit = 1; -} diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c deleted file mode 100644 index 4ef0db1..0000000 --- a/lib/libc/stdio/flags.c +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)flags.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/file.h> -#include <stdio.h> -#include <errno.h> -#include "local.h" - -/* - * Return the (stdio) flags for a given mode. Store the flags - * to be passed to an open() syscall through *optr. - * Return 0 on error. - */ -int -__sflags(mode, optr) - register const char *mode; - int *optr; -{ - register int ret, m, o; - - switch (*mode++) { - - case 'r': /* open for reading */ - ret = __SRD; - m = O_RDONLY; - o = 0; - break; - - case 'w': /* open for writing */ - ret = __SWR; - m = O_WRONLY; - o = O_CREAT | O_TRUNC; - break; - - case 'a': /* open for appending */ - ret = __SWR; - m = O_WRONLY; - o = O_CREAT | O_APPEND; - break; - - default: /* illegal mode */ - errno = EINVAL; - return (0); - } - - /* [rwa]\+ or [rwa]b\+ means read and write */ - if (*mode == '+' || (*mode == 'b' && mode[1] == '+')) { - ret = __SRW; - m = O_RDWR; - } - *optr = m | o; - return (ret); -} diff --git a/lib/libc/stdio/floatio.h b/lib/libc/stdio/floatio.h deleted file mode 100644 index c2089fe..0000000 --- a/lib/libc/stdio/floatio.h +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)floatio.h 8.1 (Berkeley) 6/4/93 - */ - -/* - * Floating point scanf/printf (input/output) definitions. - */ - -/* 11-bit exponent (VAX G floating point) is 308 decimal digits */ -#define MAXEXP 308 -/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */ -#define MAXFRACT 39 diff --git a/lib/libc/stdio/fopen.3 b/lib/libc/stdio/fopen.3 deleted file mode 100644 index f954d6c..0000000 --- a/lib/libc/stdio/fopen.3 +++ /dev/null @@ -1,237 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)fopen.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt FOPEN 3 -.Os -.Sh NAME -.Nm fopen , -.Nm fdopen , -.Nm freopen -.Nd stream open functions -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft FILE * -.Fn fopen "const char *path" "const char *mode" -.Ft FILE * -.Fn fdopen "int fildes" "const char *mode" -.Ft FILE * -.Fn freopen "const char *path" "const char *mode" "FILE *stream" -.Sh DESCRIPTION -The -.Fn fopen -function -opens the file whose name is the string pointed to by -.Fa path -and associates a stream with it. -.Pp -The argument -.Fa mode -points to a string beginning with one of the following -sequences (Additional characters may follow these sequences.): -.Bl -tag -width indent -.It Dq Li r -Open text file for reading. -The stream is positioned at the beginning of the file. -.It Dq Li r+ -Open for reading and writing. -The stream is positioned at the beginning of the file. -.It Dq Li w -Truncate file to zero length or create text file for writing. -The stream is positioned at the beginning of the file. -.It Dq Li w+ -Open for reading and writing. -The file is created if it does not exist, otherwise it is truncated. -The stream is positioned at the beginning of the file. -.It Dq Li a -Open for writing. -The file is created if it does not exist. -The stream is positioned at the end of the file. -.It Dq Li a+ -Open for reading and writing. -The file is created if it does not exist. -The stream is positioned at the end of the file. -.El -.Pp -The -.Fa mode -string can also include the letter ``b'' either as a third character or -as a character between the characters in any of the two-character strings -described above. -This is strictly for compatibility with -.St -ansiC -and has no effect; the ``b'' is ignored. -.Pp -Any created files will have mode -.Pf \\*q Dv S_IRUSR -\&| -.Dv S_IWUSR -\&| -.Dv S_IRGRP -\&| -.Dv S_IWGRP -\&| -.Dv S_IROTH -\&| -.Dv S_IWOTH Ns \\*q -.Pq Li 0666 , -as modified by the process' -umask value (see -.Xr umask 2 ) . -.Pp -Reads and writes may be intermixed on read/write streams in any order, -and do not require an intermediate seek as in previous versions of -.Em stdio . -This is not portable to other systems, however; -.Tn ANSI C -requires that -a file positioning function intervene between output and input, unless -an input operation encounters end-of-file. -.Pp -The -.Fn fdopen -function associates a stream with the existing file descriptor, -.Fa fildes . -The -.Fa mode -of the stream must be compatible with the mode of the file descriptor. -.Pp -The -.Fn freopen -function -opens the file whose name is the string pointed to by -.Fa path -and associates the stream pointed to by -.Fa stream -with it. -The original stream (if it exists) is closed. -The -.Fa mode -argument is used just as in the -.Fn fopen -function. -The primary use of the -.Fn freopen -function -is to change the file associated with a -standard text stream -.Pf ( Em stderr , -.Em stdin , -or -.Em stdout ) . -.Sh RETURN VALUES -Upon successful completion -.Fn fopen , -.Fn fdopen -and -.Fn freopen -return a -.Tn FILE -pointer. -Otherwise, -.Dv NULL -is returned and the global variable -.Va errno -is set to indicate the error. -.Sh ERRORS -.Bl -tag -width [EINVAL] -.It Bq Er EINVAL -The -.Fa mode -provided to -.Fn fopen , -.Fn fdopen , -or -.Fn freopen -was invalid. -.El -.Pp -The -.Fn fopen , -.Fn fdopen -and -.Fn freopen -functions -may also fail and set -.Va errno -for any of the errors specified for the routine -.Xr malloc 3 . -.Pp -The -.Fn fopen -function -may also fail and set -.Va errno -for any of the errors specified for the routine -.Xr open 2 . -.Pp -The -.Fn fdopen -function -may also fail and set -.Va errno -for any of the errors specified for the routine -.Xr fcntl 2 . -.Pp -The -.Fn freopen -function -may also fail and set -.Va errno -for any of the errors specified for the routines -.Xr open 2 , -.Xr fclose 3 -and -.Xr fflush 3 . -.Sh SEE ALSO -.Xr open 2 , -.Xr fclose 3 , -.Xr fseek 3 , -.Xr funopen 3 -.Sh STANDARDS -The -.Fn fopen -and -.Fn freopen -functions -conform to -.St -ansiC . -The -.Fn fdopen -function -conforms to -.St -p1003.1-88 . diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c deleted file mode 100644 index 9199755..0000000 --- a/lib/libc/stdio/fopen.c +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdio.h> -#include <errno.h> -#include "local.h" - -FILE * -fopen(file, mode) - const char *file; - const char *mode; -{ - register FILE *fp; - register int f; - int flags, oflags; - - if ((flags = __sflags(mode, &oflags)) == 0) - return (NULL); - if ((fp = __sfp()) == NULL) - return (NULL); - if ((f = open(file, oflags, DEFFILEMODE)) < 0) { - fp->_flags = 0; /* release */ - return (NULL); - } - fp->_file = f; - fp->_flags = flags; - fp->_cookie = fp; - fp->_read = __sread; - fp->_write = __swrite; - fp->_seek = __sseek; - fp->_close = __sclose; - - /* - * When opening in append mode, even though we use O_APPEND, - * we need to seek to the end so that ftell() gets the right - * answer. If the user then alters the seek pointer, or - * the file extends, this will fail, but there is not much - * we can do about this. (We could set __SAPP and check in - * fseek and ftell.) - */ - if (oflags & O_APPEND) - (void) __sseek((void *)fp, (fpos_t)0, SEEK_END); - return (fp); -} diff --git a/lib/libc/stdio/fprintf.c b/lib/libc/stdio/fprintf.c deleted file mode 100644 index 383f1e1..0000000 --- a/lib/libc/stdio/fprintf.c +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fprintf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -int -#if __STDC__ -fprintf(FILE *fp, const char *fmt, ...) -#else -fprintf(fp, fmt, va_alist) - FILE *fp; - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = vfprintf(fp, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c deleted file mode 100644 index d1d9e87..0000000 --- a/lib/libc/stdio/fpurge.c +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * fpurge: like fflush, but without writing anything: leave the - * given FILE's buffer empty. - */ -int -fpurge(fp) - register FILE *fp; -{ - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - if (!fp->_flags) { - errno = EBADF; - retval = EOF; - } else { - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; - retval = 0; - } -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); -} diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c deleted file mode 100644 index 89b138d..0000000 --- a/lib/libc/stdio/fputc.c +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -int -fputc(c, fp) - int c; - register FILE *fp; -{ - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = putc(c, fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); -} diff --git a/lib/libc/stdio/fputs.3 b/lib/libc/stdio/fputs.3 deleted file mode 100644 index 0961366..0000000 --- a/lib/libc/stdio/fputs.3 +++ /dev/null @@ -1,107 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)fputs.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt FPUTS 3 -.Os -.Sh NAME -.Nm fputs , -.Nm puts -.Nd output a line to a stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn fputs "const char *str" "FILE *stream" -.Ft int -.Fn puts "const char *str" -.Sh DESCRIPTION -The function -.Fn fputs -writes the string pointed to by -.Fa str -to the stream pointed to by -.Fa stream . -.\" The terminating -.\" .Dv NUL -.\" character is not written. -.Pp -The function -.Fn puts -writes the string -.Fa str , -and a terminating newline character, -to the stream -.Em stdout . -.Sh RETURN VALUES -The -.Fn fputs -function -returns 0 on success and -.Dv EOF -on error; -.Fn puts -returns a nonnegative integer on success and -.Dv EOF -on error. -.Sh ERRORS -.Bl -tag -width [EBADF] -.It Bq Er EBADF -The -.Fa stream -supplied -is not a writable stream. -.El -.Pp -The functions -.Fn fputs -and -.Fn puts -may also fail and set -.Va errno -for any of the errors specified for the routines -.Xr write 2 . -.Sh SEE ALSO -.Xr ferror 3 , -.Xr putc 3 , -.Xr stdio 3 -.Sh STANDARDS -The functions -.Fn fputs -and -.Fn puts -conform to -.St -ansiC . diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c deleted file mode 100644 index 537c348..0000000 --- a/lib/libc/stdio/fputs.c +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <string.h> -#include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * Write the given string to the given file. - */ -int -fputs(s, fp) - const char *s; - FILE *fp; -{ - int retval; - struct __suio uio; - struct __siov iov; - - iov.iov_base = (void *)s; - iov.iov_len = uio.uio_resid = strlen(s); - uio.uio_iov = &iov; - uio.uio_iovcnt = 1; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sfvwrite(fp, &uio); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); -} diff --git a/lib/libc/stdio/fread.3 b/lib/libc/stdio/fread.3 deleted file mode 100644 index c3e591a..0000000 --- a/lib/libc/stdio/fread.3 +++ /dev/null @@ -1,106 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)fread.3 8.2 (Berkeley) 3/8/94 -.\" -.Dd March 8, 1994 -.Dt FREAD 3 -.Os -.Sh NAME -.Nm fread , -.Nm fwrite -.Nd binary stream input/output -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft size_t -.Fn fread "void *ptr" "size_t size" "size_t nmemb" "FILE *stream" -.Ft size_t -.Fn fwrite "const void *ptr" "size_t size" "size_t nmemb" "FILE *stream" -.Sh DESCRIPTION -The function -.Fn fread -reads -.Fa nmemb -objects, each -.Fa size -bytes long, from the stream pointed to by -.Fa stream , -storing them at the location given by -.Fa ptr . -.Pp -The function -.Fn fwrite -writes -.Fa nmemb -objects, each -.Fa size -bytes long, to the stream pointed to by -.Fa stream , -obtaining them from the location given by -.Fa ptr . -.Sh RETURN VALUES -The functions -.Fn fread -and -.Fn fwrite -advance the file position indicator for the stream -by the number of bytes read or written. -They return the number of objects read or written. -If an error occurs, or the end-of-file is reached, -the return value is a short object count (or zero). -.Pp -The function -.Fn fread -does not distinguish between end-of-file and error, and callers -must use -.Xr feof 3 -and -.Xr ferror 3 -to determine which occurred. -The function -.Fn fwrite -returns a value less than -.Fa nmemb -only if a write error has occurred. -.Sh SEE ALSO -.Xr read 2 , -.Xr write 2 -.Sh STANDARDS -The functions -.Fn fread -and -.Fn fwrite -conform to -.St -ansiC . diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c deleted file mode 100644 index 4f67fbf..0000000 --- a/lib/libc/stdio/fread.c +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <string.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -size_t -fread(buf, size, count, fp) - void *buf; - size_t size, count; - register FILE *fp; -{ - register size_t resid; - register char *p; - register int r; - size_t total; - - /* - * The ANSI standard requires a return value of 0 for a count - * or a size of 0. Peculiarily, it imposes no such requirements - * on fwrite; it only requires fread to be broken. - */ - if ((resid = count * size) == 0) - return (0); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - if (fp->_r < 0) - fp->_r = 0; - total = resid; - p = buf; - while (resid > (r = fp->_r)) { - (void)memcpy((void *)p, (void *)fp->_p, (size_t)r); - fp->_p += r; - /* fp->_r = 0 ... done in __srefill */ - p += r; - resid -= r; - if (__srefill(fp)) { - /* no more input: return partial result */ - return ((total - resid) / size); - } - } - (void)memcpy((void *)p, (void *)fp->_p, resid); - fp->_r -= resid; - fp->_p += resid; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (count); -} diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c deleted file mode 100644 index 7a8a3ef..0000000 --- a/lib/libc/stdio/freopen.c +++ /dev/null @@ -1,155 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)freopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include "local.h" - -/* - * Re-direct an existing, open (probably) file to some other file. - * ANSI is written such that the original file gets closed if at - * all possible, no matter what. - */ -FILE * -freopen(file, mode, fp) - const char *file, *mode; - register FILE *fp; -{ - register int f; - int flags, isopen, oflags, sverrno, wantfd; - - if ((flags = __sflags(mode, &oflags)) == 0) { - (void) fclose(fp); - return (NULL); - } - - if (!__sdidinit) - __sinit(); - - /* - * There are actually programs that depend on being able to "freopen" - * descriptors that weren't originally open. Keep this from breaking. - * Remember whether the stream was open to begin with, and which file - * descriptor (if any) was associated with it. If it was attached to - * a descriptor, defer closing it; freopen("/dev/stdin", "r", stdin) - * should work. This is unnecessary if it was not a Unix file. - */ - if (fp->_flags == 0) { - fp->_flags = __SEOF; /* hold on to it */ - isopen = 0; - wantfd = -1; - } else { - /* flush the stream; ANSI doesn't require this. */ - if (fp->_flags & __SWR) - (void) __sflush(fp); - /* if close is NULL, closing is a no-op, hence pointless */ - isopen = fp->_close != NULL; - if ((wantfd = fp->_file) < 0 && isopen) { - (void) (*fp->_close)(fp->_cookie); - isopen = 0; - } - } - - /* Get a new descriptor to refer to the new file. */ - f = open(file, oflags, DEFFILEMODE); - if (f < 0 && isopen) { - /* If out of fd's close the old one and try again. */ - if (errno == ENFILE || errno == EMFILE) { - (void) (*fp->_close)(fp->_cookie); - isopen = 0; - f = open(file, oflags, DEFFILEMODE); - } - } - sverrno = errno; - - /* - * Finish closing fp. Even if the open succeeded above, we cannot - * keep fp->_base: it may be the wrong size. This loses the effect - * of any setbuffer calls, but stdio has always done this before. - */ - if (isopen) - (void) (*fp->_close)(fp->_cookie); - if (fp->_flags & __SMBF) - free((char *)fp->_bf._base); - fp->_w = 0; - fp->_r = 0; - fp->_p = NULL; - fp->_bf._base = NULL; - fp->_bf._size = 0; - fp->_lbfsize = 0; - if (HASUB(fp)) - FREEUB(fp); - fp->_ub._size = 0; - if (HASLB(fp)) - FREELB(fp); - fp->_lb._size = 0; - - if (f < 0) { /* did not get it after all */ - fp->_flags = 0; /* set it free */ - errno = sverrno; /* restore in case _close clobbered */ - return (NULL); - } - - /* - * If reopening something that was open before on a real file, try - * to maintain the descriptor. Various C library routines (perror) - * assume stderr is always fd STDERR_FILENO, even if being freopen'd. - */ - if (wantfd >= 0 && f != wantfd) { - if (dup2(f, wantfd) >= 0) { - (void) close(f); - f = wantfd; - } - } - - fp->_flags = flags; - fp->_file = f; - fp->_cookie = fp; - fp->_read = __sread; - fp->_write = __swrite; - fp->_seek = __sseek; - fp->_close = __sclose; - return (fp); -} diff --git a/lib/libc/stdio/fscanf.c b/lib/libc/stdio/fscanf.c deleted file mode 100644 index 8513f80..0000000 --- a/lib/libc/stdio/fscanf.c +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -#if __STDC__ -int -fscanf(FILE *fp, char const *fmt, ...) { - int ret; - va_list ap; - - va_start(ap, fmt); -#else -int -fscanf(fp, fmt, va_alist) - FILE *fp; - char *fmt; - va_dcl -{ - int ret; - va_list ap; - - va_start(ap); -#endif -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - ret = __svfscanf(fp, fmt, ap); - va_end(ap); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (ret); -} diff --git a/lib/libc/stdio/fseek.3 b/lib/libc/stdio/fseek.3 deleted file mode 100644 index 5dd79e9..0000000 --- a/lib/libc/stdio/fseek.3 +++ /dev/null @@ -1,188 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)fseek.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt FSEEK 3 -.Os -.Sh NAME -.Nm fgetpos , -.Nm fseek , -.Nm fsetpos , -.Nm ftell , -.Nm rewind -.Nd reposition a stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn fseek "FILE *stream" "long offset" "int whence" -.Ft long -.Fn ftell "FILE *stream" -.Ft void -.Fn rewind "FILE *stream" -.Ft int -.Fn fgetpos "FILE *stream" "fpos_t *pos" -.Ft int -.Fn fsetpos "FILE *stream" "const fpos_t *pos" -.Sh DESCRIPTION -The -.Fn fseek -function sets the file position indicator for the stream pointed -to by -.Fa stream . -The new position, measured in bytes, is obtained by adding -.Fa offset -bytes to the position specified by -.Fa whence . -If -.Fa whence -is set to -.Dv SEEK_SET , -.Dv SEEK_CUR , -or -.Dv SEEK_END , -the offset is relative to the -start of the file, the current position indicator, or end-of-file, -respectively. -A successful call to the -.Fn fseek -function clears the end-of-file indicator for the stream and undoes -any effects of the -.Xr ungetc 3 -function on the same stream. -.Pp -The -.Fn ftell -function -obtains the current value of the file position indicator for the -stream pointed to by -.Fa stream . -.Pp -The -.Fn rewind -function sets the file position indicator for the stream pointed -to by -.Fa stream -to the beginning of the file. -It is equivalent to: -.Pp -.Dl (void)fseek(stream, 0L, SEEK_SET) -.Pp -except that the error indicator for the stream is also cleared -(see -.Xr clearerr 3 ) . -.Pp -The -.Fn fgetpos -and -.Fn fsetpos -functions -are alternate interfaces equivalent to -.Fn ftell -and -.Fn fseek -(with whence set to -.Dv SEEK_SET -), setting and storing the current value of -the file offset into or from the object referenced by -.Fa pos . -On some -.Pq non- Ns Tn UNIX -systems an -.Dq Fa fpos_t -object may be a complex object -and these routines may be the only way to portably reposition a text stream. -.Sh RETURN VALUES -The -.Fn rewind -function -returns no value. -Upon successful completion, -.Fn fgetpos , -.Fn fseek , -.Fn fsetpos -return 0, -and -.Fn ftell -returns the current offset. -Otherwise, \-1 is returned and the global variable errno is set to -indicate the error. -.Sh ERRORS -.Bl -tag -width [EINVAL] -.It Bq Er EBADF -The -.Fa stream -specified -is not a seekable stream. -.It Bq Er EINVAL -The -.Fa whence -argument to -.Fn fseek -was not -.Dv SEEK_SET , -.Dv SEEK_END , -or -.Dv SEEK_CUR . -.El -.Pp -The function -.Fn fgetpos , -.Fn fseek , -.Fn fsetpos , -and -.Fn ftell -may also fail and set -.Va errno -for any of the errors specified for the routines -.Xr fflush 3 , -.Xr fstat 2 , -.Xr lseek 2 , -and -.Xr malloc 3 . -.Sh SEE ALSO -.Xr lseek 2 -.Sh STANDARDS -The -.Fn fgetpos , -.Fn fsetpos , -.Fn fseek , -.Fn ftell , -and -.Fn rewind -functions -conform to -.St -ansiC . diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c deleted file mode 100644 index c6707df..0000000 --- a/lib/libc/stdio/fseek.c +++ /dev/null @@ -1,276 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -#define POS_ERR (-(fpos_t)1) - -/* - * Seek the given file to the given offset. - * `Whence' must be one of the three SEEK_* macros. - */ -int -fseek(fp, offset, whence) - register FILE *fp; - long offset; - int whence; -{ - register fpos_t (*seekfn) __P((void *, fpos_t, int)); - fpos_t target, curoff; - size_t n; - struct stat st; - int havepos; - - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - /* - * Have to be able to seek. - */ - if ((seekfn = fp->_seek) == NULL) { - errno = ESPIPE; /* historic practice */ - return (EOF); - } - - /* - * Change any SEEK_CUR to SEEK_SET, and check `whence' argument. - * After this, whence is either SEEK_SET or SEEK_END. - */ - switch (whence) { - - case SEEK_CUR: - /* - * In order to seek relative to the current stream offset, - * we have to first find the current stream offset a la - * ftell (see ftell for details). - */ - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else { - curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (EOF); - } - } - if (fp->_flags & __SRD) { - curoff -= fp->_r; - if (HASUB(fp)) - curoff -= fp->_ur; - } else if (fp->_flags & __SWR && fp->_p != NULL) - curoff += fp->_p - fp->_bf._base; - - offset += curoff; - whence = SEEK_SET; - havepos = 1; - break; - - case SEEK_SET: - case SEEK_END: - curoff = 0; /* XXX just to keep gcc quiet */ - havepos = 0; - break; - - default: - errno = EINVAL; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (EOF); - } - - /* - * Can only optimise if: - * reading (and not reading-and-writing); - * not unbuffered; and - * this is a `regular' Unix file (and hence seekfn==__sseek). - * We must check __NBF first, because it is possible to have __NBF - * and __SOPT both set. - */ - if (fp->_bf._base == NULL) - __smakebuf(fp); - if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) - goto dumb; - if ((fp->_flags & __SOPT) == 0) { - if (seekfn != __sseek || - fp->_file < 0 || fstat(fp->_file, &st) || - (st.st_mode & S_IFMT) != S_IFREG) { - fp->_flags |= __SNPT; - goto dumb; - } - fp->_blksize = st.st_blksize; - fp->_flags |= __SOPT; - } - - /* - * We are reading; we can try to optimise. - * Figure out where we are going and where we are now. - */ - if (whence == SEEK_SET) - target = offset; - else { - if (fstat(fp->_file, &st)) - goto dumb; - target = st.st_size + offset; - } - - if (!havepos) { - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else { - curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == POS_ERR) - goto dumb; - } - curoff -= fp->_r; - if (HASUB(fp)) - curoff -= fp->_ur; - } - - /* - * Compute the number of bytes in the input buffer (pretending - * that any ungetc() input has been discarded). Adjust current - * offset backwards by this count so that it represents the - * file offset for the first byte in the current input buffer. - */ - if (HASUB(fp)) { - curoff += fp->_r; /* kill off ungetc */ - n = fp->_up - fp->_bf._base; - curoff -= n; - n += fp->_ur; - } else { - n = fp->_p - fp->_bf._base; - curoff -= n; - n += fp->_r; - } - - /* - * If the target offset is within the current buffer, - * simply adjust the pointers, clear EOF, undo ungetc(), - * and return. (If the buffer was modified, we have to - * skip this; see fgetln.c.) - */ - if ((fp->_flags & __SMOD) == 0 && - target >= curoff && target < curoff + n) { - register int o = target - curoff; - - fp->_p = fp->_bf._base + o; - fp->_r = n - o; - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~__SEOF; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (0); - } - - /* - * The place we want to get to is not within the current buffer, - * but we can still be kind to the kernel copyout mechanism. - * By aligning the file offset to a block boundary, we can let - * the kernel use the VM hardware to map pages instead of - * copying bytes laboriously. Using a block boundary also - * ensures that we only read one block, rather than two. - */ - curoff = target & ~(fp->_blksize - 1); - if ((*seekfn)(fp->_cookie, curoff, SEEK_SET) == POS_ERR) - goto dumb; - fp->_r = 0; - fp->_p = fp->_bf._base; - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~__SEOF; - n = target - curoff; - if (n) { - if (__srefill(fp) || fp->_r < n) - goto dumb; - fp->_p += n; - fp->_r -= n; - } -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (0); - - /* - * We get here if we cannot optimise the seek ... just - * do it. Allow the seek function to change fp->_bf._base. - */ -dumb: - if (__sflush(fp) || - (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (EOF); - } - /* success: clear EOF indicator and discard ungetc() data */ - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - /* fp->_w = 0; */ /* unnecessary (I think...) */ - fp->_flags &= ~__SEOF; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (0); -} diff --git a/lib/libc/stdio/fsetpos.c b/lib/libc/stdio/fsetpos.c deleted file mode 100644 index d521a20..0000000 --- a/lib/libc/stdio/fsetpos.c +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> - -/* - * fsetpos: like fseek. - */ -int -fsetpos(iop, pos) - FILE *iop; - const fpos_t *pos; -{ - return (fseek(iop, (long)*pos, SEEK_SET)); -} diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c deleted file mode 100644 index 9b85ee0..0000000 --- a/lib/libc/stdio/ftell.c +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95"; -#endif -static const char rcsid[] = - "$Id: ftell.c,v 1.7 1997/02/22 15:02:07 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <errno.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * ftell: return current offset. - */ -long -ftell(fp) - register FILE *fp; -{ - register fpos_t pos; - - if (fp->_seek == NULL) { - errno = ESPIPE; /* historic practice */ - return (-1L); - } - -#ifdef _THREAD_SAFE - _thread_flockfile(fp, __FILE__, __LINE__); -#endif - /* - * Find offset of underlying I/O object, then - * adjust for buffered bytes. - */ - if (fp->_flags & __SOFF) - pos = fp->_offset; - else { - pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (pos == -1) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (pos); - } - } - if (fp->_flags & __SRD) { - /* - * Reading. Any unread characters (including - * those from ungetc) cause the position to be - * smaller than that in the underlying object. - */ - pos -= fp->_r; - if (HASUB(fp)) - pos -= fp->_ur; - } else if (fp->_flags & __SWR && fp->_p != NULL) { - /* - * Writing. Any buffered characters cause the - * position to be greater than that in the - * underlying object. - */ - pos += fp->_p - fp->_bf._base; - } -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (pos); -} diff --git a/lib/libc/stdio/funopen.3 b/lib/libc/stdio/funopen.3 deleted file mode 100644 index 90e98d4..0000000 --- a/lib/libc/stdio/funopen.3 +++ /dev/null @@ -1,169 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek. -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)funopen.3 8.1 (Berkeley) 6/9/93 -.\" -.Dd June 9, 1993 -.Dt FUNOPEN 3 -.Os -.Sh NAME -.Nm funopen , -.Nm fropen , -.Nm fwopen -.Nd open a stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft FILE * -.Fn funopen "const void *cookie" "int (*readfn)(void *, char *, int)" "int (*writefn)(void *, const char *, int)" "fpos_t (*seekfn)(void *, fpos_t, int)" "int (*closefn)(void *)" -.Ft FILE * -.Fn fropen "void *cookie" "int (*readfn)(void *, char *, int)" -.Ft FILE * -.Fn fwopen "void *cookie" "int (*writefn)(void *, const char *, int)" -.Sh DESCRIPTION -The -.Fn funopen -function -associates a stream with up to four -.Dq Tn I/O No functions . -Either -.Fa readfn -or -.Fa writefn -must be specified; -the others can be given as an appropriately-typed -.Dv NULL -pointer. -These -.Tn I/O -functions will be used to read, write, seek and -close the new stream. -.Pp -In general, omitting a function means that any attempt to perform the -associated operation on the resulting stream will fail. -If the close function is omitted, closing the stream will flush -any buffered output and then succeed. -.Pp -The calling conventions of -.Fa readfn , -.Fa writefn , -.Fa seekfn -and -.Fa closefn -must match those, respectively, of -.Xr read 2 , -.Xr write 2 , -.Xr seek 2 , -and -.Xr close 2 -with the single exception that they are passed the -.Fa cookie -argument specified to -.Fn funopen -in place of the traditional file descriptor argument. -.Pp -Read and write -.Tn I/O -functions are allowed to change the underlying buffer -on fully buffered or line buffered streams by calling -.Xr setvbuf 3 . -They are also not required to completely fill or empty the buffer. -They are not, however, allowed to change streams from unbuffered to buffered -or to change the state of the line buffering flag. -They must also be prepared to have read or write calls occur on buffers other -than the one most recently specified. -.Pp -All user -.Tn I/O -functions can report an error by returning \-1. -Additionally, all of the functions should set the external variable -.Va errno -appropriately if an error occurs. -.Pp -An error on -.Fn closefn -does not keep the stream open. -.Pp -As a convenience, the include file -.Aq Pa stdio.h -defines the macros -.Fn fropen -and -.Fn fwopen -as calls to -.Fn funopen -with only a read or write function specified. -.Sh RETURN VALUES -Upon successful completion, -.Fn funopen -returns a -.Dv FILE -pointer. -Otherwise, -.Dv NULL -is returned and the global variable -.Va errno -is set to indicate the error. -.Sh ERRORS -.Bl -tag -width [EINVAL] -.It Bq Er EINVAL -The -.Fn funopen -function -was called without either a read or write function. -The -.Fn funopen -function -may also fail and set -.Va errno -for any of the errors -specified for the routine -.Xr malloc 3 . -.El -.Sh SEE ALSO -.Xr fcntl 2 , -.Xr open 2 , -.Xr fclose 3 , -.Xr fopen 3 , -.Xr fseek 3 , -.Xr setbuf 3 -.Sh HISTORY -The -.Fn funopen -functions first appeared in -.Bx 4.4 . -.Sh BUGS -The -.Fn funopen -function -may not be portable to systems other than -.Bx . diff --git a/lib/libc/stdio/funopen.c b/lib/libc/stdio/funopen.c deleted file mode 100644 index 4d65b68..0000000 --- a/lib/libc/stdio/funopen.c +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <errno.h> -#include "local.h" - -FILE * -funopen(cookie, readfn, writefn, seekfn, closefn) - const void *cookie; - int (*readfn)(), (*writefn)(); -#if __STDC__ - fpos_t (*seekfn)(void *cookie, fpos_t off, int whence); -#else - fpos_t (*seekfn)(); -#endif - int (*closefn)(); -{ - register FILE *fp; - int flags; - - if (readfn == NULL) { - if (writefn == NULL) { /* illegal */ - errno = EINVAL; - return (NULL); - } else - flags = __SWR; /* write only */ - } else { - if (writefn == NULL) - flags = __SRD; /* read only */ - else - flags = __SRW; /* read-write */ - } - if ((fp = __sfp()) == NULL) - return (NULL); - fp->_flags = flags; - fp->_file = -1; - fp->_cookie = (void *)cookie; - fp->_read = readfn; - fp->_write = writefn; - fp->_seek = seekfn; - fp->_close = closefn; - return (fp); -} diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c deleted file mode 100644 index 5061773..0000000 --- a/lib/libc/stdio/fvwrite.c +++ /dev/null @@ -1,196 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id: fvwrite.c,v 1.6 1997/12/24 13:17:13 ache Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <string.h> -#include "local.h" -#include "fvwrite.h" - -/* - * Write some memory regions. Return zero on success, EOF on error. - * - * This routine is large and unsightly, but most of the ugliness due - * to the three different kinds of output buffering is handled here. - */ -int -__sfvwrite(fp, uio) - register FILE *fp; - register struct __suio *uio; -{ - register size_t len; - register char *p; - register struct __siov *iov; - register int w, s; - char *nl; - int nlknown, nldist; - - if ((len = uio->uio_resid) == 0) - return (0); - /* make sure we can write */ - if (cantwrite(fp)) - return (EOF); - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#define COPY(n) (void)memcpy((void *)fp->_p, (void *)p, (size_t)(n)) - - iov = uio->uio_iov; - p = iov->iov_base; - len = iov->iov_len; - iov++; -#define GETIOV(extra_work) \ - while (len == 0) { \ - extra_work; \ - p = iov->iov_base; \ - len = iov->iov_len; \ - iov++; \ - } - if (fp->_flags & __SNBF) { - /* - * Unbuffered: write up to BUFSIZ bytes at a time. - */ - do { - GETIOV(;); - w = (*fp->_write)(fp->_cookie, p, MIN(len, BUFSIZ)); - if (w <= 0) - goto err; - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } else if ((fp->_flags & __SLBF) == 0) { - /* - * Fully buffered: fill partially full buffer, if any, - * and then flush. If there is no partial buffer, write - * one _bf._size byte chunk directly (without copying). - * - * String output is a special case: write as many bytes - * as fit, but pretend we wrote everything. This makes - * snprintf() return the number of bytes needed, rather - * than the number used, and avoids its write function - * (so that the write function can be invalid). - */ - do { - GETIOV(;); - w = fp->_w; - if (fp->_flags & __SSTR) { - if (len < w) - w = len; - if (w > 0) { - COPY(w); /* copy MIN(fp->_w,len), */ - fp->_w -= w; - fp->_p += w; - } - w = len; /* but pretend copied all */ - } else if (fp->_p > fp->_bf._base && len > w) { - /* fill and flush */ - COPY(w); - /* fp->_w -= w; */ /* unneeded */ - fp->_p += w; - if (fflush(fp)) - goto err; - } else if (len >= (w = fp->_bf._size)) { - /* write directly */ - w = (*fp->_write)(fp->_cookie, p, w); - if (w <= 0) - goto err; - } else { - /* fill and done */ - w = len; - COPY(w); - fp->_w -= w; - fp->_p += w; - } - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } else { - /* - * Line buffered: like fully buffered, but we - * must check for newlines. Compute the distance - * to the first newline (including the newline), - * or `infinity' if there is none, then pretend - * that the amount to write is MIN(len,nldist). - */ - nlknown = 0; - nldist = 0; /* XXX just to keep gcc happy */ - do { - GETIOV(nlknown = 0); - if (!nlknown) { - nl = memchr((void *)p, '\n', len); - nldist = nl ? nl + 1 - p : len + 1; - nlknown = 1; - } - s = MIN(len, nldist); - w = fp->_w + fp->_bf._size; - if (fp->_p > fp->_bf._base && s > w) { - COPY(w); - /* fp->_w -= w; */ - fp->_p += w; - if (fflush(fp)) - goto err; - } else if (s >= (w = fp->_bf._size)) { - w = (*fp->_write)(fp->_cookie, p, w); - if (w <= 0) - goto err; - } else { - w = s; - COPY(w); - fp->_w -= w; - fp->_p += w; - } - if ((nldist -= w) == 0) { - /* copied the newline: flush and forget */ - if (fflush(fp)) - goto err; - nlknown = 0; - } - p += w; - len -= w; - } while ((uio->uio_resid -= w) != 0); - } - return (0); - -err: - fp->_flags |= __SERR; - return (EOF); -} diff --git a/lib/libc/stdio/fvwrite.h b/lib/libc/stdio/fvwrite.h deleted file mode 100644 index ec6bc0b..0000000 --- a/lib/libc/stdio/fvwrite.h +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)fvwrite.h 8.1 (Berkeley) 6/4/93 - */ - -/* - * I/O descriptors for __sfvwrite(). - */ -struct __siov { - void *iov_base; - size_t iov_len; -}; -struct __suio { - struct __siov *uio_iov; - int uio_iovcnt; - int uio_resid; -}; - -#if __STDC__ || c_plusplus -extern int __sfvwrite(FILE *, struct __suio *); -#else -extern int __sfvwrite(); -#endif diff --git a/lib/libc/stdio/fwalk.c b/lib/libc/stdio/fwalk.c deleted file mode 100644 index 8f91b46..0000000 --- a/lib/libc/stdio/fwalk.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <errno.h> -#include <stdio.h> -#include "local.h" -#include "glue.h" - -int -_fwalk(function) - register int (*function)(FILE *); -{ - register FILE *fp; - register int n, ret; - register struct glue *g; - - ret = 0; - for (g = &__sglue; g != NULL; g = g->next) - for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) - if (fp->_flags != 0) - ret |= (*function)(fp); - return (ret); -} diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c deleted file mode 100644 index ba8540d..0000000 --- a/lib/libc/stdio/fwrite.c +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include "local.h" -#include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * Write `count' objects (each size `size') from memory to the given file. - * Return the number of whole objects written. - */ -size_t -fwrite(buf, size, count, fp) - const void *buf; - size_t size, count; - FILE *fp; -{ - size_t n; - struct __suio uio; - struct __siov iov; - - iov.iov_base = (void *)buf; - uio.uio_resid = iov.iov_len = n = count * size; - uio.uio_iov = &iov; - uio.uio_iovcnt = 1; - -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - /* - * The usual case is success (__sfvwrite returns 0); - * skip the divide if this happens, since divides are - * generally slow and since this occurs whenever size==0. - */ - if (__sfvwrite(fp, &uio) != 0) - count = (n - uio.uio_resid) / size; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (count); -} diff --git a/lib/libc/stdio/getc.3 b/lib/libc/stdio/getc.3 deleted file mode 100644 index 0c63fbe..0000000 --- a/lib/libc/stdio/getc.3 +++ /dev/null @@ -1,136 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)getc.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt GETC 3 -.Os -.Sh NAME -.Nm fgetc , -.Nm getc , -.Nm getchar , -.Nm getw -.Nd get next character or word from input stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn fgetc "FILE *stream" -.Ft int -.Fn getc "FILE *stream" -.Ft int -.Fn getchar -.Ft int -.Fn getw "FILE *stream" -.Sh DESCRIPTION -The -.Fn fgetc -function -obtains the next input character (if present) from the stream pointed at by -.Fa stream , -or the next character pushed back on the stream via -.Xr ungetc 3 . -.Pp -The -.Fn getc -function -acts essentially identically to -.Fn fgetc , -but is a macro that expands in-line. -.Pp -The -.Fn getchar -function -is equivalent to: -getc with the argument stdin. -.Pp -The -.Fn getw -function -obtains the next -.Em int -(if present) -from the stream pointed at by -.Fa stream . -.Sh RETURN VALUES -If successful, these routines return the next requested object -from the -.Fa stream . -If the stream is at end-of-file or a read error occurs, -the routines return -.Dv EOF . -The routines -.Xr feof 3 -and -.Xr ferror 3 -must be used to distinguish between end-of-file and error. -If an error occurs, the global variable -.Va errno -is set to indicate the error. -The end-of-file condition is remembered, even on a terminal, and all -subsequent attempts to read will return -.Dv EOF -until the condition is cleared with -.Xr clearerr 3 . -.Sh SEE ALSO -.Xr ferror 3 , -.Xr fopen 3 , -.Xr fread 3 , -.Xr putc 3 , -.Xr ungetc 3 -.Sh STANDARDS -The -.Fn fgetc , -.Fn getc -and -.Fn getchar -functions -conform to -.St -ansiC . -.Sh BUGS -Since -.Dv EOF -is a valid integer value, -.Xr feof 3 -and -.Xr ferror 3 -must be used to check for failure after calling -.Fn getw . -The size and byte order of an -.Em int -varies from one machine to another, and -.Fn getw -is not recommended for portable applications. -.Pp diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c deleted file mode 100644 index ced796b..0000000 --- a/lib/libc/stdio/getc.c +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * A subroutine version of the macro getc. - */ -#undef getc - -int -getc(fp) - register FILE *fp; -{ - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sgetc(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); -} diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c deleted file mode 100644 index 0bcbd3a..0000000 --- a/lib/libc/stdio/getchar.c +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -/* - * A subroutine version of the macro getchar. - */ -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -#undef getchar - -int -getchar() -{ - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(stdin,__FILE__,__LINE__); -#endif - retval = getc(stdin); -#ifdef _THREAD_SAFE - _thread_funlockfile(stdin); -#endif - return (retval); -} diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c deleted file mode 100644 index 0c821ea..0000000 --- a/lib/libc/stdio/gets.c +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <unistd.h> -#include <stdio.h> -#include <sys/cdefs.h> - -__warn_references(gets, "warning: this program uses gets(), which is unsafe."); - -char * -gets(buf) - char *buf; -{ - register int c; - register char *s; - static int warned; - static char w[] = - "warning: this program uses gets(), which is unsafe.\n"; - - if (!warned) { - (void) write(STDERR_FILENO, w, sizeof(w) - 1); - warned = 1; - } - for (s = buf; (c = getchar()) != '\n';) - if (c == EOF) - if (s == buf) - return (NULL); - else - break; - else - *s++ = c; - *s = 0; - return (buf); -} diff --git a/lib/libc/stdio/getw.c b/lib/libc/stdio/getw.c deleted file mode 100644 index c72756d..0000000 --- a/lib/libc/stdio/getw.c +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)getw.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> - -int -getw(fp) - FILE *fp; -{ - int x; - - return (fread((void *)&x, sizeof(x), 1, fp) == 1 ? x : EOF); -} diff --git a/lib/libc/stdio/glue.h b/lib/libc/stdio/glue.h deleted file mode 100644 index 5dcdaff..0000000 --- a/lib/libc/stdio/glue.h +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)glue.h 8.1 (Berkeley) 6/4/93 - */ - -/* - * The first few FILEs are statically allocated; others are dynamically - * allocated and linked in via this glue structure. - */ -struct glue { - struct glue *next; - int niobs; - FILE *iobs; -} __sglue; diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h deleted file mode 100644 index cbc07a9..0000000 --- a/lib/libc/stdio/local.h +++ /dev/null @@ -1,87 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)local.h 8.3 (Berkeley) 7/3/94 - */ - -/* - * Information local to this implementation of stdio, - * in particular, macros and private variables. - */ - -extern int __sflush __P((FILE *)); -extern FILE *__sfp __P((void)); -extern int __srefill __P((FILE *)); -extern int __sread __P((void *, char *, int)); -extern int __swrite __P((void *, char const *, int)); -extern fpos_t __sseek __P((void *, fpos_t, int)); -extern int __sclose __P((void *)); -extern void __sinit __P((void)); -extern void _cleanup __P((void)); -extern void (*__cleanup) __P((void)); -extern void __smakebuf __P((FILE *)); -extern int __swhatbuf __P((FILE *, size_t *, int *)); -extern int _fwalk __P((int (*)(FILE *))); -extern int __swsetup __P((FILE *)); -extern int __sflags __P((const char *, int *)); - -extern int __sdidinit; - -/* - * Return true iff the given FILE cannot be written now. - */ -#define cantwrite(fp) \ - ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \ - __swsetup(fp)) - -/* - * Test whether the given stdio file has an active ungetc buffer; - * release such a buffer, without restoring ordinary unread data. - */ -#define HASUB(fp) ((fp)->_ub._base != NULL) -#define FREEUB(fp) { \ - if ((fp)->_ub._base != (fp)->_ubuf) \ - free((char *)(fp)->_ub._base); \ - (fp)->_ub._base = NULL; \ -} - -/* - * test for an fgetln() buffer. - */ -#define HASLB(fp) ((fp)->_lb._base != NULL) -#define FREELB(fp) { \ - free((char *)(fp)->_lb._base); \ - (fp)->_lb._base = NULL; \ -} diff --git a/lib/libc/stdio/makebuf.c b/lib/libc/stdio/makebuf.c deleted file mode 100644 index 7dcbd70..0000000 --- a/lib/libc/stdio/makebuf.c +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <stdio.h> -#include <stdlib.h> -#include "local.h" - -/* - * Allocate a file buffer, or switch to unbuffered I/O. - * Per the ANSI C standard, ALL tty devices default to line buffered. - * - * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek - * optimisation) right after the fstat() that finds the buffer size. - */ -void -__smakebuf(fp) - register FILE *fp; -{ - register void *p; - register int flags; - size_t size; - int couldbetty; - - if (fp->_flags & __SNBF) { - fp->_bf._base = fp->_p = fp->_nbuf; - fp->_bf._size = 1; - return; - } - flags = __swhatbuf(fp, &size, &couldbetty); - if ((p = malloc(size)) == NULL) { - fp->_flags |= __SNBF; - fp->_bf._base = fp->_p = fp->_nbuf; - fp->_bf._size = 1; - return; - } - __cleanup = _cleanup; - flags |= __SMBF; - fp->_bf._base = fp->_p = p; - fp->_bf._size = size; - if (couldbetty && isatty(fp->_file)) - flags |= __SLBF; - fp->_flags |= flags; -} - -/* - * Internal routine to determine `proper' buffering for a file. - */ -int -__swhatbuf(fp, bufsize, couldbetty) - register FILE *fp; - size_t *bufsize; - int *couldbetty; -{ - struct stat st; - - if (fp->_file < 0 || fstat(fp->_file, &st) < 0) { - *couldbetty = 0; - *bufsize = BUFSIZ; - return (__SNPT); - } - - /* could be a tty iff it is a character device */ - *couldbetty = (st.st_mode & S_IFMT) == S_IFCHR; - if (st.st_blksize <= 0) { - *bufsize = BUFSIZ; - return (__SNPT); - } - - /* - * Optimise fseek() only if it is a regular file. (The test for - * __sseek is mainly paranoia.) It is safe to set _blksize - * unconditionally; it will only be used if __SOPT is also set. - */ - *bufsize = st.st_blksize; - fp->_blksize = st.st_blksize; - return ((st.st_mode & S_IFMT) == S_IFREG && fp->_seek == __sseek ? - __SOPT : __SNPT); -} diff --git a/lib/libc/stdio/mktemp.3 b/lib/libc/stdio/mktemp.3 deleted file mode 100644 index 28a662d..0000000 --- a/lib/libc/stdio/mktemp.3 +++ /dev/null @@ -1,158 +0,0 @@ -.\" Copyright (c) 1989, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)mktemp.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt MKTEMP 3 -.Os -.Sh NAME -.Nm mktemp -.Nd make temporary file name (unique) -.Sh SYNOPSIS -.Fd #include <unistd.h> -.Ft char * -.Fn mktemp "char *template" -.Ft int -.Fn mkstemp "char *template" -.Sh DESCRIPTION -The -.Fn mktemp -function -takes the given file name template and overwrites a portion of it -to create a file name. -This file name is unique and suitable for use -by the application. -The template may be any file name with some number of -.Ql X Ns s -appended -to it, for example -.Pa /tmp/temp.XXXX . -The trailing -.Ql X Ns s -are replaced with the current process number and/or a -unique letter combination. -The number of unique file names -.Fn mktemp -can return depends on the number of -.Ql X Ns s -provided; six -.Ql X Ns s -will -result in -.Fn mktemp -testing roughly 26 ** 6 combinations. -.Pp -The -.Fn mkstemp -function -makes the same replacement to the template and creates the template file, -mode 0600, returning a file descriptor opened for reading and writing. -This avoids the race between testing for a file's existence and opening it -for use. -.Sh RETURN VALUES -The -.Fn mktemp -function -returns a pointer to the template on success and -.Dv NULL -on failure. -The -.Fn mkstemp -function -returns \-1 if no suitable file could be created. -If either call fails an error code is placed in the global variable -.Va errno . -.Sh ERRORS -The -.Fn mktemp -and -.Fn mkstemp -functions -may set -.Va errno -to one of the following values: -.Bl -tag -width [ENOTDIR] -.It Bq Er ENOTDIR -The pathname portion of the template is not an existing directory. -.El -.Pp -The -.Fn mktemp -and -.Fn mkstemp -functions -may also set -.Va errno -to any value specified by the -.Xr stat 2 -function. -.Pp -The -.Fn mkstemp -function -may also set -.Va errno -to any value specified by the -.Xr open 2 -function. -.Sh NOTES -A common problem that results in a core dump is that the programmer -passes in a read-only string to -.Fn mktemp -or -.Fn mkstemp . -This is common with programs that were developed before -.St -ansiC -compilers were common. -For example, calling -.Fn mkstemp -with an argument of -.Qq /tmp/tempfile.XXXXXX -will result in a core dump due to -.Fn mkstemp -attempting to modify the string constant that was given. -If the program in question makes heavy use of that type -of function call, you do have the option of compiling the program -so that it will store string constants in a writable segment of memory. -See -.Xr gcc 1 -for more information. -.Sh SEE ALSO -.Xr chmod 2 , -.Xr getpid 2 , -.Xr open 2 , -.Xr stat 2 -.Sh HISTORY -A -.Nm mktemp -function appeared in -.At v7 . diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c deleted file mode 100644 index 19125e6..0000000 --- a/lib/libc/stdio/mktemp.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 1987, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id: mktemp.c,v 1.6 1997/02/22 15:02:16 peter Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <errno.h> -#include <stdio.h> -#include <ctype.h> -#include <unistd.h> - -static int _gettemp(char *, int *); - -int -mkstemp(path) - char *path; -{ - int fd; - - return (_gettemp(path, &fd) ? fd : -1); -} - -char * -mktemp(path) - char *path; -{ - return(_gettemp(path, (int *)NULL) ? path : (char *)NULL); -} - -static int -_gettemp(path, doopen) - char *path; - register int *doopen; -{ - register char *start, *trv; - struct stat sbuf; - pid_t pid; - - pid = getpid(); - for (trv = path; *trv; ++trv); /* extra X's get set to 0's */ - while (*--trv == 'X') { - *trv = (pid % 10) + '0'; - pid /= 10; - } - - /* - * check the target directory; if you have six X's and it - * doesn't exist this runs for a *very* long time. - */ - for (start = trv + 1;; --trv) { - if (trv <= path) - break; - if (*trv == '/') { - *trv = '\0'; - if (stat(path, &sbuf)) - return(0); - if (!S_ISDIR(sbuf.st_mode)) { - errno = ENOTDIR; - return(0); - } - *trv = '/'; - break; - } - } - - for (;;) { - if (doopen) { - if ((*doopen = - open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0) - return(1); - if (errno != EEXIST) - return(0); - } - else if (lstat(path, &sbuf)) - return(errno == ENOENT ? 1 : 0); - - /* tricky little algorithm for backward compatibility */ - for (trv = start;;) { - if (!*trv) - return(0); - if (*trv == 'z') - *trv++ = 'a'; - else { - if (isdigit(*trv)) - *trv = 'a'; - else - ++*trv; - break; - } - } - } - /*NOTREACHED*/ -} diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c deleted file mode 100644 index 91a7dee..0000000 --- a/lib/libc/stdio/perror.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)perror.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <sys/uio.h> -#include <unistd.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> - -void -perror(s) - const char *s; -{ - register struct iovec *v; - struct iovec iov[4]; - - v = iov; - if (s != NULL) { - v->iov_base = (char *)s; - v->iov_len = strlen(s); - v++; - v->iov_base = ": "; - v->iov_len = 2; - v++; - } - v->iov_base = strerror(errno); - v->iov_len = strlen(v->iov_base); - v++; - v->iov_base = "\n"; - v->iov_len = 1; - (void)writev(STDERR_FILENO, iov, (v - iov) + 1); -} diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3 deleted file mode 100644 index 6d5ad8a..0000000 --- a/lib/libc/stdio/printf.3 +++ /dev/null @@ -1,666 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)printf.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt PRINTF 3 -.Os -.Sh NAME -.Nm printf , -.Nm fprintf , -.Nm sprintf , -.Nm snprintf , -.Nm asprintf , -.Nm vprintf , -.Nm vfprintf, -.Nm vsprintf , -.Nm vsnprintf , -.Nm vasprintf -.Nd formatted output conversion -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn printf "const char *format" ... -.Ft int -.Fn fprintf "FILE *stream" "const char *format" ... -.Ft int -.Fn sprintf "char *str" "const char *format" ... -.Ft int -.Fn snprintf "char *str" "size_t size" "const char *format" ... -.Ft int -.Fn asprintf "char **ret" "const char *format" ... -.Fd #include <stdarg.h> -.Ft int -.Fn vprintf "const char *format" "va_list ap" -.Ft int -.Fn vfprintf "FILE *stream" "const char *format" "va_list ap" -.Ft int -.Fn vsprintf "char *str" "const char *format" "va_list ap" -.Ft int -.Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap" -.Ft int -.Fn vasprintf "char **ret" "const char *format" "va_list ap" -.Sh DESCRIPTION -The -.Fn printf -family of functions produces output according to a -.Fa format -as described below. -.Fn Printf -and -.Fn vprintf -write output to -.Em stdout, -the standard output stream; -.Fn fprintf -and -.Fn vfprintf -write output to the given output -.Fa stream ; -.Fn sprintf , -.Fn snprintf , -.Fn vsprintf , -and -.Fn vsnprintf -write to the character string -.Fa str ; -and -.Fn asprintf -and -.Fn vasprintf -dynamically allocate a new string with -.Xr malloc 3 -/ -.Xr realloc 3 . -.Pp -These functions write the output under the control of a -.Fa format -string that specifies how subsequent arguments -(or arguments accessed via the variable-length argument facilities of -.Xr stdarg 3 ) -are converted for output. -.Pp -These functions return -the number of characters printed -(not including the trailing -.Ql \e0 -used to end output to strings). -.Pp -.Fn Asprintf -and -.Fn vasprintf -return a pointer to a buffer sufficiently large to hold the -string in the -.Fa ret -argument; -This pointer should be passed to -.Xr free 3 -to release the allocated storage when it is no longer needed. -If sufficient space cannot be allocated, -.Fn asprintf -and -.Fn vasprintf -will return -1 and set -.Fa ret -to be a NULL pointer. -.Pp -.Fn Snprintf -and -.Fn vsnprintf -will write at most -.Fa size Ns \-1 -of the characters printed into the output string -(the -.Fa size Ns 'th -character then gets the terminating -.Ql \e0 ) ; -if the return value is greater than or equal to the -.Fa size -argument, the string was too short -and some of the printed characters were discarded. -.Pp -.Fn Sprintf -and -.Fn vsprintf -effectively assume an infinite -.Fa size . -.Pp -The format string is composed of zero or more directives: -ordinary -.\" multibyte -characters (not -.Cm % ) , -which are copied unchanged to the output stream; -and conversion specifications, each of which results -in fetching zero or more subsequent arguments. -Each conversion specification is introduced by -the character -.Cm % . -The arguments must correspond properly (after type promotion) -with the conversion specifier. -After the -.Cm % , -the following appear in sequence: -.Bl -bullet -.It -An optional field, consisting of a decimal digit string followed by a -.Cm $ , -specifying the next argument to access . -If this field is not provided, the argument following the last -argument accessed will be used. -Arguments are numbered starting at -.Cm 1 . -If unaccessed arguments in the format string are interspersed with ones that -are accessed the results will be indeterminate. -.It -Zero or more of the following flags: -.Bl -hyphen -.It -A -.Cm # -character -specifying that the value should be converted to an ``alternate form''. -For -.Cm c , -.Cm d , -.Cm i , -.Cm n , -.Cm p , -.Cm s , -and -.Cm u , -conversions, this option has no effect. -For -.Cm o -conversions, the precision of the number is increased to force the first -character of the output string to a zero (except if a zero value is printed -with an explicit precision of zero). -For -.Cm x -and -.Cm X -conversions, a non-zero result has the string -.Ql 0x -(or -.Ql 0X -for -.Cm X -conversions) prepended to it. -For -.Cm e , -.Cm E , -.Cm f , -.Cm g , -and -.Cm G , -conversions, the result will always contain a decimal point, even if no -digits follow it (normally, a decimal point appears in the results of -those conversions only if a digit follows). -For -.Cm g -and -.Cm G -conversions, trailing zeros are not removed from the result as they -would otherwise be. -.It -A zero -.Sq Cm \&0 -character specifying zero padding. -For all conversions except -.Cm n , -the converted value is padded on the left with zeros rather than blanks. -If a precision is given with a numeric conversion -.Pf ( Cm d , -.Cm i , -.Cm o , -.Cm u , -.Cm i , -.Cm x , -and -.Cm X ) , -the -.Sq Cm \&0 -flag is ignored. -.It -A negative field width flag -.Sq Cm \- -indicates the converted value is to be left adjusted on the field boundary. -Except for -.Cm n -conversions, the converted value is padded on the right with blanks, -rather than on the left with blanks or zeros. -A -.Sq Cm \- -overrides a -.Sq Cm \&0 -if both are given. -.It -A space, specifying that a blank should be left before a positive number -produced by a signed conversion -.Pf ( Cm d , -.Cm e , -.Cm E , -.Cm f , -.Cm g , -.Cm G , -or -.Cm i ) . -.It -A -.Sq Cm + -character specifying that a sign always be placed before a -number produced by a signed conversion. -A -.Sq Cm + -overrides a space if both are used. -.El -.It -An optional decimal digit string specifying a minimum field width. -If the converted value has fewer characters than the field width, it will -be padded with spaces on the left (or right, if the left-adjustment -flag has been given) to fill out -the field width. -.It -An optional precision, in the form of a period -.Sq Cm \&. -followed by an -optional digit string. If the digit string is omitted, the precision -is taken as zero. This gives the minimum number of digits to appear for -.Cm d , -.Cm i , -.Cm o , -.Cm u , -.Cm x , -and -.Cm X -conversions, the number of digits to appear after the decimal-point for -.Cm e , -.Cm E , -and -.Cm f -conversions, the maximum number of significant digits for -.Cm g -and -.Cm G -conversions, or the maximum number of characters to be printed from a -string for -.Cm s -conversions. -.It -The optional character -.Cm h , -specifying that a following -.Cm d , -.Cm i , -.Cm o , -.Cm u , -.Cm x , -or -.Cm X -conversion corresponds to a -.Em short int -or -.Em unsigned short int -argument, or that a following -.Cm n -conversion corresponds to a pointer to a -.Em short int -argument. -.It -The optional character -.Cm l -(ell) specifying that a following -.Cm d , -.Cm i , -.Cm o , -.Cm u , -.Cm x , -or -.Cm X -conversion applies to a pointer to a -.Em long int -or -.Em unsigned long int -argument, or that a following -.Cm n -conversion corresponds to a pointer to a -.Em long int -argument. -.It -The optional character -.Cm q , -specifying that a following -.Cm d , -.Cm i , -.Cm o , -.Cm u , -.Cm x , -or -.Cm X -conversion corresponds to a -.Em quad int -or -.Em unsigned quad int -argument, or that a following -.Cm n -conversion corresponds to a pointer to a -.Em quad int -argument. -.It -The character -.Cm L -specifying that a following -.Cm e , -.Cm E , -.Cm f , -.Cm g , -or -.Cm G -conversion corresponds to a -.Em long double -argument (but note that long double values are not currently supported -by the -.Tn VAX -and -.Tn Tahoe -compilers). -.It -A character that specifies the type of conversion to be applied. -.El -.Pp -A field width or precision, or both, may be indicated by -an asterisk -.Ql * -or an asterisk followed by one or more decimal digits and a -.Ql $ -instead of a -digit string. -In this case, an -.Em int -argument supplies the field width or precision. -A negative field width is treated as a left adjustment flag followed by a -positive field width; a negative precision is treated as though it were -missing. -If a single format directive mixes positional (nn$) -and non-positional arguments, the results are undefined. -.Pp -The conversion specifiers and their meanings are: -.Bl -tag -width "diouxX" -.It Cm diouxX -The -.Em int -(or appropriate variant) argument is converted to signed decimal -.Pf ( Cm d -and -.Cm i ) , -unsigned octal -.Pq Cm o , -unsigned decimal -.Pq Cm u , -or unsigned hexadecimal -.Pf ( Cm x -and -.Cm X ) -notation. The letters -.Cm abcdef -are used for -.Cm x -conversions; the letters -.Cm ABCDEF -are used for -.Cm X -conversions. -The precision, if any, gives the minimum number of digits that must -appear; if the converted value requires fewer digits, it is padded on -the left with zeros. -.It Cm DOU -The -.Em long int -argument is converted to signed decimal, unsigned octal, or unsigned -decimal, as if the format had been -.Cm ld , -.Cm lo , -or -.Cm lu -respectively. -These conversion characters are deprecated, and will eventually disappear. -.It Cm eE -The -.Em double -argument is rounded and converted in the style -.Sm off -.Pf [\-]d Cm \&. No ddd Cm e No \\*(Pmdd -.Sm on -where there is one digit before the -decimal-point character -and the number of digits after it is equal to the precision; -if the precision is missing, -it is taken as 6; if the precision is -zero, no decimal-point character appears. -An -.Cm E -conversion uses the letter -.Cm E -(rather than -.Cm e ) -to introduce the exponent. -The exponent always contains at least two digits; if the value is zero, -the exponent is 00. -.It Cm f -The -.Em double -argument is rounded and converted to decimal notation in the style -.Sm off -.Pf [-]ddd Cm \&. No ddd , -.Sm on -where the number of digits after the decimal-point character -is equal to the precision specification. -If the precision is missing, it is taken as 6; if the precision is -explicitly zero, no decimal-point character appears. -If a decimal point appears, at least one digit appears before it. -.It Cm g -The -.Em double -argument is converted in style -.Cm f -or -.Cm e -(or -.Cm E -for -.Cm G -conversions). -The precision specifies the number of significant digits. -If the precision is missing, 6 digits are given; if the precision is zero, -it is treated as 1. -Style -.Cm e -is used if the exponent from its conversion is less than -4 or greater than -or equal to the precision. -Trailing zeros are removed from the fractional part of the result; a -decimal point appears only if it is followed by at least one digit. -.It Cm c -The -.Em int -argument is converted to an -.Em unsigned char , -and the resulting character is written. -.It Cm s -The -.Dq Em char * -argument is expected to be a pointer to an array of character type (pointer -to a string). -Characters from the array are written up to (but not including) -a terminating -.Dv NUL -character; -if a precision is specified, no more than the number specified are -written. -If a precision is given, no null character -need be present; if the precision is not specified, or is greater than -the size of the array, the array must contain a terminating -.Dv NUL -character. -.It Cm p -The -.Dq Em void * -pointer argument is printed in hexadecimal (as if by -.Ql %#x -or -.Ql %#lx ) . -.It Cm n -The number of characters written so far is stored into the -integer indicated by the -.Dq Em int * -(or variant) pointer argument. -No argument is converted. -.It Cm % -A -.Ql % -is written. No argument is converted. The complete conversion specification -is -.Ql %% . -.El -.Pp -In no case does a non-existent or small field width cause truncation of -a field; if the result of a conversion is wider than the field width, the -field is expanded to contain the conversion result. -.Pp -.Sh EXAMPLES -.br -To print a date and time in the form `Sunday, July 3, 10:02', -where -.Em weekday -and -.Em month -are pointers to strings: -.Bd -literal -offset indent -#include <stdio.h> -fprintf(stdout, "%s, %s %d, %.2d:%.2d\en", - weekday, month, day, hour, min); -.Ed -.Pp -To print \*(Pi -to five decimal places: -.Bd -literal -offset indent -#include <math.h> -#include <stdio.h> -fprintf(stdout, "pi = %.5f\en", 4 * atan(1.0)); -.Ed -.Pp -To allocate a 128 byte string and print into it: -.Bd -literal -offset indent -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -char *newfmt(const char *fmt, ...) -{ - char *p; - va_list ap; - if ((p = malloc(128)) == NULL) - return (NULL); - va_start(ap, fmt); - (void) vsnprintf(p, 128, fmt, ap); - va_end(ap); - return (p); -} -.Ed -.Sh SEE ALSO -.Xr printf 1 , -.Xr scanf 3 -.Sh STANDARDS -The -.Fn fprintf , -.Fn printf , -.Fn sprintf , -.Fn vprintf , -.Fn vfprintf , -and -.Fn vsprintf -functions -conform to -.St -ansiC . -.Sh HISTORY -The functions -.Fn snprintf -and -.Fn vsnprintf -are new to this release. -.Pp -The functions -.Fn asprintf -and -.Fn vasprintf -first appeared in the GNU C library. This implementation is thought -to be compatable but is not derived from the GNU code. This implementation -was written by Peter Wemm <peter@FreeBSD.org> and first appeared in -.Fx 2.2 . -.Sh BUGS -The conversion formats -.Cm \&%D , -.Cm \&%O , -and -.Cm %U -are not standard and -are provided only for backward compatibility. -The effect of padding the -.Cm %p -format with zeros (either by the -.Sq Cm 0 -flag or by specifying a precision), and the benign effect (i.e., none) -of the -.Sq Cm # -flag on -.Cm %n -and -.Cm %p -conversions, as well as other -nonsensical combinations such as -.Cm %Ld , -are not standard; such combinations -should be avoided. -.Pp -Because -.Fn sprintf -and -.Fn vsprintf -assume an infinitely long string, -callers must be careful not to overflow the actual space; -this is often hard to assure. -For safety, programmers should use the -.Fn snprintf -interface instead. -Unfortunately, this interface is not portable. diff --git a/lib/libc/stdio/printf.c b/lib/libc/stdio/printf.c deleted file mode 100644 index 9711549..0000000 --- a/lib/libc/stdio/printf.c +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)printf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -int -#if __STDC__ -printf(char const *fmt, ...) -#else -printf(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = vfprintf(stdout, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/lib/libc/stdio/putc.3 b/lib/libc/stdio/putc.3 deleted file mode 100644 index fc6e6a7..0000000 --- a/lib/libc/stdio/putc.3 +++ /dev/null @@ -1,129 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)putc.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt PUTC 3 -.Os -.Sh NAME -.Nm fputc , -.Nm putc , -.Nm putchar , -.Nm putw -.Nd output a character or word to a stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn fputc "int c" "FILE *stream" -.Ft int -.Fn putc "int c" "FILE *stream" -.Ft int -.Fn putchar "int c" -.Ft int -.Fn putw "int w" "FILE *stream" -.Sh DESCRIPTION -The -.Fn fputc -function -writes the character -.Fa c -(converted to an ``unsigned char'') -to the output stream pointed to by -.Fa stream . -.Pp -.Fn Putc -acts essentially identically to -.Fn fputc , -but is a macro that expands in-line. It may evaluate -.Fa stream -more than once, so arguments given to -.Fn putc -should not be expressions with potential side effects. -.Pp -.Fn Putchar -is identical to -.Fn putc -with an output stream of -.Em stdout . -.Pp -The -.Fn putw -function -writes the specified -.Em int -to the named output -.Fa stream . -.Sh RETURN VALUES -The functions, -.Fn fputc , -.Fn putc -and -.Fn putchar -return the character written. -If an error occurs, the value -.Dv EOF -is returned. -The -.Fn putw -function -returns 0 on success; -.Dv EOF -is returned if -a write error occurs, -or if an attempt is made to write a read-only stream. -.Sh SEE ALSO -.Xr ferror 3 , -.Xr fopen 3 , -.Xr getc 3 , -.Xr stdio 3 -.Sh STANDARDS -The functions -.Fn fputc , -.Fn putc , -and -.Fn putchar , -conform to -.St -ansiC . -A function -.Fn putw -function appeared in -.At v6 . -.Sh BUGS -The size and byte order of an -.Em int -varies from one machine to another, and -.Fn putw -is not recommended for portable applications. diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c deleted file mode 100644 index a1b0814..0000000 --- a/lib/libc/stdio/putc.c +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * A subroutine version of the macro putc. - */ -#undef putc - -int -putc(c, fp) - int c; - register FILE *fp; -{ - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sputc(c, fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); -} diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c deleted file mode 100644 index 99439ac..0000000 --- a/lib/libc/stdio/putchar.c +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -#undef putchar - -/* - * A subroutine version of the macro putchar - */ -int -putchar(c) - int c; -{ - int retval; - register FILE *so = stdout; - -#ifdef _THREAD_SAFE - _thread_flockfile(so,__FILE__,__LINE__); -#endif - retval = __sputc(c, so); -#ifdef _THREAD_SAFE - _thread_funlockfile(so); -#endif - return (retval); -} diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c deleted file mode 100644 index 91a20de..0000000 --- a/lib/libc/stdio/puts.c +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <string.h> -#include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * Write the given string to stdout, appending a newline. - */ -int -puts(s) - char const *s; -{ - int retval; - size_t c = strlen(s); - struct __suio uio; - struct __siov iov[2]; - - iov[0].iov_base = (void *)s; - iov[0].iov_len = c; - iov[1].iov_base = "\n"; - iov[1].iov_len = 1; - uio.uio_resid = c + 1; - uio.uio_iov = &iov[0]; - uio.uio_iovcnt = 2; -#ifdef _THREAD_SAFE - _thread_flockfile(stdout,__FILE__,__LINE__); -#endif - retval = __sfvwrite(stdout, &uio) ? EOF : '\n'; -#ifdef _THREAD_SAFE - _thread_funlockfile(stdout); -#endif - return (retval); -} diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c deleted file mode 100644 index 946a311..0000000 --- a/lib/libc/stdio/putw.c +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -int -putw(w, fp) - int w; - FILE *fp; -{ - int retval; - struct __suio uio; - struct __siov iov; - - iov.iov_base = &w; - iov.iov_len = uio.uio_resid = sizeof(w); - uio.uio_iov = &iov; - uio.uio_iovcnt = 1; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sfvwrite(fp, &uio); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); -} diff --git a/lib/libc/stdio/refill.c b/lib/libc/stdio/refill.c deleted file mode 100644 index f0583f7..0000000 --- a/lib/libc/stdio/refill.c +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include "local.h" - -static int lflush __P((FILE *)); - -static int -lflush(fp) - FILE *fp; -{ - - if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) - return (__sflush(fp)); - return (0); -} - -/* - * Refill a stdio buffer. - * Return EOF on eof or error, 0 otherwise. - */ -int -__srefill(fp) - register FILE *fp; -{ - - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - fp->_r = 0; /* largely a convenience for callers */ - - /* SysV does not make this test; take it out for compatibility */ - if (fp->_flags & __SEOF) - return (EOF); - - /* if not already reading, have to be reading and writing */ - if ((fp->_flags & __SRD) == 0) { - if ((fp->_flags & __SRW) == 0) { - errno = EBADF; - return (EOF); - } - /* switch to reading */ - if (fp->_flags & __SWR) { - if (__sflush(fp)) - return (EOF); - fp->_flags &= ~__SWR; - fp->_w = 0; - fp->_lbfsize = 0; - } - fp->_flags |= __SRD; - } else { - /* - * We were reading. If there is an ungetc buffer, - * we must have been reading from that. Drop it, - * restoring the previous buffer (if any). If there - * is anything in that buffer, return. - */ - if (HASUB(fp)) { - FREEUB(fp); - if ((fp->_r = fp->_ur) != 0) { - fp->_p = fp->_up; - return (0); - } - } - } - - if (fp->_bf._base == NULL) - __smakebuf(fp); - - /* - * Before reading from a line buffered or unbuffered file, - * flush all line buffered output files, per the ANSI C - * standard. - */ - if (fp->_flags & (__SLBF|__SNBF)) - (void) _fwalk(lflush); - fp->_p = fp->_bf._base; - fp->_r = (*fp->_read)(fp->_cookie, (char *)fp->_p, fp->_bf._size); - fp->_flags &= ~__SMOD; /* buffer contents are again pristine */ - if (fp->_r <= 0) { - if (fp->_r == 0) - fp->_flags |= __SEOF; - else { - fp->_r = 0; - fp->_flags |= __SERR; - } - return (EOF); - } - return (0); -} diff --git a/lib/libc/stdio/remove.3 b/lib/libc/stdio/remove.3 deleted file mode 100644 index 7d6fc7d..0000000 --- a/lib/libc/stdio/remove.3 +++ /dev/null @@ -1,78 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)remove.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt REMOVE 3 -.Os -.Sh NAME -.Nm remove -.Nd remove directory entry -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn remove "const char *path" -.Sh DESCRIPTION -The -.Fn remove -function -is an alias for the -.Xr unlink 2 -system call. -It deletes the file referenced by -.Fa path . -.Sh RETURN VALUES -Upon successful completion, -.Fn remove -returns 0. -Otherwise, \-1 is returned and the global variable -.Va errno -is set to indicate the error. -.Sh ERRORS -The -.Fn remove -function -may fail and set -.Va errno -for any of the errors specified for the routine -.Xr unlink 2 . -.Sh SEE ALSO -.Xr unlink 2 -.Sh STANDARDS -The -.Fn remove -function conforms to -.St -ansiC . diff --git a/lib/libc/stdio/remove.c b/lib/libc/stdio/remove.c deleted file mode 100644 index 6a25563..0000000 --- a/lib/libc/stdio/remove.c +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)remove.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <unistd.h> -#include <stdio.h> - -int -remove(file) - const char *file; -{ - return (unlink(file)); -} diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c deleted file mode 100644 index f6609d6..0000000 --- a/lib/libc/stdio/rewind.c +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)rewind.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <errno.h> -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -void -rewind(fp) - register FILE *fp; -{ -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - (void) fseek(fp, 0L, SEEK_SET); - clearerr(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - errno = 0; /* not required, but seems reasonable */ -} diff --git a/lib/libc/stdio/rget.c b/lib/libc/stdio/rget.c deleted file mode 100644 index 45d817d..0000000 --- a/lib/libc/stdio/rget.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)rget.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include "local.h" - -int -__srefill(FILE *); - -/* - * Handle getc() when the buffer ran out: - * Refill, then return the first character - * in the newly-filled buffer. - */ -int __srget(fp) - register FILE *fp; -{ - if (__srefill(fp) == 0) { - fp->_r--; - return (*fp->_p++); - } - return (EOF); -} diff --git a/lib/libc/stdio/scanf.3 b/lib/libc/stdio/scanf.3 deleted file mode 100644 index a9bbc41..0000000 --- a/lib/libc/stdio/scanf.3 +++ /dev/null @@ -1,439 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)scanf.3 8.2 (Berkeley) 12/11/93 -.\" -.Dd December 11, 1993 -.Dt SCANF 3 -.Os -.Sh NAME -.Nm scanf , -.Nm fscanf , -.Nm sscanf , -.Nm vscanf , -.Nm vsscanf , -.Nm vfscanf -.Nd input format conversion -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn scanf "const char *format" ... -.Ft int -.Fn fscanf "FILE *stream" "const char *format" ... -.Ft int -.Fn sscanf "const char *str" "const char *format" ... -.Fd #include <stdarg.h> -.Ft int -.Fn vscanf "const char *format" "va_list ap" -.Ft int -.Fn vsscanf "const char *str" "const char *format" "va_list ap" -.Ft int -.Fn vfscanf "FILE *stream" "const char *format" "va_list ap" -.Sh DESCRIPTION -The -.Fn scanf -family of functions scans input according to a -.Fa format -as described below. -This format may contain -.Em conversion specifiers ; -the results from such conversions, if any, -are stored through the -.Em pointer -arguments. -The -.Fn scanf -function -reads input from the standard input stream -.Em stdin , -.Fn fscanf -reads input from the stream pointer -.Fa stream , -and -.Fn sscanf -reads its input from the character string pointed to by -.Fa str . -The -.Fn vfscanf -function -is analogous to -.Xr vfprintf 3 -and reads input from the stream pointer -.Fa stream -using a variable argument list of pointers (see -.Xr stdarg 3 ) . -The -.Fn vscanf -function scans a variable argument list from the standard input and -the -.Fn vsscanf -function scans it from a string; -these are analogous to -the -.Fn vprintf -and -.Fn vsprintf -functions respectively. -Each successive -.Em pointer -argument must correspond properly with -each successive conversion specifier -(but see `suppression' below). -All conversions are introduced by the -.Cm % -(percent sign) character. -The -.Fa format -string -may also contain other characters. -White space (such as blanks, tabs, or newlines) in the -.Fa format -string match any amount of white space, including none, in the input. -Everything else -matches only itself. -Scanning stops -when an input character does not match such a format character. -Scanning also stops -when an input conversion cannot be made (see below). -.Sh CONVERSIONS -Following the -.Cm % -character introducing a conversion -there may be a number of -.Em flag -characters, as follows: -.Bl -tag -width indent -.It Cm * -Suppresses assignment. -The conversion that follows occurs as usual, but no pointer is used; -the result of the conversion is simply discarded. -.It Cm h -Indicates that the conversion will be one of -.Cm dioux -or -.Cm n -and the next pointer is a pointer to a -.Em short int -(rather than -.Em int ) . -.It Cm l -Indicates either that the conversion will be one of -.Cm dioux -or -.Cm n -and the next pointer is a pointer to a -.Em long int -(rather than -.Em int ) , -or that the conversion will be one of -.Cm efg -and the next pointer is a pointer to -.Em double -(rather than -.Em float ) . -.It Cm L -Indicates that the conversion will be -.Cm efg -and the next pointer is a pointer to -.Em long double . -(This type is not implemented; the -.Cm L -flag is currently ignored.) -.It Cm q -Indicates either that the conversion will be one of -.Cm dioux -or -.Cm n -and the next pointer is a pointer to a -.Em long long int -(rather than -.Em int ) , -.El -.Pp -In addition to these flags, -there may be an optional maximum field width, -expressed as a decimal integer, -between the -.Cm % -and the conversion. -If no width is given, -a default of `infinity' is used (with one exception, below); -otherwise at most this many characters are scanned -in processing the conversion. -Before conversion begins, -most conversions skip white space; -this white space is not counted against the field width. -.Pp -The following conversions are available: -.Bl -tag -width XXXX -.It Cm % -Matches a literal `%'. -That is, `%\&%' in the format string -matches a single input `%' character. -No conversion is done, and assignment does not occur. -.It Cm d -Matches an optionally signed decimal integer; -the next pointer must be a pointer to -.Em int . -.It Cm D -Equivalent to -.Cm ld ; -this exists only for backwards compatibility. -.It Cm i -Matches an optionally signed integer; -the next pointer must be a pointer to -.Em int . -The integer is read in base 16 if it begins -with -.Ql 0x -or -.Ql 0X , -in base 8 if it begins with -.Ql 0 , -and in base 10 otherwise. -Only characters that correspond to the base are used. -.It Cm o -Matches an octal integer; -the next pointer must be a pointer to -.Em unsigned int . -.It Cm O -Equivalent to -.Cm lo ; -this exists for backwards compatibility. -.It Cm u -Matches an optionally signed decimal integer; -the next pointer must be a pointer to -.Em unsigned int . -.It Cm x -Matches an optionally signed hexadecimal integer; -the next pointer must be a pointer to -.Em unsigned int . -.It Cm X -Equivalent to -.Cm lx ; -this violates the -.St -ansiC , -but is backwards compatible with previous -.Ux -systems. -.It Cm f -Matches an optionally signed floating-point number; -the next pointer must be a pointer to -.Em float . -.It Cm e -Equivalent to -.Cm f . -.It Cm g -Equivalent to -.Cm f . -.It Cm E -Equivalent to -.Cm lf ; -this violates the -.St -ansiC , -but is backwards compatible with previous -.Ux -systems. -.It Cm F -Equivalent to -.Cm lf ; -this exists only for backwards compatibility. -.It Cm s -Matches a sequence of non-white-space characters; -the next pointer must be a pointer to -.Em char , -and the array must be large enough to accept all the sequence and the -terminating -.Dv NUL -character. -The input string stops at white space -or at the maximum field width, whichever occurs first. -.It Cm c -Matches a sequence of -.Em width -count -characters (default 1); -the next pointer must be a pointer to -.Em char , -and there must be enough room for all the characters -(no terminating -.Dv NUL -is added). -The usual skip of leading white space is suppressed. -To skip white space first, use an explicit space in the format. -.It Cm \&[ -Matches a nonempty sequence of characters from the specified set -of accepted characters; -the next pointer must be a pointer to -.Em char , -and there must be enough room for all the characters in the string, -plus a terminating -.Dv NUL -character. -The usual skip of leading white space is suppressed. -The string is to be made up of characters in -(or not in) -a particular set; -the set is defined by the characters between the open bracket -.Cm [ -character -and a close bracket -.Cm ] -character. -The set -.Em excludes -those characters -if the first character after the open bracket is a circumflex -.Cm ^ . -To include a close bracket in the set, -make it the first character after the open bracket -or the circumflex; -any other position will end the set. -The hyphen character -.Cm - -is also special; -when placed between two other characters, -it adds all intervening characters to the set. -To include a hyphen, -make it the last character before the final close bracket. -For instance, -.Ql [^]0-9-] -means the set `everything except close bracket, zero through nine, -and hyphen'. -The string ends with the appearance of a character not in the -(or, with a circumflex, in) set -or when the field width runs out. -.It Cm p -Matches a pointer value (as printed by -.Ql %p -in -.Xr printf 3 ) ; -the next pointer must be a pointer to -.Em void . -.It Cm n -Nothing is expected; -instead, the number of characters consumed thus far from the input -is stored through the next pointer, -which must be a pointer to -.Em int . -This is -.Em not -a conversion, although it can be suppressed with the -.Cm * -flag. -.El -.Pp -For backwards compatibility, -other conversion characters (except -.Ql \e0 ) -are taken as if they were -.Ql %d -or, if uppercase, -.Ql %ld , -and a `conversion' of -.Ql %\e0 -causes an immediate return of -.Dv EOF . -The -.Cm F -and -.Cm X -conversions will be changed in the future -to conform to the -.Tn ANSI -C standard, -after which they will act like -.Cm f -and -.Cm x -respectively. -.Pp -.Sh RETURN VALUES -These -functions -return -the number of input items assigned, which can be fewer than provided -for, or even zero, in the event of a matching failure. -Zero -indicates that, while there was input available, -no conversions were assigned; -typically this is due to an invalid input character, -such as an alphabetic character for a -.Ql %d -conversion. -The value -.Dv EOF -is returned if an input failure occurs before any conversion such as an -end-of-file occurs. If an error or end-of-file occurs after conversion -has begun, -the number of conversions which were successfully completed is returned. -.Sh SEE ALSO -.Xr getc 3 , -.Xr printf 3 , -.Xr strtod 3 , -.Xr strtol 3 , -.Xr strtoul 3 -.Sh STANDARDS -The functions -.Fn fscanf , -.Fn scanf , -and -.Fn sscanf -conform to -.St -ansiC . -.Sh HISTORY -The functions -.Fn vscanf , -.Fn vsscanf -and -.Fn vfscanf -are new to this release. -.Sh BUGS -The current situation with -.Cm %F -and -.Cm %X -conversions is unfortunate. -.Pp -All of the backwards compatibility formats will be removed in the future. -.Pp -Numerical strings are truncated to 512 characters; for example, -.Cm %f -and -.Cm %d -are implicitly -.Cm %512f -and -.Cm %512d . diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c deleted file mode 100644 index 7a8bd65..0000000 --- a/lib/libc/stdio/scanf.c +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -#if __STDC__ -int -scanf(char const *fmt, ...) -#else -int -scanf(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif -#ifdef _THREAD_SAFE - _thread_flockfile(stdin,__FILE__,__LINE__); -#endif - ret = __svfscanf(stdin, fmt, ap); - va_end(ap); -#ifdef _THREAD_SAFE - _thread_funlockfile(stdin); -#endif - return (ret); -} diff --git a/lib/libc/stdio/setbuf.3 b/lib/libc/stdio/setbuf.3 deleted file mode 100644 index ec5bbd8..0000000 --- a/lib/libc/stdio/setbuf.3 +++ /dev/null @@ -1,202 +0,0 @@ -.\" Copyright (c) 1980, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the American National Standards Committee X3, on Information -.\" Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)setbuf.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt SETBUF 3 -.Os BSD 4 -.Sh NAME -.Nm setbuf , -.Nm setbuffer , -.Nm setlinebuf , -.Nm setvbuf -.Nd stream buffering operations -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft void -.Fn setbuf "FILE *stream" "char *buf" -.Ft void -.Fn setbuffer "FILE *stream" "char *buf" "int size" -.Ft int -.Fn setlinebuf "FILE *stream" -.Ft int -.Fn setvbuf "FILE *stream" "char *buf" "int mode" "size_t size" -.Sh DESCRIPTION -The three types of buffering available are unbuffered, block buffered, -and line buffered. -When an output stream is unbuffered, information appears on the -destination file or terminal as soon as written; -when it is block buffered many characters are saved up and written as a block; -when it is line buffered characters are saved up until a newline is -output or input is read from any stream attached to a terminal device -(typically stdin). -The function -.Xr fflush 3 -may be used to force the block out early. -(See -.Xr fclose 3 . ) -.Pp -Normally all files are block buffered. -When the first -.Tn I/O -operation occurs on a file, -.Xr malloc 3 -is called, -and an optimally-sized buffer is obtained. -If a stream refers to a terminal -(as -.Em stdout -normally does) it is line buffered. -The standard error stream -.Em stderr -is always unbuffered. -.Pp -The -.Fn setvbuf -function -may be used to alter the buffering behavior of a stream. -The -.Fa mode -parameter must be one of the following three macros: -.Bl -tag -width _IOFBF -offset indent -.It Dv _IONBF -unbuffered -.It Dv _IOLBF -line buffered -.It Dv _IOFBF -fully buffered -.El -.Pp -The -.Fa size -parameter may be given as zero -to obtain deferred optimal-size buffer allocation as usual. -If it is not zero, -then except for unbuffered files, the -.Fa buf -argument should point to a buffer at least -.Fa size -bytes long; -this buffer will be used instead of the current buffer. -(If the -.Fa size -argument -is not zero but -.Fa buf -is -.Dv NULL , -a buffer of the given size will be allocated immediately, -and released on close. -This is an extension to ANSI C; -portable code should use a size of 0 with any -.Dv NULL -buffer.) -.Pp -The -.Fn setvbuf -function may be used at any time, -but may have peculiar side effects -(such as discarding input or flushing output) -if the stream is ``active''. -Portable applications should call it only once on any given stream, -and before any -.Tn I/O -is performed. -.Pp -The other three calls are, in effect, simply aliases for calls to -.Fn setvbuf . -Except for the lack of a return value, the -.Fn setbuf -function is exactly equivalent to the call -.Pp -.Dl "setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);" -.Pp -The -.Fn setbuffer -function -is the same, except that the size of the buffer is up to the caller, -rather than being determined by the default -.Dv BUFSIZ . -The -.Fn setlinebuf -function -is exactly equivalent to the call: -.Pp -.Dl "setvbuf(stream, (char *)NULL, _IOLBF, 0);" -.Sh RETURN VALUES -The -.Fn setvbuf -function returns 0 on success, or -.Dv EOF -if the request cannot be honored -(note that the stream is still functional in this case). -.Pp -The -.Fn setlinebuf -function returns what the equivalent -.Fn setvbuf -would have returned. -.Sh SEE ALSO -.Xr fclose 3 , -.Xr fopen 3 , -.Xr fread 3 , -.Xr malloc 3 , -.Xr printf 3 , -.Xr puts 3 -.Sh STANDARDS -The -.Fn setbuf -and -.Fn setvbuf -functions -conform to -.St -ansiC . -.Sh BUGS -The -.Fn setbuffer -and -.Fn setlinebuf -functions are not portable to versions of -.Bx -before -.Bx 4.2 . -On -.Bx 4.2 -and -.Bx 4.3 -systems, -.Fn setbuf -always uses a suboptimal buffer size and should be avoided. diff --git a/lib/libc/stdio/setbuf.c b/lib/libc/stdio/setbuf.c deleted file mode 100644 index b07bce9..0000000 --- a/lib/libc/stdio/setbuf.c +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)setbuf.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include "local.h" - -void -setbuf(fp, buf) - FILE *fp; - char *buf; -{ - (void) setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); -} diff --git a/lib/libc/stdio/setbuffer.c b/lib/libc/stdio/setbuffer.c deleted file mode 100644 index d272177..0000000 --- a/lib/libc/stdio/setbuffer.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)setbuffer.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> - -void -setbuffer(fp, buf, size) - register FILE *fp; - char *buf; - int size; -{ - - (void)setvbuf(fp, buf, buf ? _IOFBF : _IONBF, (size_t)size); -} - -/* - * set line buffering - */ -int -setlinebuf(fp) - FILE *fp; -{ - - return (setvbuf(fp, (char *)NULL, _IOLBF, (size_t)0)); -} diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c deleted file mode 100644 index 9cc6bb6..0000000 --- a/lib/libc/stdio/setvbuf.c +++ /dev/null @@ -1,178 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <stdlib.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* - * Set one of the three kinds of buffering, optionally including - * a buffer. - */ -int -setvbuf(fp, buf, mode, size) - register FILE *fp; - char *buf; - register int mode; - register size_t size; -{ - register int ret, flags; - size_t iosize; - int ttyflag; - - /* - * Verify arguments. The `int' limit on `size' is due to this - * particular implementation. Note, buf and size are ignored - * when setting _IONBF. - */ - if (mode != _IONBF) - if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) - return (EOF); - -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - /* - * Write current buffer, if any. Discard unread input (including - * ungetc data), cancel line buffering, and free old buffer if - * malloc()ed. We also clear any eof condition, as if this were - * a seek. - */ - ret = 0; - (void)__sflush(fp); - if (HASUB(fp)) - FREEUB(fp); - fp->_r = fp->_lbfsize = 0; - flags = fp->_flags; - if (flags & __SMBF) - free((void *)fp->_bf._base); - flags &= ~(__SLBF | __SNBF | __SMBF | __SOPT | __SNPT | __SEOF); - - /* If setting unbuffered mode, skip all the hard work. */ - if (mode == _IONBF) - goto nbf; - - /* - * Find optimal I/O size for seek optimization. This also returns - * a `tty flag' to suggest that we check isatty(fd), but we do not - * care since our caller told us how to buffer. - */ - flags |= __swhatbuf(fp, &iosize, &ttyflag); - if (size == 0) { - buf = NULL; /* force local allocation */ - size = iosize; - } - - /* Allocate buffer if needed. */ - if (buf == NULL) { - if ((buf = malloc(size)) == NULL) { - /* - * Unable to honor user's request. We will return - * failure, but try again with file system size. - */ - ret = EOF; - if (size != iosize) { - size = iosize; - buf = malloc(size); - } - } - if (buf == NULL) { - /* No luck; switch to unbuffered I/O. */ -nbf: - fp->_flags = flags | __SNBF; - fp->_w = 0; - fp->_bf._base = fp->_p = fp->_nbuf; - fp->_bf._size = 1; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (ret); - } - flags |= __SMBF; - } - - /* - * Kill any seek optimization if the buffer is not the - * right size. - * - * SHOULD WE ALLOW MULTIPLES HERE (i.e., ok iff (size % iosize) == 0)? - */ - if (size != iosize) - flags |= __SNPT; - - /* - * Fix up the FILE fields, and set __cleanup for output flush on - * exit (since we are buffered in some way). - */ - if (mode == _IOLBF) - flags |= __SLBF; - fp->_flags = flags; - fp->_bf._base = fp->_p = (unsigned char *)buf; - fp->_bf._size = size; - /* fp->_lbfsize is still 0 */ - if (flags & __SWR) { - /* - * Begin or continue writing: see __swsetup(). Note - * that __SNBF is impossible (it was handled earlier). - */ - if (flags & __SLBF) { - fp->_w = 0; - fp->_lbfsize = -fp->_bf._size; - } else - fp->_w = size; - } else { - /* begin/continue reading, or stay in intermediate state */ - fp->_w = 0; - } - __cleanup = _cleanup; - -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (ret); -} diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c deleted file mode 100644 index a4c04d9..0000000 --- a/lib/libc/stdio/snprintf.c +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id: snprintf.c,v 1.10 1997/12/24 23:54:13 ache Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <limits.h> -#include <stdio.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -#if __STDC__ -int -snprintf(char *str, size_t n, char const *fmt, ...) -#else -int -snprintf(str, n, fmt, va_alist) - char *str; - size_t n; - char *fmt; - va_dcl -#endif -{ - size_t on; - int ret; - va_list ap; - FILE f; - - on = n; - if (n != 0) - n--; - if (n > INT_MAX) - n = INT_MAX; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - f._file = -1; - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n; - ret = vfprintf(&f, fmt, ap); - if (on > 0) - *f._p = '\0'; - va_end(ap); - return (ret); -} diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c deleted file mode 100644 index fb0514d..0000000 --- a/lib/libc/stdio/sprintf.c +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif -#include <limits.h> -#include "local.h" - -int -#if __STDC__ -sprintf(char *str, char const *fmt, ...) -#else -sprintf(str, fmt, va_alist) - char *str; - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - FILE f; - - f._file = -1; - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = INT_MAX; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = vfprintf(&f, fmt, ap); - va_end(ap); - *f._p = 0; - return (ret); -} diff --git a/lib/libc/stdio/sscanf.c b/lib/libc/stdio/sscanf.c deleted file mode 100644 index d114ae3..0000000 --- a/lib/libc/stdio/sscanf.c +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)sscanf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <string.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif -#include "local.h" - -static int eofread __P((void *, char *, int)); - -/* ARGSUSED */ -static int -eofread(cookie, buf, len) - void *cookie; - char *buf; - int len; -{ - - return (0); -} - -#if __STDC__ -int -sscanf(const char *str, char const *fmt, ...) -#else -int -sscanf(str, fmt, va_alist) - char *str; - char *fmt; - va_dcl -#endif -{ - int ret; - va_list ap; - FILE f; - - f._file = -1; - f._flags = __SRD; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._r = strlen(str); - f._read = eofread; - f._ub._base = NULL; - f._lb._base = NULL; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - ret = __svfscanf(&f, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/lib/libc/stdio/stdio.3 b/lib/libc/stdio/stdio.3 deleted file mode 100644 index 81a6970..0000000 --- a/lib/libc/stdio/stdio.3 +++ /dev/null @@ -1,287 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)stdio.3 8.7 (Berkeley) 4/19/94 -.\" -.Dd April 19, 1994 -.Dt STDIO 3 -.Os BSD 4 -.Sh NAME -.Nm stdio -.Nd standard input/output library functions -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Fd FILE *stdin; -.Fd FILE *stdout; -.Fd FILE *stderr; -.Sh DESCRIPTION -The standard -.Tn I/O -library provides a simple and efficient buffered stream -.Tn I/O -interface. -Input and output is mapped into logical data streams -and the physical -.Tn I/O -characteristics are concealed. The functions and macros are listed -below; more information is available from the individual man pages. -.Pp -A stream is associated with an external file (which may be a physical -device) by -.Em opening -a file, which may involve creating a new file. Creating an -existing file causes its former contents to be discarded. -If a file can support positioning requests (such as a disk file, as opposed -to a terminal) then a -.Em file position indicator -associated with the stream is positioned at the start of the file (byte -zero), unless the file is opened with append mode. If append mode -is used, the position indicator will be placed the end-of-file. -The position indicator is maintained by subsequent reads, writes -and positioning requests. All input occurs as if the characters -were read by successive calls to the -.Xr fgetc 3 -function; all output takes place as if all characters were -read by successive calls to the -.Xr fputc 3 -function. -.Pp -A file is disassociated from a stream by -.Em closing -the file. -Output streams are flushed (any unwritten buffer contents are transferred -to the host environment) before the stream is disassociated from the file. -The value of a pointer to a -.Dv FILE -object is indeterminate after a file is closed (garbage). -.Pp -A file may be subsequently reopened, by the same or another program -execution, and its contents reclaimed or modified (if it can be repositioned -at the start). If the main function returns to its original caller, or -the -.Xr exit 3 -function is called, all open files are closed (hence all output -streams are flushed) before program termination. Other methods -of program termination, such as -.Xr abort 3 -do not bother about closing files properly. -.Pp -This implementation needs and makes -no distinction between -.Dq text -and -.Dq binary -streams. -In effect, all streams are binary. -No translation is performed and no extra padding appears on any stream. -.Pp -At program startup, three streams are predefined and need not be -opened explicitly: -.Bl -bullet -compact -offset indent -.It -.Em standard input -(for reading conventional input), -.It -.Em standard output -(for writing conventional output), and -.It -.Em standard error -(for writing diagnostic output). -.El -These streams are abbreviated -.Em stdin , stdout -and -.Em stderr . -Initially, the standard error stream -is unbuffered; the standard input and output streams are -fully buffered if and only if the streams do not refer to -an interactive or -.Dq terminal -device, as determined by the -.Xr isatty 3 -function. -In fact, -.Em all -freshly-opened streams that refer to terminal devices -default to line buffering, and -pending output to such streams is written automatically -whenever an such an input stream is read. -Note that this applies only to -.Dq "true reads" ; -if the read request can be satisfied by existing buffered data, -no automatic flush will occur. -In these cases, -or when a large amount of computation is done after printing -part of a line on an output terminal, it is necessary to -.Xr fflush 3 -the standard output before going off and computing so that the output -will appear. -Alternatively, these defaults may be modified via the -.Xr setvbuf 3 -function. -.Pp -The -.Nm stdio -library is a part of the library -.Nm libc -and routines are automatically loaded as needed by the compilers -.Xr cc 1 -and -.Xr pc 1 . -The -.Tn SYNOPSIS -sections of the following manual pages indicate which include files -are to be used, what the compiler declaration for the function -looks like and which external variables are of interest. -.Pp -The following are defined as macros; -these names may not be re-used -without first removing their current definitions with -.Dv #undef : -.Dv BUFSIZ , -.Dv EOF , -.Dv FILENAME_MAX , -.Dv FOPEN_MAX , -.Dv L_cuserid , -.Dv L_ctermid , -.Dv L_tmpnam, -.Dv NULL , -.Dv SEEK_END , -.Dv SEEK_SET , -.Dv SEE_CUR , -.Dv TMP_MAX , -.Dv clearerr , -.Dv feof , -.Dv ferror , -.Dv fileno , -.Dv freopen , -.Dv fwopen , -.Dv getc , -.Dv getchar , -.Dv putc , -.Dv putchar , -.Dv stderr , -.Dv stdin , -.Dv stdout . -Function versions of the macro functions -.Fn feof , -.Fn ferror , -.Fn clearerr , -.Fn fileno , -.Fn getc , -.Fn getchar , -.Fn putc , -and -.Fn putchar -exist and will be used if the macros -definitions are explicitly removed. -.Sh SEE ALSO -.Xr close 2 , -.Xr open 2 , -.Xr read 2 , -.Xr write 2 -.Sh BUGS -The standard buffered functions do not interact well with certain other -library and system functions, especially -.Xr vfork 2 -and -.Xr abort 3 . -.Sh STANDARDS -The -.Nm stdio -library conforms to -.St -ansiC . -.Sh LIST OF FUNCTIONS -.Bl -column "Description" -.Sy Function Description -clearerr check and reset stream status -fclose close a stream -fdopen stream open functions -feof check and reset stream status -ferror check and reset stream status -fflush flush a stream -fgetc get next character or word from input stream -fgetln get a line from a stream -fgetpos reposition a stream -fgets get a line from a stream -fileno check and reset stream status -fopen stream open functions -fprintf formatted output conversion -fpurge flush a stream -fputc output a character or word to a stream -fputs output a line to a stream -fread binary stream input/output -freopen stream open functions -fropen open a stream -fscanf input format conversion -fseek reposition a stream -fsetpos reposition a stream -ftell reposition a stream -funopen open a stream -fwopen open a stream -fwrite binary stream input/output -getc get next character or word from input stream -getchar get next character or word from input stream -gets get a line from a stream -getw get next character or word from input stream -mkstemp create unique temporary file -mktemp create unique temporary file -perror system error messages -printf formatted output conversion -putc output a character or word to a stream -putchar output a character or word to a stream -puts output a line to a stream -putw output a character or word to a stream -remove remove directory entry -rewind reposition a stream -scanf input format conversion -setbuf stream buffering operations -setbuffer stream buffering operations -setlinebuf stream buffering operations -setvbuf stream buffering operations -snprintf formatted output conversion -sprintf formatted output conversion -sscanf input format conversion -strerror system error messages -sys_errlist system error messages -sys_nerr system error messages -tempnam temporary file routines -tmpfile temporary file routines -tmpnam temporary file routines -ungetc un-get character from input stream -vfprintf formatted output conversion -vfscanf input format conversion -vprintf formatted output conversion -vscanf input format conversion -vsnprintf formatted output conversion -vsprintf formatted output conversion -vsscanf input format conversion -.El diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c deleted file mode 100644 index 852e971..0000000 --- a/lib/libc/stdio/stdio.c +++ /dev/null @@ -1,111 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <fcntl.h> -#include <unistd.h> -#include <stdio.h> -#include "local.h" - -/* - * Small standard I/O/seek/close functions. - * These maintain the `known seek offset' for seek optimisation. - */ -int -__sread(cookie, buf, n) - void *cookie; - char *buf; - int n; -{ - register FILE *fp = cookie; - register int ret; - - ret = read(fp->_file, buf, (size_t)n); - /* if the read succeeded, update the current offset */ - if (ret >= 0) - fp->_offset += ret; - else - fp->_flags &= ~__SOFF; /* paranoia */ - return (ret); -} - -int -__swrite(cookie, buf, n) - void *cookie; - char const *buf; - int n; -{ - register FILE *fp = cookie; - - if (fp->_flags & __SAPP) - (void) lseek(fp->_file, (off_t)0, SEEK_END); - fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */ - return (write(fp->_file, buf, (size_t)n)); -} - -fpos_t -__sseek(cookie, offset, whence) - void *cookie; - fpos_t offset; - int whence; -{ - register FILE *fp = cookie; - register off_t ret; - - ret = lseek(fp->_file, (off_t)offset, whence); - if (ret == -1) - fp->_flags &= ~__SOFF; - else { - fp->_flags |= __SOFF; - fp->_offset = ret; - } - return (ret); -} - -int -__sclose(cookie) - void *cookie; -{ - - return (close(((FILE *)cookie)->_file)); -} diff --git a/lib/libc/stdio/tempnam.c b/lib/libc/stdio/tempnam.c deleted file mode 100644 index 243fa39..0000000 --- a/lib/libc/stdio/tempnam.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)tempnam.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/param.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <paths.h> - -char * -tempnam(dir, pfx) - const char *dir, *pfx; -{ - int sverrno; - char *f, *name; - - if (!(name = malloc(MAXPATHLEN))) - return(NULL); - - if (!pfx) - pfx = "tmp."; - - if ((f = getenv("TMPDIR"))) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); - if ((f = mktemp(name))) - return(f); - } - - if ((f = (char *)dir)) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); - if ((f = mktemp(name))) - return(f); - } - - f = P_tmpdir; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); - if ((f = mktemp(name))) - return(f); - - f = _PATH_TMP; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); - if ((f = mktemp(name))) - return(f); - - sverrno = errno; - free(name); - errno = sverrno; - return(NULL); -} diff --git a/lib/libc/stdio/tmpfile.c b/lib/libc/stdio/tmpfile.c deleted file mode 100644 index 2f8abfc..0000000 --- a/lib/libc/stdio/tmpfile.c +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> -#include <signal.h> -#include <unistd.h> -#include <errno.h> -#include <stdio.h> -#include <paths.h> - -FILE * -tmpfile() -{ - sigset_t set, oset; - FILE *fp; - int fd, sverrno; -#define TRAILER "tmp.XXXXXX" - char buf[sizeof(_PATH_TMP) + sizeof(TRAILER)]; - - (void)memcpy(buf, _PATH_TMP, sizeof(_PATH_TMP) - 1); - (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER)); - - sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); - - fd = mkstemp(buf); - if (fd != -1) - (void)unlink(buf); - - (void)sigprocmask(SIG_SETMASK, &oset, NULL); - - if (fd == -1) - return (NULL); - - if ((fp = fdopen(fd, "w+")) == NULL) { - sverrno = errno; - (void)close(fd); - errno = sverrno; - return (NULL); - } - return (fp); -} diff --git a/lib/libc/stdio/tmpnam.3 b/lib/libc/stdio/tmpnam.3 deleted file mode 100644 index d7e0326..0000000 --- a/lib/libc/stdio/tmpnam.3 +++ /dev/null @@ -1,219 +0,0 @@ -.\" Copyright (c) 1988, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the American National Standards Committee X3, on Information -.\" Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)tmpnam.3 8.2 (Berkeley) 11/17/93 -.\" -.Dd November 17, 1993 -.Dt TMPFILE 3 -.Os -.Sh NAME -.Nm tempnam , -.Nm tmpfile , -.Nm tmpnam -.Nd temporary file routines -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft FILE * -.Fn tmpfile void -.Ft char * -.Fn tmpnam "char *str" -.Ft char * -.Fn tempnam "const char *tmpdir" "const char *prefix" -.Sh DESCRIPTION -The -.Fn tmpfile -function -returns a pointer to a stream associated with a file descriptor returned -by the routine -.Xr mkstemp 3 . -The created file is unlinked before -.Fn tmpfile -returns, causing the file to be automatically deleted when the last -reference to it is closed. -The file is opened with the access value -.Ql w+ . -.Pp -The -.Fn tmpnam -function -returns a pointer to a file name, in the -.Dv P_tmpdir -directory, which -did not reference an existing file at some indeterminate point in the -past. -.Dv P_tmpdir -is defined in the include file -.Aq Pa stdio.h . -If the argument -.Fa s -is -.Pf non- Dv NULL , -the file name is copied to the buffer it references. -Otherwise, the file name is copied to a static buffer. -In either case, -.Fn tmpnam -returns a pointer to the file name. -.Pp -The buffer referenced by -.Fa s -is expected to be at least -.Dv L_tmpnam -bytes in length. -.Dv L_tmpnam -is defined in the include file -.Aq Pa stdio.h . -.Pp -The -.Fn tempnam -function -is similar to -.Fn tmpnam , -but provides the ability to specify the directory which will -contain the temporary file and the file name prefix. -.Pp -The environment variable -.Ev TMPDIR -(if set), the argument -.Fa tmpdir -(if -.Pf non- Dv NULL ) , -the directory -.Dv P_tmpdir , -and the directory -.Pa /tmp -are tried, in the listed order, as directories in which to store the -temporary file. -.Pp -The argument -.Fa prefix , -if -.Pf non- Dv NULL , -is used to specify a file name prefix, which will be the -first part of the created file name. -.Fn Tempnam -allocates memory in which to store the file name; the returned pointer -may be used as a subsequent argument to -.Xr free 3 . -.Sh RETURN VALUES -The -.Fn tmpfile -function -returns a pointer to an open file stream on success, and a -.Dv NULL -pointer -on error. -.Pp -The -.Fn tmpnam -and -.Fn tempfile -functions -return a pointer to a file name on success, and a -.Dv NULL -pointer -on error. -.Sh ERRORS -The -.Fn tmpfile -function -may fail and set the global variable -.Va errno -for any of the errors specified for the library functions -.Xr fdopen 3 -or -.Xr mkstemp 3 . -.Pp -The -.Fn tmpnam -function -may fail and set -.Va errno -for any of the errors specified for the library function -.Xr mktemp 3 . -.Pp -The -.Fn tempnam -function -may fail and set -.Va errno -for any of the errors specified for the library functions -.Xr malloc 3 -or -.Xr mktemp 3 . -.Sh SEE ALSO -.Xr mkstemp 3 , -.Xr mktemp 3 -.Sh STANDARDS -The -.Fn tmpfile -and -.Fn tmpnam -functions -conform to -.St -ansiC . -.Sh BUGS -These interfaces are provided for System V and -.Tn ANSI -compatibility only. -The -.Xr mkstemp 3 -interface is strongly preferred. -.Pp -There are four important problems with these interfaces (as well as -with the historic -.Xr mktemp 3 -interface). -First, there is an obvious race between file name selection and file -creation and deletion. -Second, most historic implementations provide only a limited number -of possible temporary file names (usually 26) before file names will -start being recycled. -Third, the System V implementations of these functions (and of -.Xr mktemp 3 ) -use the -.Xr access 2 -function to determine whether or not the temporary file may be created. -This has obvious ramifications for setuid or setgid programs, complicating -the portable use of these interfaces in such programs. -Finally, there is no specification of the permissions with which the -temporary files are created. -.Pp -This implementation does not have these flaws, but portable software -cannot depend on that. -In particular, the -.Fn tmpfile -interface should not be used in software expected to be used on other systems -if there is any possibility that the user does not wish the temporary file to -be publicly readable and writable. diff --git a/lib/libc/stdio/tmpnam.c b/lib/libc/stdio/tmpnam.c deleted file mode 100644 index ce86482..0000000 --- a/lib/libc/stdio/tmpnam.c +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)tmpnam.c 8.3 (Berkeley) 3/28/94"; -#endif /* LIBC_SCCS and not lint */ - -#include <sys/types.h> - -#include <stdio.h> -#include <unistd.h> - -char * -tmpnam(s) - char *s; -{ - static u_long tmpcount; - static char buf[L_tmpnam]; - - if (s == NULL) - s = buf; - (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount); - ++tmpcount; - return (mktemp(s)); -} diff --git a/lib/libc/stdio/ungetc.3 b/lib/libc/stdio/ungetc.3 deleted file mode 100644 index e5c68d0..0000000 --- a/lib/libc/stdio/ungetc.3 +++ /dev/null @@ -1,95 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Chris Torek and the American National Standards Committee X3, -.\" on Information Processing Systems. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)ungetc.3 8.1 (Berkeley) 6/4/93 -.\" -.Dd June 4, 1993 -.Dt UNGETC 3 -.Os -.Sh NAME -.Nm ungetc -.Nd un-get character from input stream -.Sh SYNOPSIS -.Fd #include <stdio.h> -.Ft int -.Fn ungetc "int c" "FILE *stream" -.Sh DESCRIPTION -The -.Fn ungetc -function pushes the character -.Fa c -(converted to an unsigned char) -back onto the input stream pointed to by -.Fa stream . -The pushed-backed characters will be returned by subsequent reads on the -stream (in reverse order). -A successful intervening call, using the same stream, to one of the file -positioning functions -.Po -.Xr fseek 3 , -.Xr fsetpos 3 , -or -.Xr rewind 3 -.Pc -will discard the pushed back characters. -.Pp -One character of push-back is guaranteed, -but as long as there is -sufficient memory, an effectively infinite amount of pushback is allowed. -.Pp -If a character is successfully pushed-back, -the end-of-file indicator for the stream is cleared. -.Sh RETURN VALUES -The -.Fn ungetc -function -returns -the character pushed-back after the conversion, or -.Dv EOF -if the operation fails. -If the value of the argument -.Fa c -character equals -.Dv EOF , -the operation will fail and the stream will remain unchanged. -.Sh SEE ALSO -.Xr fseek 3 , -.Xr getc 3 , -.Xr setvbuf 3 -.Sh STANDARDS -The -.Fn ungetc -function conforms to -.St -ansiC . diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c deleted file mode 100644 index c0355b7..0000000 --- a/lib/libc/stdio/ungetc.c +++ /dev/null @@ -1,183 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -static int __submore __P((FILE *)); - -/* - * Expand the ungetc buffer `in place'. That is, adjust fp->_p when - * the buffer moves, so that it points the same distance from the end, - * and move the bytes in the buffer around as necessary so that they - * are all at the end (stack-style). - */ -static int -__submore(fp) - register FILE *fp; -{ - register int i; - register unsigned char *p; - - if (fp->_ub._base == fp->_ubuf) { - /* - * Get a new buffer (rather than expanding the old one). - */ - if ((p = malloc((size_t)BUFSIZ)) == NULL) - return (EOF); - fp->_ub._base = p; - fp->_ub._size = BUFSIZ; - p += BUFSIZ - sizeof(fp->_ubuf); - for (i = sizeof(fp->_ubuf); --i >= 0;) - p[i] = fp->_ubuf[i]; - fp->_p = p; - return (0); - } - i = fp->_ub._size; - p = realloc(fp->_ub._base, (size_t)(i << 1)); - if (p == NULL) - return (EOF); - /* no overlap (hence can use memcpy) because we doubled the size */ - (void)memcpy((void *)(p + i), (void *)p, (size_t)i); - fp->_p = p + i; - fp->_ub._base = p; - fp->_ub._size = i << 1; - return (0); -} - -int -ungetc(c, fp) - int c; - register FILE *fp; -{ - if (c == EOF) - return (EOF); - if (!__sdidinit) - __sinit(); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - if ((fp->_flags & __SRD) == 0) { - /* - * Not already reading: no good unless reading-and-writing. - * Otherwise, flush any current write stuff. - */ - if ((fp->_flags & __SRW) == 0) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (EOF); - } - if (fp->_flags & __SWR) { - if (__sflush(fp)) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (EOF); - } - fp->_flags &= ~__SWR; - fp->_w = 0; - fp->_lbfsize = 0; - } - fp->_flags |= __SRD; - } - c = (unsigned char)c; - - /* - * If we are in the middle of ungetc'ing, just continue. - * This may require expanding the current ungetc buffer. - */ - if (HASUB(fp)) { - if (fp->_r >= fp->_ub._size && __submore(fp)) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (EOF); - } - *--fp->_p = c; - fp->_r++; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (c); - } - fp->_flags &= ~__SEOF; - - /* - * If we can handle this by simply backing up, do so, - * but never replace the original character. - * (This makes sscanf() work when scanning `const' data.) - */ - if (fp->_bf._base != NULL && fp->_p > fp->_bf._base && - fp->_p[-1] == c) { - fp->_p--; - fp->_r++; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (c); - } - - /* - * Create an ungetc buffer. - * Initially, we will use the `reserve' buffer. - */ - fp->_ur = fp->_r; - fp->_up = fp->_p; - fp->_ub._base = fp->_ubuf; - fp->_ub._size = sizeof(fp->_ubuf); - fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; - fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; - fp->_r = 1; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (c); -} diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c deleted file mode 100644 index 7b75b2c..0000000 --- a/lib/libc/stdio/vasprintf.c +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * Copyright (c) 1996 Peter Wemm <peter@freebsd.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_RCS) && !defined(lint) -static char rcsid[] = "$Id: vasprintf.c,v 1.6 1997/07/06 07:54:56 peter Exp $"; -#endif /* LIBC_RCS and not lint */ - -#include <stdio.h> -#include <stdlib.h> - -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -#define CHUNK_SPARE 128 /* how much spare to allocate to avoid realloc calls */ - -struct bufcookie { - char *base; /* start of buffer */ - size_t size; - size_t left; -}; - -static int writehook __P((void *cookie, const char *, int)); - -static int -writehook(cookie, buf, len) - void *cookie; - const char *buf; - int len; -{ - struct bufcookie *h = (struct bufcookie *)cookie; - char *newbuf; - - if (len == 0) - return 0; - - if (len > h->left) { - /* grow malloc region */ - /* - * XXX this is linearly expanded, which is slow for obscenely - * large strings. - */ - h->left = h->left + len + CHUNK_SPARE; - h->size = h->size + len + CHUNK_SPARE; - newbuf = realloc(h->base, h->size); - if (newbuf == NULL) { - free(h->base); - h->base = NULL; - return (-1); - } else - h->base = newbuf; - } - /* "write" it */ - (void)memcpy(h->base + h->size - h->left, buf, (size_t)len); - h->left -= len; - return (len); -} - - -int -vasprintf(str, fmt, ap) - char **str; - const char *fmt; - va_list ap; -{ - int ret; - FILE *f; - struct bufcookie h; - - h.base = malloc(CHUNK_SPARE); - if (h.base == NULL) - return (-1); - h.size = CHUNK_SPARE; - h.left = CHUNK_SPARE; - - f = funopen(&h, NULL, writehook, NULL, NULL); - if (f == NULL) { - free(h.base); - return (-1); - } - ret = vfprintf(f, fmt, ap); - fclose(f); - - /* - * clean up the wreckage. Did writehook fail or did something else - * in stdio explode perhaps? - */ - if (h.base == NULL) /* realloc failed in writehook */ - return (-1); - if (ret < 0) { /* something else? */ - free(h.base); - return (-1); - } - - /* - * At this point, we have a non-null terminated string in a - * buffer. There may not be enough room to null-terminate it - * (h.left == 0) - if realloc failes to expand it, it's fatal. - * If we were merely trying to shrink the buffer, a realloc failure - * is not [yet] fatal. Note that when realloc returns NULL, - * the original buffer is left allocated and valid. - */ - if (h.left == 1) /* exact fit, do not realloc */ - *str = h.base; - else { - *str = realloc(h.base, (size_t)(h.size - h.left + 1)); - if (*str == NULL) { - /* failed to expand? - fatal */ - if (h.left == 0) { - free(h.base); - return (-1); - } - *str = h.base; /* use oversize original buffer */ - } - } - (*str)[h.size - h.left] = '\0'; - return (ret); -} diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c deleted file mode 100644 index dd3f743..0000000 --- a/lib/libc/stdio/vfprintf.c +++ /dev/null @@ -1,1284 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id: vfprintf.c,v 1.16 1997/12/25 00:32:17 ache Exp $"; -#endif /* LIBC_SCCS and not lint */ - -/* - * Actual printf innards. - * - * This code is large and complicated... - */ - -#include <sys/types.h> - -#include <limits.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -#include "local.h" -#include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -/* Define FLOATING_POINT to get floating point. */ -#define FLOATING_POINT - -static int __sprint __P((FILE *, struct __suio *)); -static int __sbprintf __P((FILE *, const char *, va_list)); -static char * __ultoa __P((u_long, char *, int, int, char *)); -static char * __uqtoa __P((u_quad_t, char *, int, int, char *)); -static void __find_arguments __P((const char *, va_list, void ***)); -static void __grow_type_table __P((int, unsigned char **, int *)); - -/* - * Flush out all the vectors defined by the given uio, - * then reset it so that it can be reused. - */ -static int -__sprint(fp, uio) - FILE *fp; - register struct __suio *uio; -{ - register int err; - - if (uio->uio_resid == 0) { - uio->uio_iovcnt = 0; - return (0); - } - err = __sfvwrite(fp, uio); - uio->uio_resid = 0; - uio->uio_iovcnt = 0; - return (err); -} - -/* - * Helper function for `fprintf to unbuffered unix file': creates a - * temporary buffer. We only work on write-only files; this avoids - * worries about ungetc buffers and so forth. - */ -static int -__sbprintf(fp, fmt, ap) - register FILE *fp; - const char *fmt; - va_list ap; -{ - int ret; - FILE fake; - unsigned char buf[BUFSIZ]; - - /* copy the important variables */ - fake._flags = fp->_flags & ~__SNBF; - fake._file = fp->_file; - fake._cookie = fp->_cookie; - fake._write = fp->_write; - - /* set up the buffer */ - fake._bf._base = fake._p = buf; - fake._bf._size = fake._w = sizeof(buf); - fake._lbfsize = 0; /* not actually used, but Just In Case */ - - /* do the work, then copy any error status */ - ret = vfprintf(&fake, fmt, ap); - if (ret >= 0 && fflush(&fake)) - ret = EOF; - if (fake._flags & __SERR) - fp->_flags |= __SERR; - return (ret); -} - -/* - * Macros for converting digits to letters and vice versa - */ -#define to_digit(c) ((c) - '0') -#define is_digit(c) ((unsigned)to_digit(c) <= 9) -#define to_char(n) ((n) + '0') - -/* - * Convert an unsigned long to ASCII for printf purposes, returning - * a pointer to the first character of the string representation. - * Octal numbers can be forced to have a leading zero; hex numbers - * use the given digits. - */ -static char * -__ultoa(val, endp, base, octzero, xdigs) - register u_long val; - char *endp; - int base, octzero; - char *xdigs; -{ - register char *cp = endp; - register long sval; - - /* - * Handle the three cases separately, in the hope of getting - * better/faster code. - */ - switch (base) { - case 10: - if (val < 10) { /* many numbers are 1 digit */ - *--cp = to_char(val); - return (cp); - } - /* - * On many machines, unsigned arithmetic is harder than - * signed arithmetic, so we do at most one unsigned mod and - * divide; this is sufficient to reduce the range of - * the incoming value to where signed arithmetic works. - */ - if (val > LONG_MAX) { - *--cp = to_char(val % 10); - sval = val / 10; - } else - sval = val; - do { - *--cp = to_char(sval % 10); - sval /= 10; - } while (sval != 0); - break; - - case 8: - do { - *--cp = to_char(val & 7); - val >>= 3; - } while (val); - if (octzero && *cp != '0') - *--cp = '0'; - break; - - case 16: - do { - *--cp = xdigs[val & 15]; - val >>= 4; - } while (val); - break; - - default: /* oops */ - abort(); - } - return (cp); -} - -/* Identical to __ultoa, but for quads. */ -static char * -__uqtoa(val, endp, base, octzero, xdigs) - register u_quad_t val; - char *endp; - int base, octzero; - char *xdigs; -{ - register char *cp = endp; - register quad_t sval; - - /* quick test for small values; __ultoa is typically much faster */ - /* (perhaps instead we should run until small, then call __ultoa?) */ - if (val <= ULONG_MAX) - return (__ultoa((u_long)val, endp, base, octzero, xdigs)); - switch (base) { - case 10: - if (val < 10) { - *--cp = to_char(val % 10); - return (cp); - } - if (val > QUAD_MAX) { - *--cp = to_char(val % 10); - sval = val / 10; - } else - sval = val; - do { - *--cp = to_char(sval % 10); - sval /= 10; - } while (sval != 0); - break; - - case 8: - do { - *--cp = to_char(val & 7); - val >>= 3; - } while (val); - if (octzero && *cp != '0') - *--cp = '0'; - break; - - case 16: - do { - *--cp = xdigs[val & 15]; - val >>= 4; - } while (val); - break; - - default: - abort(); - } - return (cp); -} - -#ifdef FLOATING_POINT -#include <math.h> -#include "floatio.h" - -#define BUF (MAXEXP+MAXFRACT+1) /* + decimal point */ -#define DEFPREC 6 - -static char *cvt __P((double, int, int, char *, int *, int, int *)); -static int exponent __P((char *, int, int)); - -#else /* no FLOATING_POINT */ - -#define BUF 68 - -#endif /* FLOATING_POINT */ - -#define STATIC_ARG_TBL_SIZE 8 /* Size of static argument table. */ - -/* - * Flags used during conversion. - */ -#define ALT 0x001 /* alternate form */ -#define HEXPREFIX 0x002 /* add 0x or 0X prefix */ -#define LADJUST 0x004 /* left adjustment */ -#define LONGDBL 0x008 /* long double */ -#define LONGINT 0x010 /* long integer */ -#define QUADINT 0x020 /* quad integer */ -#define SHORTINT 0x040 /* short integer */ -#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ -#define FPT 0x100 /* Floating point number */ -int -vfprintf(fp, fmt0, ap) - FILE *fp; - const char *fmt0; - va_list ap; -{ - register char *fmt; /* format string */ - register int ch; /* character from fmt */ - register int n, n2; /* handy integer (short term usage) */ - register char *cp; /* handy char pointer (short term usage) */ - register struct __siov *iovp;/* for PRINT macro */ - register int flags; /* flags as above */ - int ret; /* return value accumulator */ - int width; /* width from format (%8d), or 0 */ - int prec; /* precision from format (%.3d), or -1 */ - char sign; /* sign prefix (' ', '+', '-', or \0) */ -#ifdef FLOATING_POINT - char softsign; /* temporary negative sign for floats */ - double _double; /* double precision arguments %[eEfgG] */ - int expt; /* integer value of exponent */ - int expsize; /* character count for expstr */ - int ndig; /* actual number of digits returned by cvt */ - char expstr[7]; /* buffer for exponent string */ -#endif - u_long ulval; /* integer arguments %[diouxX] */ - u_quad_t uqval; /* %q integers */ - int base; /* base for [diouxX] conversion */ - int dprec; /* a copy of prec if [diouxX], 0 otherwise */ - int realsz; /* field size expanded by dprec, sign, etc */ - int size; /* size of converted field or string */ - int prsize; /* max size of printed field */ - char *xdigs; /* digits for [xX] conversion */ -#define NIOV 8 - struct __suio uio; /* output information: summary */ - struct __siov iov[NIOV];/* ... and individual io vectors */ - char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ - char ox[2]; /* space for 0x hex-prefix */ - void **argtable; /* args, built due to positional arg */ - void *statargtable [STATIC_ARG_TBL_SIZE]; - int nextarg; /* 1-based argument index */ - va_list orgap; /* original argument pointer */ - - /* - * Choose PADSIZE to trade efficiency vs. size. If larger printf - * fields occur frequently, increase PADSIZE and make the initialisers - * below longer. - */ -#define PADSIZE 16 /* pad chunk size */ - static char blanks[PADSIZE] = - {' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}; - static char zeroes[PADSIZE] = - {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}; - - /* - * BEWARE, these `goto error' on error, and PAD uses `n'. - */ -#define PRINT(ptr, len) { \ - iovp->iov_base = (ptr); \ - iovp->iov_len = (len); \ - uio.uio_resid += (len); \ - iovp++; \ - if (++uio.uio_iovcnt >= NIOV) { \ - if (__sprint(fp, &uio)) \ - goto error; \ - iovp = iov; \ - } \ -} -#define PAD(howmany, with) { \ - if ((n = (howmany)) > 0) { \ - while (n > PADSIZE) { \ - PRINT(with, PADSIZE); \ - n -= PADSIZE; \ - } \ - PRINT(with, n); \ - } \ -} -#define FLUSH() { \ - if (uio.uio_resid && __sprint(fp, &uio)) \ - goto error; \ - uio.uio_iovcnt = 0; \ - iovp = iov; \ -} - - /* - * Get the argument indexed by nextarg. If the argument table is - * built, use it to get the argument. If its not, get the next - * argument (and arguments must be gotten sequentially). - */ -#define GETARG(type) \ - ((argtable != NULL) ? *((type*)(argtable[nextarg++])) : \ - (nextarg++, va_arg(ap, type))) - - /* - * To extend shorts properly, we need both signed and unsigned - * argument extraction methods. - */ -#define SARG() \ - (flags&LONGINT ? GETARG(long) : \ - flags&SHORTINT ? (long)(short)GETARG(int) : \ - (long)GETARG(int)) -#define UARG() \ - (flags&LONGINT ? GETARG(u_long) : \ - flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \ - (u_long)GETARG(u_int)) - - /* - * Get * arguments, including the form *nn$. Preserve the nextarg - * that the argument can be gotten once the type is determined. - */ -#define GETASTER(val) \ - n2 = 0; \ - cp = fmt; \ - while (is_digit(*cp)) { \ - n2 = 10 * n2 + to_digit(*cp); \ - cp++; \ - } \ - if (*cp == '$') { \ - int hold = nextarg; \ - if (argtable == NULL) { \ - argtable = statargtable; \ - __find_arguments (fmt0, orgap, &argtable); \ - } \ - nextarg = n2; \ - val = GETARG (int); \ - nextarg = hold; \ - fmt = ++cp; \ - } else { \ - val = GETARG (int); \ - } - - -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ - if (cantwrite(fp)) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (EOF); - } - - /* optimise fprintf(stderr) (and other unbuffered Unix files) */ - if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && - fp->_file >= 0) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (__sbprintf(fp, fmt0, ap)); - } - - fmt = (char *)fmt0; - argtable = NULL; - nextarg = 1; - orgap = ap; - uio.uio_iov = iovp = iov; - uio.uio_resid = 0; - uio.uio_iovcnt = 0; - ret = 0; - - /* - * Scan the format for conversions (`%' character). - */ - for (;;) { - for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) - /* void */; - if ((n = fmt - cp) != 0) { - if ((unsigned)ret + n > INT_MAX) { - ret = EOF; - goto error; - } - PRINT(cp, n); - ret += n; - } - if (ch == '\0') - goto done; - fmt++; /* skip over '%' */ - - flags = 0; - dprec = 0; - width = 0; - prec = -1; - sign = '\0'; - -rflag: ch = *fmt++; -reswitch: switch (ch) { - case ' ': - /* - * ``If the space and + flags both appear, the space - * flag will be ignored.'' - * -- ANSI X3J11 - */ - if (!sign) - sign = ' '; - goto rflag; - case '#': - flags |= ALT; - goto rflag; - case '*': - /* - * ``A negative field width argument is taken as a - * - flag followed by a positive field width.'' - * -- ANSI X3J11 - * They don't exclude field widths read from args. - */ - GETASTER (width); - if (width >= 0) - goto rflag; - width = -width; - /* FALLTHROUGH */ - case '-': - flags |= LADJUST; - goto rflag; - case '+': - sign = '+'; - goto rflag; - case '.': - if ((ch = *fmt++) == '*') { - GETASTER (n); - prec = n < 0 ? -1 : n; - goto rflag; - } - n = 0; - while (is_digit(ch)) { - n = 10 * n + to_digit(ch); - ch = *fmt++; - } - prec = n < 0 ? -1 : n; - goto reswitch; - case '0': - /* - * ``Note that 0 is taken as a flag, not as the - * beginning of a field width.'' - * -- ANSI X3J11 - */ - flags |= ZEROPAD; - goto rflag; - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = 0; - do { - n = 10 * n + to_digit(ch); - ch = *fmt++; - } while (is_digit(ch)); - if (ch == '$') { - nextarg = n; - if (argtable == NULL) { - argtable = statargtable; - __find_arguments (fmt0, orgap, - &argtable); - } - goto rflag; - } - width = n; - goto reswitch; -#ifdef FLOATING_POINT - case 'L': - flags |= LONGDBL; - goto rflag; -#endif - case 'h': - flags |= SHORTINT; - goto rflag; - case 'l': - flags |= LONGINT; - goto rflag; - case 'q': - flags |= QUADINT; - goto rflag; - case 'c': - *(cp = buf) = GETARG(int); - size = 1; - sign = '\0'; - break; - case 'D': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'd': - case 'i': - if (flags & QUADINT) { - uqval = GETARG(quad_t); - if ((quad_t)uqval < 0) { - uqval = -uqval; - sign = '-'; - } - } else { - ulval = SARG(); - if ((long)ulval < 0) { - ulval = -ulval; - sign = '-'; - } - } - base = 10; - goto number; -#ifdef FLOATING_POINT - case 'e': - case 'E': - case 'f': - goto fp_begin; - case 'g': - case 'G': - if (prec == 0) - prec = 1; -fp_begin: if (prec == -1) - prec = DEFPREC; - if (flags & LONGDBL) - /* XXX this loses precision. */ - _double = (double)GETARG(long double); - else - _double = GETARG(double); - /* do this before tricky precision changes */ - if (isinf(_double)) { - if (_double < 0) - sign = '-'; - cp = "Inf"; - size = 3; - break; - } - if (isnan(_double)) { - cp = "NaN"; - size = 3; - break; - } - flags |= FPT; - cp = cvt(_double, prec, flags, &softsign, - &expt, ch, &ndig); - if (ch == 'g' || ch == 'G') { - if (expt <= -4 || expt > prec) - ch = (ch == 'g') ? 'e' : 'E'; - else - ch = 'g'; - } - if (ch <= 'e') { /* 'e' or 'E' fmt */ - --expt; - expsize = exponent(expstr, expt, ch); - size = expsize + ndig; - if (ndig > 1 || flags & ALT) - ++size; - } else if (ch == 'f') { /* f fmt */ - if (expt > 0) { - size = expt; - if (prec || flags & ALT) - size += prec + 1; - } else /* "0.X" */ - size = prec + 2; - } else if (expt >= ndig) { /* fixed g fmt */ - size = expt; - if (flags & ALT) - ++size; - } else - size = ndig + (expt > 0 ? - 1 : 2 - expt); - - if (softsign) - sign = '-'; - break; -#endif /* FLOATING_POINT */ - case 'n': - if (flags & QUADINT) - *GETARG(quad_t *) = ret; - else if (flags & LONGINT) - *GETARG(long *) = ret; - else if (flags & SHORTINT) - *GETARG(short *) = ret; - else - *GETARG(int *) = ret; - continue; /* no output */ - case 'O': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'o': - if (flags & QUADINT) - uqval = GETARG(u_quad_t); - else - ulval = UARG(); - base = 8; - goto nosign; - case 'p': - /* - * ``The argument shall be a pointer to void. The - * value of the pointer is converted to a sequence - * of printable characters, in an implementation- - * defined manner.'' - * -- ANSI X3J11 - */ - ulval = (u_long)GETARG(void *); - base = 16; - xdigs = "0123456789abcdef"; - flags = (flags & ~QUADINT) | HEXPREFIX; - ch = 'x'; - goto nosign; - case 's': - if ((cp = GETARG(char *)) == NULL) - cp = "(null)"; - if (prec >= 0) { - /* - * can't use strlen; can only look for the - * NUL in the first `prec' characters, and - * strlen() will go further. - */ - char *p = memchr(cp, 0, (size_t)prec); - - if (p != NULL) { - size = p - cp; - if (size > prec) - size = prec; - } else - size = prec; - } else - size = strlen(cp); - sign = '\0'; - break; - case 'U': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'u': - if (flags & QUADINT) - uqval = GETARG(u_quad_t); - else - ulval = UARG(); - base = 10; - goto nosign; - case 'X': - xdigs = "0123456789ABCDEF"; - goto hex; - case 'x': - xdigs = "0123456789abcdef"; -hex: if (flags & QUADINT) - uqval = GETARG(u_quad_t); - else - ulval = UARG(); - base = 16; - /* leading 0x/X only if non-zero */ - if (flags & ALT && - (flags & QUADINT ? uqval != 0 : ulval != 0)) - flags |= HEXPREFIX; - - /* unsigned conversions */ -nosign: sign = '\0'; - /* - * ``... diouXx conversions ... if a precision is - * specified, the 0 flag will be ignored.'' - * -- ANSI X3J11 - */ -number: if ((dprec = prec) >= 0) - flags &= ~ZEROPAD; - - /* - * ``The result of converting a zero value with an - * explicit precision of zero is no characters.'' - * -- ANSI X3J11 - */ - cp = buf + BUF; - if (flags & QUADINT) { - if (uqval != 0 || prec != 0) - cp = __uqtoa(uqval, cp, base, - flags & ALT, xdigs); - } else { - if (ulval != 0 || prec != 0) - cp = __ultoa(ulval, cp, base, - flags & ALT, xdigs); - } - size = buf + BUF - cp; - break; - default: /* "%?" prints ?, unless ? is NUL */ - if (ch == '\0') - goto done; - /* pretend it was %c with argument ch */ - cp = buf; - *cp = ch; - size = 1; - sign = '\0'; - break; - } - - /* - * All reasonable formats wind up here. At this point, `cp' - * points to a string which (if not flags&LADJUST) should be - * padded out to `width' places. If flags&ZEROPAD, it should - * first be prefixed by any sign or other prefix; otherwise, - * it should be blank padded before the prefix is emitted. - * After any left-hand padding and prefixing, emit zeroes - * required by a decimal [diouxX] precision, then print the - * string proper, then emit zeroes required by any leftover - * floating precision; finally, if LADJUST, pad with blanks. - * - * Compute actual size, so we know how much to pad. - * size excludes decimal prec; realsz includes it. - */ - realsz = dprec > size ? dprec : size; - if (sign) - realsz++; - else if (flags & HEXPREFIX) - realsz += 2; - - prsize = width > realsz ? width : realsz; - if ((unsigned)ret + prsize > INT_MAX) { - ret = EOF; - goto error; - } - - /* right-adjusting blank padding */ - if ((flags & (LADJUST|ZEROPAD)) == 0) - PAD(width - realsz, blanks); - - /* prefix */ - if (sign) { - PRINT(&sign, 1); - } else if (flags & HEXPREFIX) { - ox[0] = '0'; - ox[1] = ch; - PRINT(ox, 2); - } - - /* right-adjusting zero padding */ - if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) - PAD(width - realsz, zeroes); - - /* leading zeroes from decimal precision */ - PAD(dprec - size, zeroes); - - /* the string or number proper */ -#ifdef FLOATING_POINT - if ((flags & FPT) == 0) { - PRINT(cp, size); - } else { /* glue together f_p fragments */ - if (ch >= 'f') { /* 'f' or 'g' */ - if (_double == 0) { - /* kludge for __dtoa irregularity */ - if (expt >= ndig && - (flags & ALT) == 0) { - PRINT("0", 1); - } else { - PRINT("0.", 2); - PAD(ndig - 1, zeroes); - } - } else if (expt <= 0) { - PRINT("0.", 2); - PAD(-expt, zeroes); - PRINT(cp, ndig); - } else if (expt >= ndig) { - PRINT(cp, ndig); - PAD(expt - ndig, zeroes); - if (flags & ALT) - PRINT(".", 1); - } else { - PRINT(cp, expt); - cp += expt; - PRINT(".", 1); - PRINT(cp, ndig-expt); - } - } else { /* 'e' or 'E' */ - if (ndig > 1 || flags & ALT) { - ox[0] = *cp++; - ox[1] = '.'; - PRINT(ox, 2); - if (_double) { - PRINT(cp, ndig-1); - } else /* 0.[0..] */ - /* __dtoa irregularity */ - PAD(ndig - 1, zeroes); - } else /* XeYYY */ - PRINT(cp, 1); - PRINT(expstr, expsize); - } - } -#else - PRINT(cp, size); -#endif - /* left-adjusting padding (always blank) */ - if (flags & LADJUST) - PAD(width - realsz, blanks); - - /* finally, adjust ret */ - ret += prsize; - - FLUSH(); /* copy out the I/O vectors */ - } -done: - FLUSH(); -error: - if (__sferror(fp)) - ret = EOF; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - if ((argtable != NULL) && (argtable != statargtable)) - free (argtable); - return (ret); - /* NOTREACHED */ -} - -/* - * Type ids for argument type table. - */ -#define T_UNUSED 0 -#define T_SHORT 1 -#define T_U_SHORT 2 -#define TP_SHORT 3 -#define T_INT 4 -#define T_U_INT 5 -#define TP_INT 6 -#define T_LONG 7 -#define T_U_LONG 8 -#define TP_LONG 9 -#define T_QUAD 10 -#define T_U_QUAD 11 -#define TP_QUAD 12 -#define T_DOUBLE 13 -#define T_LONG_DOUBLE 14 -#define TP_CHAR 15 -#define TP_VOID 16 - -/* - * Find all arguments when a positional parameter is encountered. Returns a - * table, indexed by argument number, of pointers to each arguments. The - * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries. - * It will be replaces with a malloc-ed on if it overflows. - */ -static void -__find_arguments (fmt0, ap, argtable) - const char *fmt0; - va_list ap; - void ***argtable; -{ - register char *fmt; /* format string */ - register int ch; /* character from fmt */ - register int n, n2; /* handy integer (short term usage) */ - register char *cp; /* handy char pointer (short term usage) */ - register int flags; /* flags as above */ - int width; /* width from format (%8d), or 0 */ - unsigned char *typetable; /* table of types */ - unsigned char stattypetable [STATIC_ARG_TBL_SIZE]; - int tablesize; /* current size of type table */ - int tablemax; /* largest used index in table */ - int nextarg; /* 1-based argument index */ - - /* - * Add an argument type to the table, expanding if necessary. - */ -#define ADDTYPE(type) \ - ((nextarg >= tablesize) ? \ - __grow_type_table(nextarg, &typetable, &tablesize) : 0, \ - typetable[nextarg++] = type, \ - (nextarg > tablemax) ? tablemax = nextarg : 0) - -#define ADDSARG() \ - ((flags&LONGINT) ? ADDTYPE(T_LONG) : \ - ((flags&SHORTINT) ? ADDTYPE(T_SHORT) : ADDTYPE(T_INT))) - -#define ADDUARG() \ - ((flags&LONGINT) ? ADDTYPE(T_U_LONG) : \ - ((flags&SHORTINT) ? ADDTYPE(T_U_SHORT) : ADDTYPE(T_U_INT))) - - /* - * Add * arguments to the type array. - */ -#define ADDASTER() \ - n2 = 0; \ - cp = fmt; \ - while (is_digit(*cp)) { \ - n2 = 10 * n2 + to_digit(*cp); \ - cp++; \ - } \ - if (*cp == '$') { \ - int hold = nextarg; \ - nextarg = n2; \ - ADDTYPE (T_INT); \ - nextarg = hold; \ - fmt = ++cp; \ - } else { \ - ADDTYPE (T_INT); \ - } - fmt = (char *)fmt0; - typetable = stattypetable; - tablesize = STATIC_ARG_TBL_SIZE; - tablemax = 0; - nextarg = 1; - memset (typetable, T_UNUSED, STATIC_ARG_TBL_SIZE); - - /* - * Scan the format for conversions (`%' character). - */ - for (;;) { - for (cp = fmt; (ch = *fmt) != '\0' && ch != '%'; fmt++) - /* void */; - if (ch == '\0') - goto done; - fmt++; /* skip over '%' */ - - flags = 0; - width = 0; - -rflag: ch = *fmt++; -reswitch: switch (ch) { - case ' ': - case '#': - goto rflag; - case '*': - ADDASTER (); - goto rflag; - case '-': - case '+': - goto rflag; - case '.': - if ((ch = *fmt++) == '*') { - ADDASTER (); - goto rflag; - } - while (is_digit(ch)) { - ch = *fmt++; - } - goto reswitch; - case '0': - goto rflag; - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - n = 0; - do { - n = 10 * n + to_digit(ch); - ch = *fmt++; - } while (is_digit(ch)); - if (ch == '$') { - nextarg = n; - goto rflag; - } - width = n; - goto reswitch; -#ifdef FLOATING_POINT - case 'L': - flags |= LONGDBL; - goto rflag; -#endif - case 'h': - flags |= SHORTINT; - goto rflag; - case 'l': - flags |= LONGINT; - goto rflag; - case 'q': - flags |= QUADINT; - goto rflag; - case 'c': - ADDTYPE(T_INT); - break; - case 'D': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'd': - case 'i': - if (flags & QUADINT) { - ADDTYPE(T_QUAD); - } else { - ADDSARG(); - } - break; -#ifdef FLOATING_POINT - case 'e': - case 'E': - case 'f': - case 'g': - case 'G': - if (flags & LONGDBL) - ADDTYPE(T_LONG_DOUBLE); - else - ADDTYPE(T_DOUBLE); - break; -#endif /* FLOATING_POINT */ - case 'n': - if (flags & QUADINT) - ADDTYPE(TP_QUAD); - else if (flags & LONGINT) - ADDTYPE(TP_LONG); - else if (flags & SHORTINT) - ADDTYPE(TP_SHORT); - else - ADDTYPE(TP_INT); - continue; /* no output */ - case 'O': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'o': - if (flags & QUADINT) - ADDTYPE(T_U_QUAD); - else - ADDUARG(); - break; - case 'p': - ADDTYPE(TP_VOID); - break; - case 's': - ADDTYPE(TP_CHAR); - break; - case 'U': - flags |= LONGINT; - /*FALLTHROUGH*/ - case 'u': - if (flags & QUADINT) - ADDTYPE(T_U_QUAD); - else - ADDUARG(); - break; - case 'X': - case 'x': - if (flags & QUADINT) - ADDTYPE(T_U_QUAD); - else - ADDUARG(); - break; - default: /* "%?" prints ?, unless ? is NUL */ - if (ch == '\0') - goto done; - break; - } - } -done: - /* - * Build the argument table. - */ - if (tablemax >= STATIC_ARG_TBL_SIZE) { - *argtable = (void **) - malloc (sizeof (void *) * (tablemax + 1)); - } - - (*argtable) [0] = NULL; - for (n = 1; n <= tablemax; n++) { - (*argtable) [n] = ap; - switch (typetable [n]) { - case T_UNUSED: - (void) va_arg (ap, int); - break; - case T_SHORT: - (void) va_arg (ap, int); - break; - case T_U_SHORT: - (void) va_arg (ap, int); - break; - case TP_SHORT: - (void) va_arg (ap, short *); - break; - case T_INT: - (void) va_arg (ap, int); - break; - case T_U_INT: - (void) va_arg (ap, unsigned int); - break; - case TP_INT: - (void) va_arg (ap, int *); - break; - case T_LONG: - (void) va_arg (ap, long); - break; - case T_U_LONG: - (void) va_arg (ap, unsigned long); - break; - case TP_LONG: - (void) va_arg (ap, long *); - break; - case T_QUAD: - (void) va_arg (ap, quad_t); - break; - case T_U_QUAD: - (void) va_arg (ap, u_quad_t); - break; - case TP_QUAD: - (void) va_arg (ap, quad_t *); - break; - case T_DOUBLE: - (void) va_arg (ap, double); - break; - case T_LONG_DOUBLE: - (void) va_arg (ap, long double); - break; - case TP_CHAR: - (void) va_arg (ap, char *); - break; - case TP_VOID: - (void) va_arg (ap, void *); - break; - } - } - - if ((typetable != NULL) && (typetable != stattypetable)) - free (typetable); -} - -/* - * Increase the size of the type table. - */ -static void -__grow_type_table (nextarg, typetable, tablesize) - int nextarg; - unsigned char **typetable; - int *tablesize; -{ - unsigned char *oldtable = *typetable; - int newsize = *tablesize * 2; - - if (*tablesize == STATIC_ARG_TBL_SIZE) { - *typetable = (unsigned char *) - malloc (sizeof (unsigned char) * newsize); - bcopy (oldtable, *typetable, *tablesize); - } else { - *typetable = (unsigned char *) - realloc (typetable, sizeof (unsigned char) * newsize); - - } - memset (&typetable [*tablesize], T_UNUSED, (newsize - *tablesize)); - - *tablesize = newsize; -} - - -#ifdef FLOATING_POINT - -extern char *__dtoa __P((double, int, int, int *, int *, char **)); - -static char * -cvt(value, ndigits, flags, sign, decpt, ch, length) - double value; - int ndigits, flags, *decpt, ch, *length; - char *sign; -{ - int mode, dsgn; - char *digits, *bp, *rve; - - if (ch == 'f') - mode = 3; /* ndigits after the decimal point */ - else { - /* - * To obtain ndigits after the decimal point for the 'e' - * and 'E' formats, round to ndigits + 1 significant - * figures. - */ - if (ch == 'e' || ch == 'E') - ndigits++; - mode = 2; /* ndigits significant digits */ - } - if (value < 0) { - value = -value; - *sign = '-'; - } else - *sign = '\000'; - digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve); - if ((ch != 'g' && ch != 'G') || flags & ALT) { - /* print trailing zeros */ - bp = digits + ndigits; - if (ch == 'f') { - if (*digits == '0' && value) - *decpt = -ndigits + 1; - bp += *decpt; - } - if (value == 0) /* kludge for __dtoa irregularity */ - rve = bp; - while (rve < bp) - *rve++ = '0'; - } - *length = rve - digits; - return (digits); -} - -static int -exponent(p0, exp, fmtch) - char *p0; - int exp, fmtch; -{ - register char *p, *t; - char expbuf[MAXEXP]; - - p = p0; - *p++ = fmtch; - if (exp < 0) { - exp = -exp; - *p++ = '-'; - } - else - *p++ = '+'; - t = expbuf + MAXEXP; - if (exp > 9) { - do { - *--t = to_char(exp % 10); - } while ((exp /= 10) > 9); - *--t = to_char(exp); - for (; t < expbuf + MAXEXP; *p++ = *t++); - } - else { - *p++ = '0'; - *p++ = to_char(exp); - } - return (p - p0); -} -#endif /* FLOATING_POINT */ diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c deleted file mode 100644 index ba4be5c..0000000 --- a/lib/libc/stdio/vfscanf.c +++ /dev/null @@ -1,791 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)vfscanf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id: vfscanf.c,v 1.11 1997/07/01 17:46:39 jkh Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <stdlib.h> -#include <ctype.h> -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif -#include <string.h> - -#include "collate.h" -#include "local.h" - -#define FLOATING_POINT - -#include "floatio.h" -#define BUF 513 /* Maximum length of numeric string. */ - -/* - * Flags used during conversion. - */ -#define LONG 0x01 /* l: long or double */ -#define LONGDBL 0x02 /* L: long double */ -#define SHORT 0x04 /* h: short */ -#define SUPPRESS 0x08 /* suppress assignment */ -#define POINTER 0x10 /* weird %p pointer (`fake hex') */ -#define NOSKIP 0x20 /* do not skip blanks */ -#define QUAD 0x400 - -/* - * The following are used in numeric conversions only: - * SIGNOK, NDIGITS, DPTOK, and EXPOK are for floating point; - * SIGNOK, NDIGITS, PFXOK, and NZDIGITS are for integral. - */ -#define SIGNOK 0x40 /* +/- is (still) legal */ -#define NDIGITS 0x80 /* no digits detected */ - -#define DPTOK 0x100 /* (float) decimal point is still legal */ -#define EXPOK 0x200 /* (float) exponent (e+3, etc) still legal */ - -#define PFXOK 0x100 /* 0x prefix is (still) legal */ -#define NZDIGITS 0x200 /* no zero digits detected */ - -/* - * Conversion types. - */ -#define CT_CHAR 0 /* %c conversion */ -#define CT_CCL 1 /* %[...] conversion */ -#define CT_STRING 2 /* %s conversion */ -#define CT_INT 3 /* integer, i.e., strtoq or strtouq */ -#define CT_FLOAT 4 /* floating, i.e., strtod */ - -#define u_char unsigned char -#define u_long unsigned long - -static u_char *__sccl(char *, u_char *); - -/* - * vfscanf - */ -int -__svfscanf(fp, fmt0, ap) - register FILE *fp; - char const *fmt0; - va_list ap; -{ - register u_char *fmt = (u_char *)fmt0; - register int c; /* character from format, or conversion */ - register size_t width; /* field width, or 0 */ - register char *p; /* points into all kinds of strings */ - register int n; /* handy integer */ - register int flags; /* flags as defined above */ - register char *p0; /* saves original value of p when necessary */ - int nassigned; /* number of fields assigned */ - int nconversions; /* number of conversions */ - int nread; /* number of characters consumed from fp */ - int base; /* base argument to strtoq/strtouq */ - u_quad_t(*ccfn)(); /* conversion function (strtoq/strtouq) */ - char ccltab[256]; /* character class table for %[...] */ - char buf[BUF]; /* buffer for numeric conversions */ - - /* `basefix' is used to avoid `if' tests in the integer scanner */ - static short basefix[17] = - { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; - - nassigned = 0; - nconversions = 0; - nread = 0; - base = 0; /* XXX just to keep gcc happy */ - ccfn = NULL; /* XXX just to keep gcc happy */ - for (;;) { - c = *fmt++; - if (c == 0) - return (nassigned); - if (isspace(c)) { - for (;;) { - if (fp->_r <= 0 && __srefill(fp)) - goto input_failure; - if (!isspace(*fp->_p)) - break; - nread++, fp->_r--, fp->_p++; - } - continue; - } - if (c != '%') - goto literal; - width = 0; - flags = 0; - /* - * switch on the format. continue if done; - * break once format type is derived. - */ -again: c = *fmt++; - switch (c) { - case '%': -literal: - if (fp->_r <= 0 && __srefill(fp)) - goto input_failure; - if (*fp->_p != c) - goto match_failure; - fp->_r--, fp->_p++; - nread++; - continue; - - case '*': - flags |= SUPPRESS; - goto again; - case 'l': - flags |= LONG; - goto again; - case 'q': - flags |= QUAD; - goto again; - case 'L': - flags |= LONGDBL; - goto again; - case 'h': - flags |= SHORT; - goto again; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - width = width * 10 + c - '0'; - goto again; - - /* - * Conversions. - * Those marked `compat' are for 4.[123]BSD compatibility. - * - * (According to ANSI, E and X formats are supposed - * to the same as e and x. Sorry about that.) - */ - case 'D': /* compat */ - flags |= LONG; - /* FALLTHROUGH */ - case 'd': - c = CT_INT; - ccfn = (u_quad_t (*)())strtoq; - base = 10; - break; - - case 'i': - c = CT_INT; - ccfn = (u_quad_t (*)())strtoq; - base = 0; - break; - - case 'O': /* compat */ - flags |= LONG; - /* FALLTHROUGH */ - case 'o': - c = CT_INT; - ccfn = strtouq; - base = 8; - break; - - case 'u': - c = CT_INT; - ccfn = strtouq; - base = 10; - break; - - case 'X': /* compat XXX */ - flags |= LONG; - /* FALLTHROUGH */ - case 'x': - flags |= PFXOK; /* enable 0x prefixing */ - c = CT_INT; - ccfn = strtouq; - base = 16; - break; - -#ifdef FLOATING_POINT - case 'E': /* compat XXX */ - case 'F': /* compat */ - flags |= LONG; - /* FALLTHROUGH */ - case 'e': case 'f': case 'g': - c = CT_FLOAT; - break; -#endif - - case 's': - c = CT_STRING; - break; - - case '[': - fmt = __sccl(ccltab, fmt); - flags |= NOSKIP; - c = CT_CCL; - break; - - case 'c': - flags |= NOSKIP; - c = CT_CHAR; - break; - - case 'p': /* pointer format is like hex */ - flags |= POINTER | PFXOK; - c = CT_INT; - ccfn = strtouq; - base = 16; - break; - - case 'n': - nconversions++; - if (flags & SUPPRESS) /* ??? */ - continue; - if (flags & SHORT) - *va_arg(ap, short *) = nread; - else if (flags & LONG) - *va_arg(ap, long *) = nread; - else if (flags & QUAD) - *va_arg(ap, quad_t *) = nread; - else - *va_arg(ap, int *) = nread; - continue; - - /* - * Disgusting backwards compatibility hacks. XXX - */ - case '\0': /* compat */ - return (EOF); - - default: /* compat */ - if (isupper(c)) - flags |= LONG; - c = CT_INT; - ccfn = (u_quad_t (*)())strtoq; - base = 10; - break; - } - - /* - * We have a conversion that requires input. - */ - if (fp->_r <= 0 && __srefill(fp)) - goto input_failure; - - /* - * Consume leading white space, except for formats - * that suppress this. - */ - if ((flags & NOSKIP) == 0) { - while (isspace(*fp->_p)) { - nread++; - if (--fp->_r > 0) - fp->_p++; - else if (__srefill(fp)) - goto input_failure; - } - /* - * Note that there is at least one character in - * the buffer, so conversions that do not set NOSKIP - * ca no longer result in an input failure. - */ - } - - /* - * Do the conversion. - */ - switch (c) { - - case CT_CHAR: - /* scan arbitrary characters (sets NOSKIP) */ - if (width == 0) - width = 1; - if (flags & SUPPRESS) { - size_t sum = 0; - for (;;) { - if ((n = fp->_r) < width) { - sum += n; - width -= n; - fp->_p += n; - if (__srefill(fp)) { - if (sum == 0) - goto input_failure; - break; - } - } else { - sum += width; - fp->_r -= width; - fp->_p += width; - break; - } - } - nread += sum; - } else { - size_t r = fread((void *)va_arg(ap, char *), 1, - width, fp); - - if (r == 0) - goto input_failure; - nread += r; - nassigned++; - } - nconversions++; - break; - - case CT_CCL: - /* scan a (nonempty) character class (sets NOSKIP) */ - if (width == 0) - width = (size_t)~0; /* `infinity' */ - /* take only those things in the class */ - if (flags & SUPPRESS) { - n = 0; - while (ccltab[*fp->_p]) { - n++, fp->_r--, fp->_p++; - if (--width == 0) - break; - if (fp->_r <= 0 && __srefill(fp)) { - if (n == 0) - goto input_failure; - break; - } - } - if (n == 0) - goto match_failure; - } else { - p0 = p = va_arg(ap, char *); - while (ccltab[*fp->_p]) { - fp->_r--; - *p++ = *fp->_p++; - if (--width == 0) - break; - if (fp->_r <= 0 && __srefill(fp)) { - if (p == p0) - goto input_failure; - break; - } - } - n = p - p0; - if (n == 0) - goto match_failure; - *p = 0; - nassigned++; - } - nread += n; - nconversions++; - break; - - case CT_STRING: - /* like CCL, but zero-length string OK, & no NOSKIP */ - if (width == 0) - width = (size_t)~0; - if (flags & SUPPRESS) { - n = 0; - while (!isspace(*fp->_p)) { - n++, fp->_r--, fp->_p++; - if (--width == 0) - break; - if (fp->_r <= 0 && __srefill(fp)) - break; - } - nread += n; - } else { - p0 = p = va_arg(ap, char *); - while (!isspace(*fp->_p)) { - fp->_r--; - *p++ = *fp->_p++; - if (--width == 0) - break; - if (fp->_r <= 0 && __srefill(fp)) - break; - } - *p = 0; - nread += p - p0; - nassigned++; - } - nconversions++; - continue; - - case CT_INT: - /* scan an integer as if by strtoq/strtouq */ -#ifdef hardway - if (width == 0 || width > sizeof(buf) - 1) - width = sizeof(buf) - 1; -#else - /* size_t is unsigned, hence this optimisation */ - if (--width > sizeof(buf) - 2) - width = sizeof(buf) - 2; - width++; -#endif - flags |= SIGNOK | NDIGITS | NZDIGITS; - for (p = buf; width; width--) { - c = *fp->_p; - /* - * Switch on the character; `goto ok' - * if we accept it as a part of number. - */ - switch (c) { - - /* - * The digit 0 is always legal, but is - * special. For %i conversions, if no - * digits (zero or nonzero) have been - * scanned (only signs), we will have - * base==0. In that case, we should set - * it to 8 and enable 0x prefixing. - * Also, if we have not scanned zero digits - * before this, do not turn off prefixing - * (someone else will turn it off if we - * have scanned any nonzero digits). - */ - case '0': - if (base == 0) { - base = 8; - flags |= PFXOK; - } - if (flags & NZDIGITS) - flags &= ~(SIGNOK|NZDIGITS|NDIGITS); - else - flags &= ~(SIGNOK|PFXOK|NDIGITS); - goto ok; - - /* 1 through 7 always legal */ - case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - base = basefix[base]; - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - - /* digits 8 and 9 ok iff decimal or hex */ - case '8': case '9': - base = basefix[base]; - if (base <= 8) - break; /* not legal here */ - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - - /* letters ok iff hex */ - case 'A': case 'B': case 'C': - case 'D': case 'E': case 'F': - case 'a': case 'b': case 'c': - case 'd': case 'e': case 'f': - /* no need to fix base here */ - if (base <= 10) - break; /* not legal here */ - flags &= ~(SIGNOK | PFXOK | NDIGITS); - goto ok; - - /* sign ok only as first character */ - case '+': case '-': - if (flags & SIGNOK) { - flags &= ~SIGNOK; - goto ok; - } - break; - - /* x ok iff flag still set & 2nd char */ - case 'x': case 'X': - if (flags & PFXOK && p == buf + 1) { - base = 16; /* if %i */ - flags &= ~PFXOK; - goto ok; - } - break; - } - - /* - * If we got here, c is not a legal character - * for a number. Stop accumulating digits. - */ - break; - ok: - /* - * c is legal: store it and look at the next. - */ - *p++ = c; - if (--fp->_r > 0) - fp->_p++; - else if (__srefill(fp)) - break; /* EOF */ - } - /* - * If we had only a sign, it is no good; push - * back the sign. If the number ends in `x', - * it was [sign] '0' 'x', so push back the x - * and treat it as [sign] '0'. - */ - if (flags & NDIGITS) { - if (p > buf) - (void) ungetc(*(u_char *)--p, fp); - goto match_failure; - } - c = ((u_char *)p)[-1]; - if (c == 'x' || c == 'X') { - --p; - (void) ungetc(c, fp); - } - if ((flags & SUPPRESS) == 0) { - u_quad_t res; - - *p = 0; - res = (*ccfn)(buf, (char **)NULL, base); - if (flags & POINTER) - *va_arg(ap, void **) = - (void *)(u_long)res; - else if (flags & SHORT) - *va_arg(ap, short *) = res; - else if (flags & LONG) - *va_arg(ap, long *) = res; - else if (flags & QUAD) - *va_arg(ap, quad_t *) = res; - else - *va_arg(ap, int *) = res; - nassigned++; - } - nread += p - buf; - nconversions++; - break; - -#ifdef FLOATING_POINT - case CT_FLOAT: - /* scan a floating point number as if by strtod */ -#ifdef hardway - if (width == 0 || width > sizeof(buf) - 1) - width = sizeof(buf) - 1; -#else - /* size_t is unsigned, hence this optimisation */ - if (--width > sizeof(buf) - 2) - width = sizeof(buf) - 2; - width++; -#endif - flags |= SIGNOK | NDIGITS | DPTOK | EXPOK; - for (p = buf; width; width--) { - c = *fp->_p; - /* - * This code mimicks the integer conversion - * code, but is much simpler. - */ - switch (c) { - - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - case '8': case '9': - flags &= ~(SIGNOK | NDIGITS); - goto fok; - - case '+': case '-': - if (flags & SIGNOK) { - flags &= ~SIGNOK; - goto fok; - } - break; - case '.': - if (flags & DPTOK) { - flags &= ~(SIGNOK | DPTOK); - goto fok; - } - break; - case 'e': case 'E': - /* no exponent without some digits */ - if ((flags&(NDIGITS|EXPOK)) == EXPOK) { - flags = - (flags & ~(EXPOK|DPTOK)) | - SIGNOK | NDIGITS; - goto fok; - } - break; - } - break; - fok: - *p++ = c; - if (--fp->_r > 0) - fp->_p++; - else if (__srefill(fp)) - break; /* EOF */ - } - /* - * If no digits, might be missing exponent digits - * (just give back the exponent) or might be missing - * regular digits, but had sign and/or decimal point. - */ - if (flags & NDIGITS) { - if (flags & EXPOK) { - /* no digits at all */ - while (p > buf) - ungetc(*(u_char *)--p, fp); - goto match_failure; - } - /* just a bad exponent (e and maybe sign) */ - c = *(u_char *)--p; - if (c != 'e' && c != 'E') { - (void) ungetc(c, fp);/* sign */ - c = *(u_char *)--p; - } - (void) ungetc(c, fp); - } - if ((flags & SUPPRESS) == 0) { - double res; - - *p = 0; - /* XXX this loses precision for long doubles. */ - res = strtod(buf, (char **) NULL); - if (flags & LONGDBL) - *va_arg(ap, long double *) = res; - else if (flags & LONG) - *va_arg(ap, double *) = res; - else - *va_arg(ap, float *) = res; - nassigned++; - } - nread += p - buf; - nconversions++; - break; -#endif /* FLOATING_POINT */ - } - } -input_failure: - return (nconversions != 0 ? nassigned : EOF); -match_failure: - return (nassigned); -} - -/* - * Fill in the given table from the scanset at the given format - * (just after `['). Return a pointer to the character past the - * closing `]'. The table has a 1 wherever characters should be - * considered part of the scanset. - */ -static u_char * -__sccl(tab, fmt) - register char *tab; - register u_char *fmt; -{ - register int c, n, v, i; - - /* first `clear' the whole table */ - c = *fmt++; /* first char hat => negated scanset */ - if (c == '^') { - v = 1; /* default => accept */ - c = *fmt++; /* get new first char */ - } else - v = 0; /* default => reject */ - - /* XXX: Will not work if sizeof(tab*) > sizeof(char) */ - (void) memset(tab, v, 256); - - if (c == 0) - return (fmt - 1);/* format ended before closing ] */ - - /* - * Now set the entries corresponding to the actual scanset - * to the opposite of the above. - * - * The first character may be ']' (or '-') without being special; - * the last character may be '-'. - */ - v = 1 - v; - for (;;) { - tab[c] = v; /* take character c */ -doswitch: - n = *fmt++; /* and examine the next */ - switch (n) { - - case 0: /* format ended too soon */ - return (fmt - 1); - - case '-': - /* - * A scanset of the form - * [01+-] - * is defined as `the digit 0, the digit 1, - * the character +, the character -', but - * the effect of a scanset such as - * [a-zA-Z0-9] - * is implementation defined. The V7 Unix - * scanf treats `a-z' as `the letters a through - * z', but treats `a-a' as `the letter a, the - * character -, and the letter a'. - * - * For compatibility, the `-' is not considerd - * to define a range if the character following - * it is either a close bracket (required by ANSI) - * or is not numerically greater than the character - * we just stored in the table (c). - */ - n = *fmt; - if (n == ']' - || (__collate_load_error ? n < c : - __collate_range_cmp (n, c) < 0 - ) - ) { - c = '-'; - break; /* resume the for(;;) */ - } - fmt++; - /* fill in the range */ - if (__collate_load_error) { - do { - tab[++c] = v; - } while (c < n); - } else { - for (i = 0; i < 256; i ++) - if ( __collate_range_cmp (c, i) < 0 - && __collate_range_cmp (i, n) <= 0 - ) - tab[i] = v; - } -#if 1 /* XXX another disgusting compatibility hack */ - c = n; - /* - * Alas, the V7 Unix scanf also treats formats - * such as [a-c-e] as `the letters a through e'. - * This too is permitted by the standard.... - */ - goto doswitch; -#else - c = *fmt++; - if (c == 0) - return (fmt - 1); - if (c == ']') - return (fmt); -#endif - break; - - case ']': /* end of scanset */ - return (fmt); - - default: /* just another character */ - c = n; - break; - } - } - /* NOTREACHED */ -} diff --git a/lib/libc/stdio/vprintf.c b/lib/libc/stdio/vprintf.c deleted file mode 100644 index 8d449d6..0000000 --- a/lib/libc/stdio/vprintf.c +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)vprintf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> - -int -vprintf(fmt, ap) - char const *fmt; - _BSD_VA_LIST_ ap; -{ - return (vfprintf(stdout, fmt, ap)); -} diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c deleted file mode 100644 index 9381710..0000000 --- a/lib/libc/stdio/vscanf.c +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Donn Seeley at UUNET Technologies, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif - -int -vscanf(fmt, ap) - const char *fmt; - _BSD_VA_LIST_ ap; -{ - int retval; - -#ifdef _THREAD_SAFE - _thread_flockfile(stdin,__FILE__,__LINE__); -#endif - retval = __svfscanf(stdin, fmt, ap); -#ifdef _THREAD_SAFE - _thread_funlockfile(stdin); -#endif - return (retval); -} diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c deleted file mode 100644 index 6cf2d76..0000000 --- a/lib/libc/stdio/vsnprintf.c +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id: vsnprintf.c,v 1.10 1997/12/24 23:54:19 ache Exp $"; -#endif /* LIBC_SCCS and not lint */ - -#include <limits.h> -#include <stdio.h> - -int -vsnprintf(str, n, fmt, ap) - char *str; - size_t n; - const char *fmt; - _BSD_VA_LIST_ ap; -{ - size_t on; - int ret; - FILE f; - - on = n; - if (n != 0) - n--; - if (n > INT_MAX) - n = INT_MAX; - f._file = -1; - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n; - ret = vfprintf(&f, fmt, ap); - if (on > 0) - *f._p = '\0'; - return (ret); -} diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c deleted file mode 100644 index 911d97f..0000000 --- a/lib/libc/stdio/vsprintf.c +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)vsprintf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <limits.h> - -int -vsprintf(str, fmt, ap) - char *str; - const char *fmt; - _BSD_VA_LIST_ ap; -{ - int ret; - FILE f; - - f._file = -1; - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = INT_MAX; - ret = vfprintf(&f, fmt, ap); - *f._p = 0; - return (ret); -} diff --git a/lib/libc/stdio/vsscanf.c b/lib/libc/stdio/vsscanf.c deleted file mode 100644 index 4cfa662..0000000 --- a/lib/libc/stdio/vsscanf.c +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Donn Seeley at UUNET Technologies, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)vsscanf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <string.h> - -static int -eofread __P((void *, char *, int)); - -/* ARGSUSED */ -static int -eofread(cookie, buf, len) - void *cookie; - char *buf; - int len; -{ - - return (0); -} - -int -vsscanf(str, fmt, ap) - const char *str; - const char *fmt; - _BSD_VA_LIST_ ap; -{ - FILE f; - - f._file = -1; - f._flags = __SRD; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._r = strlen(str); - f._read = eofread; - f._ub._base = NULL; - f._lb._base = NULL; - return (__svfscanf(&f, fmt, ap)); -} diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c deleted file mode 100644 index b85ac51..0000000 --- a/lib/libc/stdio/wbuf.c +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include "local.h" - -/* - * Write the given character into the (probably full) buffer for - * the given file. Flush the buffer out if it is or becomes full, - * or if c=='\n' and the file is line buffered. - */ -int -__swbuf(c, fp) - register int c; - register FILE *fp; -{ - register int n; - - /* - * In case we cannot write, or longjmp takes us out early, - * make sure _w is 0 (if fully- or un-buffered) or -_bf._size - * (if line buffered) so that we will get called again. - * If we did not do this, a sufficient number of putc() - * calls might wrap _w from negative to positive. - */ - fp->_w = fp->_lbfsize; - if (cantwrite(fp)) - return (EOF); - c = (unsigned char)c; - - /* - * If it is completely full, flush it out. Then, in any case, - * stuff c into the buffer. If this causes the buffer to fill - * completely, or if c is '\n' and the file is line buffered, - * flush it (perhaps a second time). The second flush will always - * happen on unbuffered streams, where _bf._size==1; fflush() - * guarantees that putc() will always call wbuf() by setting _w - * to 0, so we need not do anything else. - */ - n = fp->_p - fp->_bf._base; - if (n >= fp->_bf._size) { - if (fflush(fp)) - return (EOF); - n = 0; - } - fp->_w--; - *fp->_p++ = c; - if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) - if (fflush(fp)) - return (EOF); - return (c); -} diff --git a/lib/libc/stdio/wsetup.c b/lib/libc/stdio/wsetup.c deleted file mode 100644 index 74f0f77..0000000 --- a/lib/libc/stdio/wsetup.c +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Chris Torek. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <stdlib.h> -#include "local.h" - -/* - * Various output routines call wsetup to be sure it is safe to write, - * because either _flags does not include __SWR, or _buf is NULL. - * _wsetup returns 0 if OK to write, nonzero otherwise. - */ -int -__swsetup(fp) - register FILE *fp; -{ - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - /* - * If we are not writing, we had better be reading and writing. - */ - if ((fp->_flags & __SWR) == 0) { - if ((fp->_flags & __SRW) == 0) - return (EOF); - if (fp->_flags & __SRD) { - /* clobber any ungetc data */ - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~(__SRD|__SEOF); - fp->_r = 0; - fp->_p = fp->_bf._base; - } - fp->_flags |= __SWR; - } - - /* - * Make a buffer if necessary, then set _w. - */ - if (fp->_bf._base == NULL) - __smakebuf(fp); - if (fp->_flags & __SLBF) { - /* - * It is line buffered, so make _lbfsize be -_bufsize - * for the putc() macro. We will change _lbfsize back - * to 0 whenever we turn off __SWR. - */ - fp->_w = 0; - fp->_lbfsize = -fp->_bf._size; - } else - fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size; - return (0); -} |