⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ansistdio.c

📁 vxworks libc库源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
** SEE ALSO: fread(), fgetc()*/char * fgets    (    char *	buf,	/* where to store characters */    FAST size_t n,	/* no. of bytes to read + 1 */    FAST FILE *	fp	/* stream to read from */    )    {    FAST size_t		len;    FAST char *		s;    FAST uchar_t *      p;    FAST uchar_t *      t;    if (OBJ_VERIFY (fp, fpClassId) != OK)	return (NULL);    if (n < 2)				/* sanity check */	return (NULL);    s = buf;    n--;				/* leave space for NULL */    do 	{	if ((len = fp->_r) <= 0)	/* If the buffer is empty, refill it */	    {	    if (__srefill(fp))		/* EOF/error: partial or no line */		{		if (s == buf)		    return (NULL);		break;		}	    len = fp->_r;	    }	p = fp->_p;	/*	 * Scan through at most n bytes of the current buffer,	 * looking for '\n'.  If found, copy up to and including	 * newline, and stop.  Otherwise, copy entire chunk	 * and loop.	 */	if (len > n)	    len = n;	t = memchr ((void *)p, '\n', len);	if (t != NULL) 	    {	    len = ++t - p;	    fp->_r -= len;	    fp->_p = t;	    (void) bcopy ((void *)p, (void *)s, len);	    s[len] = 0;	    return (buf);	    }	fp->_r -= len;	fp->_p += len;	(void) bcopy ((void *)p, (void *)s, len);	s += len;	} while ((n -= len) != 0);    *s = 0;    return (buf);    }/* fileno.c - determine file number for stdio.h *//* Copyright 1992-1993 Wind River Systems, Inc. */ /*modification history--------------------01c,05mar93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,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.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "objLib.h"#include "private/stdioP.h"#undef fileno/******************************************************************************** fileno - return the file descriptor for a stream (POSIX)* * This routine returns the file descriptor associated with a specified* stream.** INCLUDE FILES: stdio.h ** RETURNS:* The file descriptor, or -1 if an error occurs, with `errno' set to indicate* the error.** SEE ALSO:* .br* .I "Information Technology - POSIX - Part 1:"* .I "System API [C Language], IEEE Std 1003.1"*/int fileno    (    FILE *	fp	/* stream */    )    {    if (OBJ_VERIFY (fp, fpClassId) != OK)	return (ERROR);    return (__sfileno(fp));    }/* fopen.c - open a file. stdio.h *//* Copyright 1992-1995 Wind River Systems, Inc. *//*modification history--------------------01d,10feb95,jdi  doc format tweak.01c,05mar93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,29jul92,jcf  modified to use stdioFpCreate and close memory leaks.	    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.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/ #include "vxWorks.h"#include "stdio.h"#include "sys/types.h"#include "sys/stat.h"#include "ioLib.h"#include "fcntl.h"#include "errno.h"#include "private/stdioP.h"/******************************************************************************** fopen - open a file specified by name (ANSI)** This routine opens a file whose name is the string pointed to by <file>* and associates a stream with it.* The argument <mode> points to a string beginning with one of the following * sequences:* .iP r "" 3* open text file for reading* .iP w* truncate to zero length or create text file for writing* .iP a* append; open or create text file for writing at end-of-file* .iP rb* open binary file for reading* .iP wb* truncate to zero length or create binary file for writing* .iP ab* append; open or create binary file for writing at end-of-file* .iP r+* open text file for update (reading and writing)* .iP w+* truncate to zero length or create text file for update.* .iP a+* append; open or create text file for update, writing at end-of-file* .iP "r+b / rb+"* open binary file for update (reading and writing)* .iP "w+b / wb+"* truncate to zero length or create binary file for update* .iP "a+b / ab+"* append; open or create binary file for update, writing at end-of-file* .LP** Opening a file with read mode (`r' as the first character in the <mode>* argument) fails if the file does not exist or cannot be read.** Opening a file with append mode (`a' as the first character in the <mode>* argument) causes all subsequent writes to the file to be forced to the* then current end-of-file, regardless of intervening calls to fseek().  In* some implementations, opening a binary file with append mode (`b' as the* second or third character in the <mode> argument) may initially position* the file position indicator for the stream beyond the last data written,* because of null character padding.  In VxWorks, whether append mode is* supported is device-specific.** When a file is opened with update mode (`+' as the second or third* character in the <mode> argument), both input and output may be performed* on the associated stream.  However, output may not be directly followed by* input without an intervening call to fflush() or to a file positioning* function (fseek(), fsetpos(), or rewind()), and input may not be directly* followed by output without an intervening call to a file positioning* function, unless the input operation encounters end-of-file.  Opening (or* creating) a text file with update mode may instead open (or create) a* binary stream in some implementations.** When opened, a stream is fully buffered if and only if it can be determined* not to refer to an interactive device.  The error and end-of-file* indicators for the stream are cleared.* * INCLUDE FILES: stdio.h ** RETURNS:* A pointer to the object controlling the stream, or a null pointer if the* operation fails.** SEE ALSO: fdopen(), freopen()*/FILE * fopen    (    const char *	file,	/* name of file */    const char *	mode	/* mode */    )    {    FAST FILE *	fp;    FAST int	f;    int		flags;    int		oflags;    if ((flags = __sflags (mode, &oflags)) == 0)	return (NULL);    if ((fp = stdioFpCreate ()) == NULL)	return (NULL);    if ((f = open (file, oflags, DEFFILEMODE )) < 0) 	{ 	fp->_flags = 0x0;			/* release */        stdioFpDestroy (fp);			/* destroy file pointer */	return (NULL);	}    fp->_file	= f;    fp->_flags	= flags;    /*     * When opening in append mode, even though we use O_APPEND,     * we need to seek to the end so that ftell() gets the right     * answer.  If the user then alters the seek pointer, or     * the file extends, this will fail, but there is not much     * we can do about this.  (We could set __SAPP and check in     * fseek and ftell.)     */    if (oflags & O_APPEND)	(void) __sseek ((void *)fp, (fpos_t)0, SEEK_END);    return (fp);    }/* fprintf.c - print to a file. stdio.h *//* Copyright 1992-1995 Wind River Systems, Inc. *//*modification history--------------------01e,24jan95,rhp  doc: avoid 'L' in fprintf(), no long doubles                  in VxWorks (see SPR#3886)01d,19jul94,dvs  doc tweak (SPR #2512).01c,05mar93,jdi  documentation cleanup for 5.1.01b,20sep92,smb  documentation additions01a,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. *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -