📄 ansistdio.c
字号:
/* ansiStdio.c - ANSI `stdio' documentation *//* Copyright 1984-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01j,21jan02,jkf SPR#72774, fread is checking for NULL on wrong arg01i,12dec01,jkf fixing SPR#72128, fread should check for NULL before bcopy.01h,11nov01,jkf SPR#70967, fread() returns wrong value when 3rd arg == 001g,17mar99,jdi doc: updated w/ info about proj facility (SPR 25727).01f,04feb99,dgp document errno values01e,10feb95,jdi doc format tweak in fopen() and update for rhp changes in 01d.01d,24jan95,rhp doc: avoid 'L' in fprintf() and fscanf(), no long doubles in VxWorks (see SPR#3886)01c,19jul94,dvs doc tweak (SPR #2512)01b,05mar93,jdi documentation cleanup for 5.1.01a,24oct92,smb created.*//*DESCRIPTIONThe header stdio.h declares three types, several macros, and many functionsfor performing input and output..SS TypesThe types declared are `size_t' and:.iP `FILE' 12object type capable of recording all the information needed tocontrol a stream, including its file position indicator, a pointer to itsassociated buffer (if any), an error indicator that records whether aread/write error has occurred, and an end-of-file indicator that recordswhether the end of the file has been reached..iP `fpos_t'object type capable of recording all the information needed tospecify uniquely every position within a file..SS MacrosThe macros are NULL and:.iP "_IOFBF, _IOLBF, _IONBF" 12 3expand to integral constant expressions with distinct values, suitablefor use as the third argument to setvbuf()..iP BUFSIZexpands to an integral constant expression that is the size of thebuffer used by setbuf()..iP EOFexpands to a negative integral constant expression that is returned byseveral functions to indicate `end-of-file', that is, no more input from astream..iP FOPEN_MAXexpands to an integral constant expression that is the minimum number ofthe files that the system guarantees can be open simultaneously..iP FILENAME_MAXexpands to an integral constant expression that is the size needed for anarray of `char' large enough to hold the longest file name string thatcan be used..iP L_tmpnamexpands to an integral constant expression that is the size needed foran array of `char' large enough to hold a temporary file name stringgenerated by tmpnam()..iP "SEEK_CUR, SEEK_END, SEEK_SET"expand to integral constant expressions with distinct values suitablefor use as the third argument to fseek()..iP TMP_MAXexpands to an integral constant expression that is the minimum number offile names generated by tmpnam() that will be unique..iP "`stderr', `stdin', `stdout'"expressions of type "pointer to FILE" that point to the FILE objectsassociated, respectively, with the standard error, input, and output streams.STREAMSInput and output, whether to or from physical devices such as terminals andtape drives, or whether to or from files supported on structured storagedevices, are mapped into logical data streams, whose properties are moreuniform than their various inputs and outputs. Two forms of mapping aresupported: for text streams and for binary streams.A text stream is an ordered sequence of characters composed into lines,each line consisting of zero or more characters plus a terminating new-linecharacter. Characters may have to be added, altered, or deletedon input and output to conform to differing conventions for representingtext in the host environment. Thus, there is no need for a one-to-onecorrespondence between the characters in a stream and those in the externalrepresentation. Data read in from a text stream will necessarily compareequal to the data that were earlier written out to that stream only if:the data consists only of printable characters and the control charactershorizontal tab and new-line; no new-line character is immediately precededby space characters; and the last character is a new-line character.Space characters are written out immediately before a new-line characterappears.A binary stream is an ordered sequence of characters that can transparentlyrecord internal data. Data read in from a binary stream should compareequal to the data that was earlier written out to that stream, under thesame implementation. However, such a stream may have anumber of null characters appended to the end of the stream..SS "Environmental Limits"VxWorks supports text files with lines containing at least 254 characters,including the terminating new-line character. The value of the macroBUFSIZ is 1024.FILESA stream is associated with an external file (which may be a physicaldevice) by opening a file, which may involve creating a new file.Creating an existing file causes its former contents to be discarded, ifnecessary. If a file can support positioning requests (such as a diskfile, as opposed to a terminal), then a file position indicator associatedwith the stream is positioned at the start (character number zero) of thefile. The file position indicator is maintained by subsequent reads,writes, and positioning requests, to facilitate an orderly progressionthrough the file. All input takes place as if characters were read bysuccessive calls to fgetc(); all output takes place as if characters werewritten by successive calls to fputc().Binary files are not truncated, except as defined in fopen() documentation.When a stream is unbuffered, characters are intended to appear from thesource or at the destination as soon as possible. Otherwise charactersmay be accumulated and transmitted to or from the host environment as ablock. When a stream is fully buffered, characters are intended to betransmitted to or from the host environment as a block when the buffer isfilled. When a stream is line buffered, characters are intended to betransmitted to or from the host environment as a block when a new-linecharacter is encountered. Furthermore, characters are intended to betransmitted as a block to the host environment when a buffer is filled,when input is requested on an unbuffered stream, or when input is requested ona line-buffered stream that requires the transmission of characters fromthe host environment. VxWorks supports these characteristics via thesetbuf() and setvbuf() functions.A file may be disassociated from a controlling stream by closing the file.Output streams are flushed (any unwritten buffer contents are transmittedto the host environment) before the stream is disassociated from the file.The value of a pointer to a FILE object is indeterminate after the associatedfile is closed (including the standard text streams).The file may be subsequently reopened, by the same or another programexecution, and its contents reclaimed or modified (if it can be repositionedat its start).TASK TERMINATIONANSI specifies that if the main function returns to its original caller orif exit() is called, all open files are closed (and hence all outputstreams are flushed) before program termination. This does \f3not\fPhappen in VxWorks. The exit() function does not close all files openedfor that task. A file opened by one task may be used and closed by another.Unlike in UNIX, when a VxWorks task exits, it is the responsibility of thetask to fclose() its file pointers, except `stdin', `stdout', and`stderr'. If a task is to be terminated asynchronously, use kill() andarrange for a signal handler to clean up.The address of the FILE object used to control a stream may be significant;a copy of a FILE object may not necessarily serve in place of the original.At program startup, three text streams are predefined and need not be openedexplicitly: standard input (for reading conventional input), standard output(for writing conventional output), and standard error (for writing diagnosticoutput). When opened, the standard error stream is not fully buffered; thestandard input and standard output streams are fully buffered if and only ifthe stream can be determined not to refer to an interactive device.Functions that open additional (non-temporary) files require a file name,which is a string. VxWorks allows the same file to be open multiple timessimultaneously. It is up to the user to maintain synchronization betweendifferent tasks accessing the same file.FIOLIBSeveral routines normally considered part of standard I/O -- printf(),sprintf(), vprintf(), vsprintf(), and sscanf() -- are not implemented as partof the buffered standard I/O library; they areinstead implemented in fioLib. They do not use the standard I/O bufferingscheme. They are self-contained, formatted, but unbuffered I/Ofunctions. This allows a limited amount of formatted I/O to be achievedwithout the overhead of the standard I/O library.SEE ALSO:fioLib,.I "American National Standard for Information Systems -".I "Programming Language - C, ANSI X3.159-1989: Input/Output (stdio.h)INTERNALThis documentation module is built by appending the following files: clearerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c fgetpos.c fgets.c fileno.c fopen.c fprintf.c fputc.c fputs.c fread.c freopen.c fscanf.c fseek.c fsetpos.c ftell.c fwrite.c getc.c getchar.c gets.c getw.c perror.c putc.c putchar.c puts.c putw.c rewind.c scanf.c setbuf.c setbuffer.c setvbuf.c stdioLib.c stdioShow.c tmpfile.c tmpnam.c ungetc.c vfprintf.c*//* clearerr.c - clear error file for stdio.h *//* Copyright 1992-1993 Wind River Systems, Inc. *//* modification history -------------------- 01d,05mar93,jdi documentation cleanup for 5.1.01c,21sep92,smb corrected first line of file.01b,20sep92,smb documentation additions01a,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.*NOMANUAL*/#include "vxWorks.h"#include "stdio.h"#undef clearerr/******************************************************************************** clearerr - clear end-of-file and error flags for a stream (ANSI)* * This routine clears the end-of-file and error flags for a specified stream.** INCLUDE FILES: stdio.h ** RETURNS: N/A** SEE ALSO: feof(), ferror()*/void clearerr ( FILE * fp /* stream to clear EOF and ERROR flags for */ ) { __sclearerr(fp); }/* fclose.c - close file 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 and memory reclaimation. +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, error.hSEE ALSO: American National Standard X3.159-1989NOMANUAL*/#include "vxWorks.h"#include "stdio.h"#include "errno.h"#include "stdlib.h"#include "objLib.h"#include "private/stdioP.h"/*******************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -