ansiStdio.c
上传用户:nvosite88
上传日期:2007-01-17
资源大小:4983k
文件大小:177k
- * 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;
- doStat = ioctl (fp->_file, FIOFSTATGET, (int)&st);
- if ((fp->_flags & __SOPT) == 0)
- {
- if ((fp->_file < 0 || (doStat) ||
- (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 (doStat)
- goto dumb;
- target = st.st_size + offset;
- }
- if (!havepos)
- {
- if (fp->_flags & __SOFF)
- curoff = fp->_offset;
- else
- {
- curoff = __sseek (fp, 0L, 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))
- {
- 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 fgetline.c.)
- */
- if (((fp->_flags & __SMOD) == 0) &&
- (target >= curoff) &&
- (target < (curoff + n)))
- {
- FAST int o = target - curoff;
- fp->_p = fp->_bf._base + o;
- fp->_r = n - o;
- if (HASUB(fp))
- FREEUB(fp);
- fp->_flags &= ~__SEOF;
- 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 (__sseek (fp, curoff, SEEK_SET) == POS_ERR)
- goto dumb;
- fp->_r = 0;
- 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;
- }
- 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)) || (__sseek (fp, offset, whence) == POS_ERR))
- 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;
- return (0);
- }
- /* fsetpos.c - set a position in a file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- /******************************************************************************
- *
- * fsetpos - set the file position indicator for a stream (ANSI)
- *
- * This routine sets the file position indicator for a specified stream <iop>
- * according to the value of the object pointed to by <pos>, which is a value
- * obtained from an earlier call to fgetpos() on the same stream.
- *
- * A successful call to fsetpos() clears the end-of-file indicator for the
- * stream and undoes any effects of ungetc() on the same stream. After an
- * fsetpos() call, the next operation on an update stream may be either input
- * or output.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * Zero, or non-zero if the call fails, with `errno' set to indicate the error.
- *
- * SEE ALSO: fgetpos()
- */
- int fsetpos
- (
- FILE * iop, /* stream */
- const fpos_t * pos /* position, obtained by fgetpos() */
- )
- {
- return (fseek (iop, (long)*pos, SEEK_SET));
- }
- /* ftell.c - remember a position in a file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h, error.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "errno.h"
- #include "objLib.h"
- #include "private/stdioP.h"
- /******************************************************************************
- *
- * ftell - return the current value of the file position indicator for a stream (ANSI)
- *
- * This routine returns the current value of the file position indicator for
- * a specified stream. For a binary stream, the value is the number of
- * characters from the beginning of the file. For a text stream, the file
- * position indicator contains unspecified information, usable by fseek() for
- * returning the file position indicator to its position at the time of the
- * ftell() call; the difference between two such return values is not
- * necessary a meaningful measure of the number of characters written or read.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * The current value of the file position indicator,
- * or -1L if unsuccessful, with `errno' set to indicate the error.
- *
- * SEE ALSO: fseek()
- */
- long ftell
- (
- FAST FILE * fp /* stream */
- )
- {
- FAST fpos_t pos;
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return (ERROR);
- /*
- * Find offset of underlying I/O object, then
- * adjust for buffered bytes.
- */
- if (fp->_flags & __SOFF)
- pos = fp->_offset;
- else
- {
- pos = __sseek (fp, (fpos_t)0, SEEK_CUR);
- if (pos == -1L)
- 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;
- }
- return (pos);
- }
- /* fwrite.c - write to a file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "objLib.h"
- #include "private/stdioP.h"
- #include "private/fvwriteP.h"
- /******************************************************************************
- *
- * fwrite - write from a specified array (ANSI)
- *
- * This routine writes, from the array <buf>, up to <count> elements whose
- * size is <size>, to a specified stream. The file position indicator for
- * the stream (if defined) is advanced by the number of characters
- * successfully written. If an error occurs, the resulting value of the file
- * position indicator for the stream is indeterminate.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * The number of elements successfully written, which will be less than
- * <count> only if a write error is encountered.
- */
- int fwrite
- (
- const void * buf, /* where to copy from */
- size_t size, /* element size */
- size_t count, /* no. of elements */
- FILE * fp /* stream to write to */
- )
- {
- size_t n;
- struct __suio uio;
- struct __siov iov;
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return (0);
- iov.iov_base = (void *)buf;
- uio.uio_resid = iov.iov_len = n = (count * size);
- uio.uio_iov = &iov;
- uio.uio_iovcnt = 1;
- /* 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)
- return (count);
- return ((n - uio.uio_resid) / size);
- }
- /* getc.c - get a character from a file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "objLib.h"
- #include "private/stdioP.h"
- #undef getc
- /******************************************************************************
- *
- * getc - return the next character from a stream (ANSI)
- *
- * This routine is equivalent to fgetc(), except that if it is implemented as
- * a macro, it may evaluate <fp> more than once; thus the argument should
- * never be an expression with side effects.
- *
- * If the stream is at end-of-file, the end-of-file indicator for the stream is
- * set; if a read error occurs, the error indicator is set.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * The next character from the stream, or EOF if the stream is at end-of-file
- * or a read error occurs.
- *
- * SEE ALSO: fgetc()
- */
- int getc
- (
- FILE * fp /* input stream */
- )
- {
- int ch;
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return (EOF);
- if ((ch = __sgetc(fp)) == EOF)
- fp->_flags |= __SEOF;
- return (ch);
- }
- /* getchar.c - get a character from a file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "private/stdioP.h"
- #undef getchar
- /******************************************************************************
- *
- * getchar - return the next character from the standard input stream (ANSI)
- *
- * This routine returns the next character from the standard input stream
- * and advances the file position indicator.
- *
- * It is equivalent to getc() with the stream argument `stdin'.
- *
- * If the stream is at end-of-file, the end-of-file indicator is
- * set; if a read error occurs, the error indicator is set.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * The next character from the standard input stream, or EOF if the stream is
- * at end-of-file or a read error occurs.
- *
- * SEE ALSO: getc(), fgetc()
- */
- int getchar (void)
- {
- return (getc (stdin));
- }
- /* gets.c - get a string of characters from a file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h, unistd.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "unistd.h"
- #include "private/stdioP.h"
- /******************************************************************************
- *
- * gets - read characters from the standard input stream (ANSI)
- *
- * This routine reads characters from the standard input stream into the
- * array <buf> until end-of-file is encountered or a new-line is read.
- * Any new-line character is discarded, and a null character is written
- * immediately after the last character read into the array.
- *
- * If end-of-file is encountered and no characters have been read,
- * the contents of the array remain unchanged. If a read error
- * occurs, the array contents are indeterminate.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * A pointer to <buf>, or a null pointer if (1) end-of-file is encountered
- * and no characters have been read, or (2) there is a read error.
- */
- char * gets
- (
- char * buf /* output array */
- )
- {
- FAST int c;
- FAST char * s;
- for (s = buf; (c = getchar()) != 'n';)
- {
- if (c == EOF)
- {
- if (s == buf)
- return (NULL);
- else
- break;
- }
- else
- *s++ = c;
- }
- *s = EOS;
- return (buf);
- }
- /* getw.c - get a word. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb written.
- */
- /*
- DESCRIPTION
- INCLUDE FILE: stdio.h, string.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- /******************************************************************************
- *
- * getw - read the next word (32-bit integer) from a stream
- *
- * This routine reads the next 32-bit quantity from a specified stream.
- * It returns EOF on end-of-file or an error; however, this is also a
- * valid integer, thus feof() and ferror() must be used to check for
- * a true end-of-file.
- *
- * This routine is provided for compatibility with earlier VxWorks releases.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURN: A 32-bit number from the stream, or EOF on either end-of-file
- * or an error.
- *
- * SEE ALSO: putw()
- */
- int getw
- (
- FILE * fp /* stream to read from */
- )
- {
- int x;
- return (fread ((void *)&x, sizeof (x), 1, fp) == 1 ? x : EOF);
- }
- /* perror.c - print error value. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb written.
- */
- /*
- DESCRIPTION
- INCLUDE FILE: stdio.h, error.h, string.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "string.h"
- #include "errno.h"
- /******************************************************************************
- *
- * perror - map an error number in `errno' to an error message (ANSI)
- *
- * This routine maps the error number in the integer expression `errno' to an
- * error message. It writes a sequence of characters to the standard error
- * stream as follows: first (if <__s> is not a null pointer and the character
- * pointed to by <__s> is not the null character), the string pointed to by
- * <__s> followed by a colon (:) and a space; then an appropriate error
- * message string followed by a new-line character. The contents of the
- * error message strings are the same as those returned by strerror() with
- * the argument `errno'.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS: N/A
- *
- * SEE ALSO: strerror()
- */
- void perror
- (
- const char * __s /* error string */
- )
- {
- if ((__s) && (*__s != EOS))
- fprintf (stderr, "%s: ", __s);
- fprintf (stderr, "%sn", strerror (errno));
- }
- /* putc.c - put a character. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "private/stdioP.h"
- #undef putc
- /******************************************************************************
- *
- * putc - write a character to a stream (ANSI)
- *
- * This routine writes a character <c> to a specified stream, at the
- * position indicated by the stream's file position indicator
- * (if defined), and advances the indicator appropriately.
- *
- * This routine is equivalent to fputc(), except that if it is implemented as
- * a macro, it may evaluate <fp> more than once; thus, the argument should
- * never be an expression with side effects.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * The character written, or EOF if a write error occurs, with the error
- * indicator set for the stream.
- *
- * SEE ALSO: fputc()
- */
- int putc
- (
- int c, /* character to write */
- FAST FILE * fp /* stream to write to */
- )
- {
- return (__sputc(c, fp));
- }
- /* putchar.c - put a character to standard output. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "private/stdioP.h"
- #undef putchar
- /******************************************************************************
- *
- * putchar - write a character to the standard output stream (ANSI)
- *
- * This routine writes a character <c> to the standard output stream, at the
- * position indicated by the stream's file position indicator
- * (if defined), and advances the indicator appropriately.
- *
- * This routine is equivalent to putc() with a second argument of `stdout'.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * The character written, or EOF if a write error occurs, with the error
- * indicator set for the standard output stream.
- *
- * SEE ALSO: putc(), fputc()
- */
- int putchar
- (
- int c /* character to write */
- )
- {
- return (__sputc(c, stdout));
- }
- /* puts.c - put a string of characters. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h, string.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "string.h"
- #include "private/fvwriteP.h"
- /******************************************************************************
- *
- * puts - write a string to the standard output stream (ANSI)
- *
- * This routine writes to the standard output stream a specified string <s>,
- * minus the terminating null character, and appends a new-line character to
- * the output.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * A non-negative value, or EOF if a write error occurs.
- *
- * SEE ALSO: fputs()
- */
- int puts
- (
- char const * s /* string to write */
- )
- {
- 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;
- return ((__sfvwrite (stdout, &uio)) ? (EOF) : ('n'));
- }
- /* putw.c - put a word. stdio.h */
-
- /* Copyright 1992-1993 Wind River Systems, Inc. */
-
- /*
- modification history
- --------------------
- 01d,05mar93,jdi documentation cleanup for 5.1.
- 01c,21sep92,smb tweaks for mg
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb written.
- */
-
- /*
- DESCRIPTION
-
- INCLUDE FILE: stdio.h, string.h
-
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
-
- #include "vxWorks.h"
- #include "stdio.h"
-
- /******************************************************************************
- *
- * putw - write a word (32-bit integer) to a stream
- *
- * This routine appends the 32-bit quantity <w> to a specified stream.
- *
- * This routine is provided for compatibility with earlier VxWorks releases.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS: The value written.
- */
- int putw
- (
- int w, /* word (32-bit integer) */
- FILE * fp /* output stream */
- )
- {
- return (fwrite ((void *) &w, sizeof (int), 1, fp) == 1 ? w : EOF);
- }
- /* rewind.c - rewind a stream. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h, error.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "objLib.h"
- #include "errno.h"
- /******************************************************************************
- *
- * rewind - set the file position indicator to the beginning of a file (ANSI)
- *
- * This routine sets the file position indicator for a specified stream to
- * the beginning of the file.
- *
- * It is equivalent to:
- * .CS
- * (void) fseek (fp, 0L, SEEK_SET);
- * .CE
- * except that the error indicator for the stream is cleared.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS: N/A
- *
- * SEE ALSO: fseek(), ftell()
- */
- void rewind
- (
- FILE * fp /* stream */
- )
- {
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return;
- (void) fseek (fp, 0L, SEEK_SET);
- clearerr(fp);
- }
- /* scanf.c - scan a file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf rewritten to usr fioScanV()
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h, stdarg.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdarg.h"
- #include "fioLib.h"
- #include "private/stdioP.h"
- /******************************************************************************
- *
- * scanf - read and convert characters from the standard input stream (ANSI)
- *
- * This routine reads input from the standard input stream under the control
- * of the string <fmt>. It is equivalent to fscanf() with an <fp> argument
- * of `stdin'.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * The number of input items assigned, which can be fewer than provided for,
- * or even zero, in the event of an early matching failure; or EOF if an
- * input failure occurs before any conversion.
- *
- * SEE ALSO: fscanf(), sscanf()
- */
- int scanf
- (
- char const * fmt, /* format string */
- ... /* arguments to format string */
- )
- {
- int nArgs;
- int unget;
- va_list vaList; /* vararg list */
- va_start (vaList, fmt);
- nArgs = fioScanV (fmt, fgetc, (int) stdin, &unget, vaList);
- va_end (vaList);
- if (unget != -1)
- ungetc (unget, stdin);
- return (nArgs);
- }
- /* setbuf.c - set buffered mode. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "objLib.h"
- #include "private/stdioP.h"
- /******************************************************************************
- *
- * setbuf - specify the buffering for a stream (ANSI)
- *
- * Except that it returns no value, this routine is equivalent to setvbuf()
- * invoked with the <mode> _IOFBF (full buffering) and <size> BUFSIZ, or (if
- * <buf> is a null pointer), with the <mode> _IONBF (no buffering).
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS: N/A
- *
- * SEE ALSO: setvbuf()
- */
- void setbuf
- (
- FILE * fp, /* stream to set buffering for */
- char * buf /* buffer to use */
- )
- {
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return;
- (void) setvbuf (fp, buf, ((buf) ? (_IOFBF) : (_IONBF)), BUFSIZ);
- }
- /* setbuffer.c- file for stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "objLib.h"
- #include "private/stdioP.h"
- /******************************************************************************
- *
- * setbuffer - specify buffering for a stream
- *
- * This routine specifies a buffer <buf> to be used for a stream in place of the
- * automatically allocated buffer. If <buf> is NULL, the stream is unbuffered.
- * This routine should be called only after the stream has been associated with
- * an open file and before any other operation is performed on the stream.
- *
- * This routine is provided for compatibility with earlier VxWorks releases.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS: N/A
- *
- * SEE ALSO: setvbuf()
- */
- void setbuffer
- (
- FAST FILE * fp, /* stream to set buffering for */
- char * buf, /* buffer to use */
- int size /* buffer size */
- )
- {
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return;
- (void) setvbuf (fp, buf, ((buf) ? (_IOFBF) : (_IONBF)), size);
- }
- /******************************************************************************
- *
- * setlinebuf - set line buffering for standard output or standard error
- *
- * This routine changes `stdout' or `stderr' streams from block-buffered or
- * unbuffered to line-buffered. Unlike setbuf(), setbuffer(), or setvbuf(), it
- * can be used at any time the stream is active.
- *
- * A stream can be changed from unbuffered or line-buffered to fully buffered
- * using freopen(). A stream can be changed from fully buffered or
- * line-buffered to unbuffered using freopen() followed by setbuf() with a
- * buffer argument of NULL.
- *
- * This routine is provided for compatibility with earlier VxWorks releases.
- *
- * INCLUDE: stdio.h
- *
- * RETURNS: OK, or ERROR if <fp> is not a valid stream.
- */
- int setlinebuf
- (
- FILE * fp /* stream - stdout or stderr */
- )
- {
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return (ERROR);
- (void) setvbuf (fp, (char *)NULL, _IOLBF, (size_t)0);
- return (OK); /* ??? */
- }
- /* setvbuf.c - set buffered mode. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h, stdlib.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "objLib.h"
- #include "private/stdioP.h"
- /******************************************************************************
- *
- * setvbuf - specify buffering for a stream (ANSI)
- *
- * This routine sets the buffer size and buffering mode for a specified
- * stream. It should be called only after the stream has been associated
- * with an open file and before any other operation is performed on the
- * stream. The argument <mode> determines how the stream will be buffered,
- * as follows:
- * .iP _IOFBF 12
- * input/output is to be fully buffered.
- * .iP _IOLBF
- * input/output is to be line buffered.
- * .iP _IONBF
- * input/output is to be unbuffered.
- * .LP
- *
- * If <buf> is not a null pointer, the array it points to may be used instead
- * of a buffer allocated by setvbuf(). The argument <size> specifies
- * the size of the array. The contents of the array at any time are
- * indeterminate.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * Zero, or non-zero if <mode> is invalid or the request cannot be honored.
- */
- int setvbuf
- (
- FAST FILE * fp, /* stream to set buffering for */
- char * buf, /* buffer to use (optional) */
- FAST int mode, /* _IOFBF = fully buffered */
- /* _IOLBF = line buffered */
- /* _IONBF = unbuffered */
- FAST size_t size /* buffer size */
- )
- {
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return (ERROR);
- /*
- * Verify arguments. The `int' limit on `size' is due to this
- * particular implementation.
- */
- if (((mode != _IOFBF) && (mode != _IOLBF) && (mode != _IONBF)) ||
- ((int)size < 0))
- return (EOF);
- /*
- * Write current buffer, if any; drop read count, if any.
- * Make sure putc() will not think fp is line buffered.
- * Free old buffer if it was from malloc(). Clear line and
- * non buffer flags, and clear malloc flag.
- */
- (void) __sflush (fp);
- fp->_r = 0;
- fp->_lbfsize = 0;
- if (fp->_flags & __SMBF)
- free ((void *)fp->_bf._base);
- fp->_flags &= ~(__SLBF | __SNBF | __SMBF);
- /*
- * Now put back whichever flag is needed, and fix _lbfsize
- * if line buffered. Ensure output flush on exit if the
- * stream will be buffered at all.
- */
- switch (mode)
- {
- case _IONBF:
- fp->_flags |= __SNBF;
- fp->_bf._base = fp->_p = fp->_nbuf;
- fp->_bf._size = 1;
- break;
- case _IOLBF:
- fp->_flags |= __SLBF;
- fp->_lbfsize = -size;
- /* FALLTHROUGH */
- case _IOFBF:
- /* no flag */
- fp->_bf._base = fp->_p = (unsigned char *)buf;
- fp->_bf._size = size;
- break;
- default:
- break;
- }
- /*
- * Patch up write count if necessary.
- */
- if (fp->_flags & __SWR)
- fp->_w = (fp->_flags & (__SLBF | __SNBF)) ? (0) : (size);
- return (0);
- }
- /* stdioLib.c - standard I/O library */
- /* Copyright 1984-1995 Wind River Systems, Inc. */
- #include "copyright_wrs.h"
- /*
- modification history
- --------------------
- 02i,11feb95,jdi doc tweak.
- 02h,05mar93,jdi documentation cleanup for 5.1.
- 02g,13nov92,dnw added __std{in,out,err} (SPR #1770)
- made stdInitStd() be LOCAL.
- changed stdioFp() create FILE if it doesn't already exist.
- 02f,20sep92,smb documentation additions
- 02e,29jul92,smb added stdioFp().
- Modified the documentation for the new stdio library.
- 02d,29jul92,jcf taken from stdioLib.c
- 02c,26may92,rrr the tree shuffle
- 02b,02apr92,jmm added free() of memory if bad options passed to fdopen()
- SPR # 1396
- 02a,27mar92,jmm changed fopen() to free memory if the open() fails, SPR #1115
- 01z,25nov91,rrr cleanup of some ansi warnings.
- 01y,12nov91,rrr removed VARARG_OK, no longer needed with ansi c.
- 01x,07oct91,rrr junk for r3000 braindamage.
- 01w,04oct91,rrr passed through the ansification filter
- -changed functions to ansi style
- -changed includes to have absolute path from h/
- -fixed #else and #endif
- -changed VOID to void
- -changed copyright notice
- 01v,18may91,gae fixed varargs for 960 with conditional VARARG_OK,
- namely: fscanf, fprintf, and scanf.
- 01u,04apr91,jdi documentation cleanup; doc review by dnw.
- 01t,10aug90,dnw added forward declaration of stdioExitStd ().
- 01s,08aug90,dnw changed incorrect forward declaration for stdioCreateHook().
- 01r,10jun90,dnw changed to call fioFormatV and fioScanV directly with
- appropriate handling of varargs (removed doscan and doprnt)
- moved all routine implementations of stdio macros to end of
- module so that macros would be used in rest of code
- spr 640: fprintf returns number of chars printed instead of OK
- spr 754: vararg routines no longer limited to 16 args
- fixed coercions to allow void to be defined as void one day.
- 01q,26jun90,jcf lint.
- 01p,12mar90,jcf changed std{in,out,err} to macros to fps in tcbx.
- 01o,16feb90,dab fixed bug in doscan() that wouldn't match characters between
- the input stream and the format specification.
- 01n,03aug89,dab removed call to creat() in fopen().
- 01m,08apr89,dnw changed stdioInit() to call taskVarInit().
- 01l,23mar89,dab changed numerical constants to appropriate defines.
- fixed fseek() to return only OK or ERROR.
- 01k,15nov88,dnw documentation touchup.
- 01j,23sep88,gae documentation touchup.
- 01i,13sep88,gae removed ifdef'd sprintf which got into documentation.
- 01h,06sep88,gae adjusted some argument declarations to please f2cgen.
- 01g,20aug88,gae documentation.
- 01f,07jul88,jcf changed malloc to match new declaration.
- 01e,29jun88,gae documentation. Added error messages in stioInit().
- 01d,22jun88,dnw name tweaks.
- 01c,30may88,dnw changed to v4 names.
- 01b,28may88,dnw removed routines that had been excluded with "#if FALSE".
- made stdioFlushBuf LOCAL.
- cleaned up stdio{Init,Exit}Task; improved error msgs.
- 01a,28mar88,gae created.
- */
- /*
- DESCRIPTION
- This library provides a complete UNIX compatible standard I/O buffering
- scheme. It is beyond the scope of this manual entry to describe all aspects
- of the buffering -- see the
- .I "VxWorks Programmer's Guide: I/O System"
- and the Kernighan & Ritchie C manual. This manual entry primarily highlights
- the differences between the UNIX and VxWorks standard I/O.
- FILE POINTERS
- The routine fopen() creates a file pointer. Use of the file pointer follows
- conventional UNIX usage. In a shared address space, however, and perhaps more
- critically, with the VxWorks system symbol table, tasks may not use each
- others' file pointers, at least not without some interlocking mechanism. If it
- is necessary to use the same name for a file pointer but have incarnations for
- each task, then use task variables; see the manual entry for taskVarLib.
- FIOLIB
- Several routines normally considered part of standard I/O -- printf(),
- sscanf(), and sprintf() -- are not implemented in stdio; they are
- instead implemented in fioLib. They do not use the standard I/O buffering
- scheme. They are self-contained, formatted, but unbuffered I/O
- functions. This allows a limited amount of formatted I/O to be achieved
- without the overhead of the stdio library.
- TASK TERMINATION
- When a task exits, unlike in UNIX, it is the responsibility of the task to
- fclose() its file pointers, except `stdin', `stdout', and `stderr'. If a
- task is to be terminated asynchronously, use kill() and arrange for a
- signal handler to clean up.
- INCLUDE FILES
- stdio.h, taskLib.h
- All the macros defined in stdio.h are also implemented as real functions so
- that they are available from the VxWorks shell.
- SEE ALSO
- fioLib, ioLib, taskVarLib, sigLib, Kernighan & Ritchie C manual,
- .pG "I/O System"
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "sys/types.h"
- #include "ctype.h"
- #include "ioLib.h"
- #include "stdlib.h"
- #include "taskLib.h"
- #include "taskHookLib.h"
- #include "stdarg.h"
- #include "logLib.h"
- #include "fcntl.h"
- #include "unistd.h"
- #include "errnoLib.h"
- #include "string.h"
- #include "fioLib.h"
- #include "classLib.h"
- #include "private/objLibP.h"
- #include "private/stdioP.h"
- #include "private/funcBindP.h"
- /* locals */
- LOCAL OBJ_CLASS fpClass; /* file object class */
- LOCAL BOOL stdioInitialized = FALSE;
- /* global variables */
- CLASS_ID fpClassId = &fpClass; /* file class id */
- /*******************************************************************************
- *
- * stdioInit - initialize standard I/O support
- *
- * This routine installs standard I/O support. It must be called before
- * using `stdio' buffering. If INCLUDE_STDIO is defined in configAll.h, it
- * is called automatically by the root task usrRoot() in usrConfig.c.
- *
- * RETURNS:
- * OK, or ERROR if the standard I/O facilities cannot be installed.
- */
- STATUS stdioInit (void)
- {
- if ((!stdioInitialized) &&
- (classInit (fpClassId, sizeof (FILE), OFFSET (FILE, objCore),
- (FUNCPTR) NULL, (FUNCPTR) NULL, (FUNCPTR) NULL) == OK))
- {
- _func_fclose = fclose; /* attach fclose vfunc to taskLib */
- stdioInitialized = TRUE; /* we've finished the initialization */
- }
- return (OK);
- }
- /*******************************************************************************
- *
- * stdioFpCreate - allocate a new FILE structure
- *
- * RETURNS:
- * The pointer to newly created file, or NULL if out of memory.
- *
- * NOMANUAL
- */
- FILE *stdioFpCreate (void)
- {
- FAST FILE *fp = NULL;
- if ((stdioInit () == OK) &&
- ((fp = (FILE *)objAlloc (fpClassId)) != NULL))
- {
- fp->_p = NULL; /* no current pointer */
- fp->_r = 0;
- fp->_w = 0; /* nothing to read or write */
- fp->_flags = 1; /* caller sets real flags */
- fp->_file = -1; /* no file */
- fp->_bf._base = NULL; /* no buffer */
- fp->_bf._size = 0;
- fp->_lbfsize = 0; /* not line buffered */
- fp->_ub._base = NULL; /* no ungetc buffer */
- fp->_ub._size = 0;
- fp->_lb._base = NULL; /* no line buffer */
- fp->_lb._size = 0;
- fp->_blksize = 0;
- fp->_offset = 0;
- fp->taskId = (int) taskIdCurrent; /* task id might be useful */
- objCoreInit (&fp->objCore, fpClassId); /* validate file object */
- }
- return (fp);
- }
- /*******************************************************************************
- *
- * stdioFpDestroy - destroy and reclaim resources of specified file pointer
- *
- * RETURNS:
- * OK, or ERROR if file pointer could not be destroyed.
- *
- * NOMANUAL
- */
- STATUS stdioFpDestroy
- (
- FILE *fp
- )
- {
- /* fclose() deallocates any buffers associated with the file pointer */
- objCoreTerminate (&fp->objCore); /* invalidate file pointer */
- return (objFree (fpClassId, (char *) fp)); /* deallocate file pointer */
- }
- /*******************************************************************************
- *
- * stdioInitStd - initialize use of a standard file
- */
- LOCAL STATUS stdioInitStd
- (
- int stdFd /* standard file descriptor to initialize (0,1,2) */
- )
- {
- FILE *fp;
- if ((fp = stdioFpCreate ()) == NULL)
- return (ERROR);
- switch (stdFd)
- {
- case STD_IN: fp->_flags = __SRD; break; /* read only */
- case STD_OUT: fp->_flags = __SWR; break; /* write only */
- case STD_ERR: fp->_flags = __SWRNBF; break; /* write only unbuf'd */
- }
- fp->_file = stdFd; /* standard fd */
- taskIdCurrent->taskStdFp[stdFd] = fp; /* init private file pointer */
- return (OK);
- }
- /******************************************************************************
- *
- * stdioFp - return the standard input/output/error FILE of the current task
- *
- * This routine returns the specified standard FILE structure address of the
- * current task. It is provided primarily to give access to standard input,
- * standard output, and standard error from the shell, where the usual
- * `stdin', `stdout', `stderr' macros cannot be used.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS: The standard FILE structure address of the specified file
- * descriptor, for the current task.
- */
- FILE * stdioFp
- (
- int stdFd /* fd of standard FILE to return (0,1,2) */
- )
- {
- if (taskIdCurrent->taskStdFp [stdFd] == NULL)
- stdioInitStd (stdFd);
- return (taskIdCurrent->taskStdFp [stdFd]);
- }
- /*******************************************************************************
- *
- * __stdin - get pointer to current task's stdin
- *
- * This function returns a pointer to the current task's stdin. If the
- * current task does not have a stdin then one is created.
- *
- * NOMANUAL
- */
- FILE ** __stdin (void)
- {
- if (taskIdCurrent->taskStdFp [STD_IN] == NULL)
- stdioInitStd (STD_IN);
- return (&taskIdCurrent->taskStdFp [STD_IN]);
- }
- /*******************************************************************************
- *
- * __stdout - get pointer to current task's stdout
- *
- * This function returns a pointer to the current task's stdout. If the
- * current task does not have a stdout then one is created.
- *
- * NOMANUAL
- */
- FILE ** __stdout (void)
- {
- if (taskIdCurrent->taskStdFp [STD_OUT] == NULL)
- stdioInitStd (STD_OUT);
- return (&taskIdCurrent->taskStdFp [STD_OUT]);
- }
- /*******************************************************************************
- *
- * __stderr - get pointer to current task's stderr
- *
- * This function returns a pointer to the current task's stderr. If the
- * current task does not have a stderr then one is created.
- *
- * NOMANUAL
- */
- FILE ** __stderr (void)
- {
- if (taskIdCurrent->taskStdFp [STD_ERR] == NULL)
- stdioInitStd (STD_ERR);
- return (&taskIdCurrent->taskStdFp [STD_ERR]);
- }
- /* stdioShow.c - standard I/O show library */
- /* Copyright 1984-1993 Wind River Systems, Inc. */
- #include "copyright_wrs.h"
- /*
- modification history
- --------------------
- 01f,17mar99,jdi doc: updated w/ info about proj facility (SPR 25727).
- 01e,16sep93,jmm cleaned up warnings about printf args
- 01d,15sep93,kdl fixed man page for stdioShowInit() (SPR #2244).
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf created.
- */
- /*
- DESCRIPTION
- This library provides a show routine for file pointers.
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "sys/types.h"
- #include "stdlib.h"
- #include "taskLib.h"
- #include "fioLib.h"
- #include "classLib.h"
- #include "errnoLib.h"
- #include "private/objLibP.h"
- #include "private/stdioP.h"
- /******************************************************************************
- *
- * stdioShowInit - initialize the standard I/O show facility
- *
- * This routine links the file pointer show routine into the VxWorks system.
- * It is called automatically when this show facility is
- * configured into VxWorks using either of the following methods:
- * .iP
- * If you use the configuration header files, define
- * INCLUDE_SHOW_ROUTINES in config.h.
- * .iP
- * If you use the Tornado project facility, select INCLUDE_STDIO_SHOW.
- *
- * RETURNS: OK, or ERROR if an error occurs installing the file pointer show
- * routine.
- */
- STATUS stdioShowInit (void)
- {
- classShowConnect (fpClassId, (FUNCPTR)stdioShow);
- return (OK);
- }
- /*******************************************************************************
- *
- * stdioShow - display file pointer internals
- *
- * This routine displays information about a specified stream.
- *
- * RETURNS: OK, or ERROR if the file pointer is invalid.
- */
- STATUS stdioShow
- (
- FAST FILE * fp, /* stream */
- int level /* level */
- )
- {
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return (ERROR); /* invalid file pointer */
- printf ("%-20s: %#-10xn", "Owning Task", fp->taskId);
- printf ("%-20s: %-10hdn", "File Descriptor", fp->_file);
- printf ("%-20s: %#-10xn", "Current Position", (unsigned int) fp->_p);
- printf ("%-20s: %#-10xn", "Read Space Left", fp->_r);
- printf ("%-20s: %#-10xn", "Write Space Left", fp->_w);
- printf ("%-20s: %#-10xn", "Buffer Base", (unsigned int) fp->_bf._base);
- printf ("%-20s: %#-10xn", "Buffer Size", fp->_bf._size);
- printf ("%-20s: %#-10xn", "Ungetc Buffer Base",
- (unsigned int) fp->_ub._base);
- printf ("%-20s: %#-10xn", "Ungetc Buffer Size", fp->_ub._size);
- printf ("%-20s: %#-10xn", "Line Buffer Base", (unsigned int) fp->_lb._base);
- printf ("%-20s: %#-10xn", "Line Buffer Size", fp->_lb._size);
- printf ("%-20s: %#-10xn", "stat.st_blksize", fp->_blksize);
- printf ("%-20s: %#-10xn", "lseek Offset", fp->_offset);
- printf ("%-20s: %#-10hxn", "Flags", fp->_flags);
- /* someday display the buffer contents with level >= 1 */
- return (OK);
- }
- /* tmpfile.c - creat a temporary file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01d,05mar93,jdi documentation cleanup for 5.1.
- 01c,21sep92,smb tweaks for mg.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb written.
- */
- /*
- DESCRIPTION
-
- INCLUDE FILE: stdio.h, string.h
-
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- /*******************************************************************************
- *
- * tmpfile - create a temporary binary file (Unimplemented) (ANSI)
- *
- * This routine is not be implemented
- * because VxWorks does not close all open files at task exit.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS: NULL
- */
- FILE * tmpfile (void)
- {
- return (NULL);
- }
- /* tmpnam.c - devise a temporary name. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01d,23sep93,jmm made tmpnam()'s buffer static (spr 2525)
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,smb written.
- */
- /*
- DESCRIPTION
- INCLUDE FILE: stdio.h, string.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "string.h"
- /******************************************************************************
- *
- * tmpnam - generate a temporary file name (ANSI)
- *
- * This routine generates a string that is a valid file name and not the same
- * as the name of an existing file. It generates a different string each
- * time it is called, up to TMP_MAX times.
- *
- * If the argument is a null pointer, tmpnam() leaves its
- * result in an internal static object and returns a pointer to that
- * object. Subsequent calls to tmpnam() may modify the same
- * object. If the argument is not a null pointer, it is assumed to
- * point to an array of at least L_tmpnam chars; tmpnam() writes
- * its result in that array and returns the argument as its value.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS: A pointer to the file name.
- */
- char * tmpnam
- (
- char * s /* name buffer */
- )
- {
- int index;
- char * pos;
- ushort_t t;
- static char buf [L_tmpnam]; /* internal buffer for name */
- static ushort_t seed = 0; /* used to generate unique name */
- /* if parameter is NULL use internal buffer */
- if (s == NULL)
- s = buf;
- /* generate unique name */
- strcpy (s, "tmp");
- /* fill up the name buffer from the last position */
- index = 5;
- pos = s + strlen (s) + index;
- *pos = ' ';
- seed++;
- for (t = seed; 0 <= --index; t >>= 3)
- *--pos = '0' + (t & 07);
- /* return name buffer */
- return (s);
- }
- /* ungetc.c - return a character to a stream. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h, stdlib.h, string.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "objLib.h"
- #include "private/stdioP.h"
- /******************************************************************************
- *
- * __submore - internal routine
- *
- * 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).
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * NOMANUAL
- */
- static int __submore
- (
- FAST FILE *fp
- )
- {
- FAST int i;
- FAST uchar_t * 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, i << 1);
- if (p == NULL)
- return (EOF);
- (void) bcopy ((void *)p, (void *)(p + i), (size_t)i);
- fp->_p = p + i;
- fp->_ub._base = p;
- fp->_ub._size = i << 1;
- return (0);
- }
- /******************************************************************************
- *
- * ungetc - push a character back into an input stream (ANSI)
- *
- * This routine pushes a character <c> (converted to an `unsigned char') back
- * into the specified input stream. The pushed-back characters will be
- * returned by subsequent reads on that stream in the reverse order of their
- * pushing. A successful intervening call on the stream to a file
- * positioning function (fseek(), fsetpos(), or rewind()) discards any
- * pushed-back characters for the stream. The external storage corresponding
- * to the stream is unchanged.
- *
- * One character of push-back is guaranteed. If ungetc() is called too many
- * times on the same stream without an intervening read or file positioning
- * operation, the operation may fail.
- *
- * If the value of <c> equals EOF, the operation fails and the
- * input stream is unchanged.
- *
- * A successful call to ungetc() clears the end-of-file indicator for the
- * stream. The value of the file position indicator for the stream after
- * reading or discarding all pushed-back characters is the same as it was
- * before the character were pushed back. For a text stream, the value of
- * its file position indicator after a successful call to ungetc() is
- * unspecified until all pushed-back characters are read or discarded.
- * For a binary stream, the file position indicator is decremented by each
- * successful call to ungetc(); if its value was zero before a call, it is
- * indeterminate after the call.
- *
- * INCLUDE: stdio.h
- *
- * RETURNS:
- * The pushed-back character after conversion, or EOF if the operation fails.
- *
- * SEE ALSO: getc(), fgetc()
- */
- int ungetc
- (
- int c, /* character to push */
- FAST FILE * fp /* input stream */
- )
- {
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return (EOF);
- if (c == EOF)
- return (EOF);
- 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)
- return (EOF);
- if (fp->_flags & __SWR)
- {
- if (__sflush(fp))
- return (EOF);
- fp->_flags &= ~__SWR;
- fp->_w = 0;
- fp->_lbfsize = 0;
- }
- fp->_flags |= __SRD;
- }
- c = (uchar_t) 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))
- return (EOF);
- *--fp->_p = c;
- fp->_r++;
- return (c);
- }
- /*
- * 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++;
- 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;
- return (c);
- }
- /* vfprintf.c - print to a file. stdio.h */
- /* Copyright 1992-1993 Wind River Systems, Inc. */
- /*
- modification history
- --------------------
- 01c,05mar93,jdi documentation cleanup for 5.1.
- 01b,20sep92,smb documentation additions
- 01a,29jul92,jcf Added OBJ_VERIFY, use fioFormatV()
- +smb taken from UCB stdio
- */
- /*
- DESCRIPTION
- * Copyright (c) 1990 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.
- INCLUDE FILE: stdio.h, stdarg.h
- SEE ALSO: American National Standard X3.159-1989
- NOMANUAL
- */
- #include "vxWorks.h"
- #include "stdarg.h"
- #include "fioLib.h"
- #include "objLib.h"
- #include "private/stdioP.h"
- /* forward declarations */
- LOCAL STATUS putbuf (char *buffer, int nbytes, FILE *fp);
- /*******************************************************************************
- *
- * vfprintf - write a formatted string to a stream (ANSI)
- *
- * This routine is equivalent to fprintf(), except that it takes the variable
- * arguments to be formatted from a list <vaList> of type `va_list' rather
- * than from in-line arguments.
- *
- * INCLUDE FILES: stdio.h
- *
- * RETURNS:
- * The number of characters written, or a negative value if an
- * output error occurs.
- *
- * SEE ALSO: fprintf()
- */
- int vfprintf
- (
- FILE * fp, /* stream to write to */
- const char * fmt, /* format string */
- va_list vaList /* arguments to format string */
- )
- {
- uchar_t localbuf[BUFSIZE];
- int ret;
- FILE fake;
- if (OBJ_VERIFY (fp, fpClassId) != OK)
- return (EOF);
- if (cantwrite (fp))
- return (EOF);
- if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && fp->_file >= 0)
- {
- /*
- * This optimizes an fprintf to unbuffered unix file by creating a
- * temporary buffer. This avoids worries about ungetc buffers and
- * so forth. It is particularly useful for stderr.
- */
- fake._flags = fp->_flags & ~__SNBF; /* turn on buffering */
- fake._file = fp->_file; /* store fd */
- fake._bf._base = fake._p = localbuf; /* set up the buffer */
- fake._bf._size = fake._w = sizeof(localbuf); /* initialize size */
- fake._lbfsize = 0; /* init to be safe */
- fake._r = 0; /* init to be safe */
- fake._ub._base = NULL; /* init to be safe */
- fake._ub._size = 0; /* init to be safe */
- fake._lb._base = NULL; /* init to be safe */
- fake._lb._size = 0; /* init to be safe */
- objCoreInit (&fake.objCore, fpClassId); /* validate fake fp */
- ret = fioFormatV (fmt, vaList, putbuf, (int) &fake);
- if ((ret >= 0) && fflush (&fake))
- ret = EOF;
- if (fake._flags & __SERR)
- fp->_flags |= __SERR;
- objCoreTerminate (&fake.objCore); /* invalidate fp */
- }
- else
- {
- ret = fioFormatV (fmt, vaList, putbuf, (int) fp);
- ret = (ferror (fp)) ? EOF : ret;
- }
- return (ret);
- }
- /*******************************************************************************
- *
- * putbuf - put a buffer on an output stream
- * NOMANUAL
- */
- LOCAL STATUS putbuf
- (
- char * buffer, /* source */
- int nbytes, /* number of bytes in source */
- FILE * fp /* stream */
- )
- {
- FAST int ix;
- for (ix = 0; ix < nbytes; ix++)
- putc (buffer [ix], fp);
- return (OK);
- }