diff options
Diffstat (limited to 'libc/stdio')
-rw-r--r-- | libc/stdio/fflush.c | 97 | ||||
-rw-r--r-- | libc/stdio/fgetc.c | 40 | ||||
-rw-r--r-- | libc/stdio/fputc.c | 41 | ||||
-rw-r--r-- | libc/stdio/fscanf.c | 47 | ||||
-rw-r--r-- | libc/stdio/fseek.c | 260 | ||||
-rw-r--r-- | libc/stdio/ftell.c | 100 | ||||
-rw-r--r-- | libc/stdio/gets.c | 59 | ||||
-rw-r--r-- | libc/stdio/printf.c | 47 | ||||
-rw-r--r-- | libc/stdio/refill.c | 128 | ||||
-rw-r--r-- | libc/stdio/rewind.c | 43 | ||||
-rw-r--r-- | libc/stdio/scanf.c | 47 | ||||
-rw-r--r-- | libc/stdio/stdio.c | 89 | ||||
-rw-r--r-- | libc/stdio/ungetc.c | 145 | ||||
-rw-r--r-- | libc/stdio/vasprintf.c | 55 | ||||
-rw-r--r-- | libc/stdio/vprintf.c | 40 | ||||
-rw-r--r-- | libc/stdio/vscanf.c | 41 | ||||
-rw-r--r-- | libc/stdio/vsnprintf.c | 64 | ||||
-rw-r--r-- | libc/stdio/vsprintf.c | 59 | ||||
-rw-r--r-- | libc/stdio/wbuf.c | 84 |
19 files changed, 0 insertions, 1486 deletions
diff --git a/libc/stdio/fflush.c b/libc/stdio/fflush.c deleted file mode 100644 index e69bdcc..0000000 --- a/libc/stdio/fflush.c +++ /dev/null @@ -1,97 +0,0 @@ -/* $OpenBSD: fflush.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <errno.h> -#include <stdio.h> -#include "local.h" - -/* Flush a single file, or (if fp is NULL) all files. */ -int -fflush(FILE *fp) -{ - int r; - - if (fp == NULL) - return (_fwalk(__sflush_locked)); - FLOCKFILE(fp); - if ((fp->_flags & (__SWR | __SRW)) == 0) { - errno = EBADF; - r = EOF; - } else - r = __sflush(fp); - FUNLOCKFILE(fp); - return (r); -} - -int -__sflush(FILE *fp) -{ - unsigned char *p; - 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); -} - -int -__sflush_locked(FILE *fp) -{ - int r; - - FLOCKFILE(fp); - r = __sflush(fp); - FUNLOCKFILE(fp); - return (r); -} diff --git a/libc/stdio/fgetc.c b/libc/stdio/fgetc.c deleted file mode 100644 index 0a6d54e..0000000 --- a/libc/stdio/fgetc.c +++ /dev/null @@ -1,40 +0,0 @@ -/* $OpenBSD: fgetc.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> - -int -fgetc(FILE *fp) -{ - return (getc(fp)); -} diff --git a/libc/stdio/fputc.c b/libc/stdio/fputc.c deleted file mode 100644 index 90809e2..0000000 --- a/libc/stdio/fputc.c +++ /dev/null @@ -1,41 +0,0 @@ -/* $OpenBSD: fputc.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include <errno.h> - -int -fputc(int c, FILE *fp) -{ - return (putc(c, fp)); -} diff --git a/libc/stdio/fscanf.c b/libc/stdio/fscanf.c deleted file mode 100644 index 2f3fceb..0000000 --- a/libc/stdio/fscanf.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: fscanf.c,v 1.9 2005/10/10 17:37:44 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include <stdarg.h> - -int -fscanf(FILE *fp, const char *fmt, ...) -{ - int ret; - va_list ap; - - va_start(ap, fmt); - ret = vfscanf(fp, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/libc/stdio/fseek.c b/libc/stdio/fseek.c deleted file mode 100644 index 38697f5..0000000 --- a/libc/stdio/fseek.c +++ /dev/null @@ -1,260 +0,0 @@ -/* $OpenBSD: fseek.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include "local.h" - -#define POS_ERR (-(fpos_t)1) - -/* - * Seek the given file to the given offset. - * `Whence' must be one of the three SEEK_* macros. - */ -int -fseeko(FILE *fp, off_t offset, int whence) -{ - fpos_t (*seekfn)(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(); - - /* - * 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. - */ - FLOCKFILE(fp); - 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). - */ - __sflush(fp); /* may adjust seek offset on append stream */ - if (fp->_flags & __SOFF) - curoff = fp->_offset; - else { - curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == (fpos_t)-1) { - FUNLOCKFILE(fp); - 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: - FUNLOCKFILE(fp); - errno = EINVAL; - 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 < (fpos_t)(curoff + n)) { - int o = target - curoff; - - fp->_p = fp->_bf._base + o; - fp->_r = n - o; - if (HASUB(fp)) - FREEUB(fp); - fp->_flags &= ~__SEOF; - FUNLOCKFILE(fp); - 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) || (size_t)fp->_r < n) - goto dumb; - fp->_p += n; - fp->_r -= n; - } - FUNLOCKFILE(fp); - 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) { - FUNLOCKFILE(fp); - 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; - FUNLOCKFILE(fp); - return (0); -} - -/* - * fseek()'s offset is a long and sizeof(off_t) != sizeof(long) on all arches - */ -#if defined(__alpha__) && defined(__indr_reference) -__indr_reference(fseeko, fseek); -#else -int -fseek(FILE *fp, long offset, int whence) -{ - off_t off = offset; - - return(fseeko(fp, off, whence)); -} -#endif diff --git a/libc/stdio/ftell.c b/libc/stdio/ftell.c deleted file mode 100644 index 9f850ee..0000000 --- a/libc/stdio/ftell.c +++ /dev/null @@ -1,100 +0,0 @@ -/* $OpenBSD: ftell.c,v 1.6 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include <errno.h> -#include "local.h" - -/* - * ftello: return current offset. - */ -off_t -ftello(FILE *fp) -{ - fpos_t pos; - - if (fp->_seek == NULL) { - errno = ESPIPE; /* historic practice */ - pos = -1; - goto out; - } - - /* - * Find offset of underlying I/O object, then - * adjust for buffered bytes. - */ - FLOCKFILE(fp); - __sflush(fp); /* may adjust seek offset on append stream */ - if (fp->_flags & __SOFF) - pos = fp->_offset; - else { - pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (pos == -1) - goto out; - } - 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; - } -out: FUNLOCKFILE(fp); - return (pos); -} - -/* - * ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches - */ -#if defined(__alpha__) && defined(__indr_reference) -__indr_reference(ftello, ftell); -#else -long -ftell(FILE *fp) -{ - long pos; - - pos = (long)ftello(fp); - return(pos); -} -#endif diff --git a/libc/stdio/gets.c b/libc/stdio/gets.c deleted file mode 100644 index 93e2edd..0000000 --- a/libc/stdio/gets.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: gets.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include "local.h" - -__warn_references(gets, - "warning: gets() is very unsafe; consider using fgets()"); - -char * -gets(char *buf) -{ - int c; - char *s; - - FLOCKFILE(stdin); - for (s = buf; (c = getchar_unlocked()) != '\n';) - if (c == EOF) - if (s == buf) { - FUNLOCKFILE(stdin); - return (NULL); - } else - break; - else - *s++ = c; - *s = '\0'; - FUNLOCKFILE(stdin); - return (buf); -} diff --git a/libc/stdio/printf.c b/libc/stdio/printf.c deleted file mode 100644 index 614b435..0000000 --- a/libc/stdio/printf.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: printf.c,v 1.7 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include <stdarg.h> - -int -printf(const char *fmt, ...) -{ - int ret; - va_list ap; - - va_start(ap, fmt); - ret = vfprintf(stdout, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/libc/stdio/refill.c b/libc/stdio/refill.c deleted file mode 100644 index 7cb6b78..0000000 --- a/libc/stdio/refill.c +++ /dev/null @@ -1,128 +0,0 @@ -/* $OpenBSD: refill.c,v 1.8 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include "local.h" - -static int -lflush(FILE *fp) -{ - if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) - return (__sflush_locked(fp)); /* ignored... */ - return (0); -} - -/* - * Refill a stdio buffer. - * Return EOF on eof or error, 0 otherwise. - */ -int -__srefill(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; - fp->_flags |= __SERR; - 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)) { - /* Ignore this file in _fwalk to avoid potential deadlock. */ - fp->_flags |= __SIGN; - (void) _fwalk(lflush); - fp->_flags &= ~__SIGN; - - /* Now flush this file without locking it. */ - if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR)) - __sflush(fp); - } - 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/libc/stdio/rewind.c b/libc/stdio/rewind.c deleted file mode 100644 index 28119b6..0000000 --- a/libc/stdio/rewind.c +++ /dev/null @@ -1,43 +0,0 @@ -/* $OpenBSD: rewind.c,v 1.5 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <errno.h> -#include <stdio.h> - -void -rewind(FILE *fp) -{ - (void) fseek(fp, 0L, SEEK_SET); - clearerr(fp); - errno = 0; /* not required, but seems reasonable */ -} diff --git a/libc/stdio/scanf.c b/libc/stdio/scanf.c deleted file mode 100644 index 71194d0..0000000 --- a/libc/stdio/scanf.c +++ /dev/null @@ -1,47 +0,0 @@ -/* $OpenBSD: scanf.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include <stdarg.h> - -int -scanf(const char *fmt, ...) -{ - int ret; - va_list ap; - - va_start(ap, fmt); - ret = vfscanf(stdin, fmt, ap); - va_end(ap); - return (ret); -} diff --git a/libc/stdio/stdio.c b/libc/stdio/stdio.c deleted file mode 100644 index 1596ebf..0000000 --- a/libc/stdio/stdio.c +++ /dev/null @@ -1,89 +0,0 @@ -/* $OpenBSD: stdio.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#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(void *cookie, char *buf, int n) -{ - FILE *fp = cookie; - int ret; - - ret = read(fp->_file, buf, n); - /* if the read succeeded, update the current offset */ - if (ret >= 0) - fp->_offset += ret; - else - fp->_flags &= ~__SOFF; /* paranoia */ - return (ret); -} - -int -__swrite(void *cookie, const char *buf, int n) -{ - 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, n)); -} - -fpos_t -__sseek(void *cookie, fpos_t offset, int whence) -{ - FILE *fp = cookie; - off_t ret; - - ret = lseek(fp->_file, (off_t)offset, whence); - if (ret == (off_t)-1) - fp->_flags &= ~__SOFF; - else { - fp->_flags |= __SOFF; - fp->_offset = ret; - } - return (ret); -} - -int -__sclose(void *cookie) -{ - return (close(((FILE *)cookie)->_file)); -} diff --git a/libc/stdio/ungetc.c b/libc/stdio/ungetc.c deleted file mode 100644 index b493d21..0000000 --- a/libc/stdio/ungetc.c +++ /dev/null @@ -1,145 +0,0 @@ -/* $OpenBSD: ungetc.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "local.h" - -static int __submore(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(FILE *fp) -{ - int i; - unsigned char *p; - - if (_UB(fp)._base == fp->_ubuf) { - /* - * Get a new buffer (rather than expanding the old one). - */ - if ((p = malloc((size_t)BUFSIZ)) == NULL) - return (EOF); - _UB(fp)._base = p; - _UB(fp)._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 = _UB(fp)._size; - p = realloc(_UB(fp)._base, 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; - _UB(fp)._base = p; - _UB(fp)._size = i << 1; - return (0); -} - -int -ungetc(int c, FILE *fp) -{ - if (c == EOF) - return (EOF); - if (!__sdidinit) - __sinit(); - FLOCKFILE(fp); - _SET_ORIENTATION(fp, -1); - 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) { -error: FUNLOCKFILE(fp); - return (EOF); - } - if (fp->_flags & __SWR) { - if (__sflush(fp)) - goto error; - 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 >= _UB(fp)._size && __submore(fp)) - goto error; - *--fp->_p = c; -inc_ret: fp->_r++; - FUNLOCKFILE(fp); - 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--; - goto inc_ret; - } - - /* - * Create an ungetc buffer. - * Initially, we will use the `reserve' buffer. - */ - fp->_ur = fp->_r; - fp->_up = fp->_p; - _UB(fp)._base = fp->_ubuf; - _UB(fp)._size = sizeof(fp->_ubuf); - fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; - fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; - fp->_r = 1; - FUNLOCKFILE(fp); - return (c); -} diff --git a/libc/stdio/vasprintf.c b/libc/stdio/vasprintf.c deleted file mode 100644 index 1630ccb..0000000 --- a/libc/stdio/vasprintf.c +++ /dev/null @@ -1,55 +0,0 @@ -/* $OpenBSD: vasprintf.c,v 1.13 2006/01/06 18:53:04 millert Exp $ */ - -/* - * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com> - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> -#include "local.h" - -int -vasprintf(char **str, const char *fmt, __va_list ap) -{ - int ret; - FILE f; - struct __sfileext fext; - unsigned char *_base; - - _FILEEXT_SETUP(&f, &fext); - f._file = -1; - f._flags = __SWR | __SSTR | __SALC; - f._bf._base = f._p = (unsigned char *)malloc(128); - if (f._bf._base == NULL) - goto err; - f._bf._size = f._w = 127; /* Leave room for the NUL */ - ret = __vfprintf(&f, fmt, ap); - if (ret == -1) - goto err; - *f._p = '\0'; - _base = realloc(f._bf._base, ret + 1); - if (_base == NULL) - goto err; - *str = (char *)_base; - return (ret); - -err: - free(f._bf._base); - *str = NULL; - errno = ENOMEM; - return (-1); -} diff --git a/libc/stdio/vprintf.c b/libc/stdio/vprintf.c deleted file mode 100644 index fcc622c..0000000 --- a/libc/stdio/vprintf.c +++ /dev/null @@ -1,40 +0,0 @@ -/* $OpenBSD: vprintf.c,v 1.8 2006/01/06 18:53:04 millert Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> - -int -vprintf(const char *fmt, __va_list ap) -{ - return (vfprintf(stdout, fmt, ap)); -} diff --git a/libc/stdio/vscanf.c b/libc/stdio/vscanf.c deleted file mode 100644 index 228498e..0000000 --- a/libc/stdio/vscanf.c +++ /dev/null @@ -1,41 +0,0 @@ -/* $OpenBSD: vscanf.c,v 1.8 2006/01/06 18:53:04 millert Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> - -int -vscanf(const char *fmt, __va_list ap) -{ - - return (vfscanf(stdin, fmt, ap)); -} diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c deleted file mode 100644 index ca30f94..0000000 --- a/libc/stdio/vsnprintf.c +++ /dev/null @@ -1,64 +0,0 @@ -/* $OpenBSD: vsnprintf.c,v 1.12 2006/01/06 18:53:04 millert Exp $ */ -/*- - * 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. 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. - */ - -#include <limits.h> -#include <stdio.h> -#include <string.h> -#include "local.h" - -int -vsnprintf(char *str, size_t n, const char *fmt, __va_list ap) -{ - int ret; - char dummy; - FILE f; - struct __sfileext fext; - - _FILEEXT_SETUP(&f, &fext); - - /* While snprintf(3) specifies size_t stdio uses an int internally */ - if (n > INT_MAX) - n = INT_MAX; - /* Stdio internals do not deal correctly with zero length buffer */ - if (n == 0) { - str = &dummy; - n = 1; - } - f._file = -1; - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = n - 1; - ret = __vfprintf(&f, fmt, ap); - *f._p = '\0'; - return (ret); -} diff --git a/libc/stdio/vsprintf.c b/libc/stdio/vsprintf.c deleted file mode 100644 index 846ee8a..0000000 --- a/libc/stdio/vsprintf.c +++ /dev/null @@ -1,59 +0,0 @@ -/* $OpenBSD: vsprintf.c,v 1.13 2006/01/06 18:53:04 millert Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include <string.h> -#include <limits.h> -#include "local.h" - -#if defined(APIWARN) -__warn_references(vsprintf, - "warning: vsprintf() is often misused, please use vsnprintf()"); -#endif - -int -vsprintf(char *str, const char *fmt, __va_list ap) -{ - int ret; - FILE f; - struct __sfileext fext; - - _FILEEXT_SETUP(&f, &fext); - 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/libc/stdio/wbuf.c b/libc/stdio/wbuf.c deleted file mode 100644 index e09ac59..0000000 --- a/libc/stdio/wbuf.c +++ /dev/null @@ -1,84 +0,0 @@ -/* $OpenBSD: wbuf.c,v 1.9 2005/08/08 08:05:36 espie Exp $ */ -/*- - * 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. 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. - */ - -#include <stdio.h> -#include <errno.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(int c, FILE *fp) -{ - int n; - - _SET_ORIENTATION(fp, -1); - /* - * 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)) { - errno = EBADF; - 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; __sflush() - * 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 (__sflush(fp)) - return (EOF); - n = 0; - } - fp->_w--; - *fp->_p++ = c; - if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) - if (__sflush(fp)) - return (EOF); - return (c); -} |