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

📄 sio.3

📁 牛顿插值方法求解多项式的系数
💻 3
字号:
.\"(c) Copyright 1992, 1993 by Panagiotis Tsirigotis.\"All rights reserved.  The file named COPYRIGHT specifies the terms .\"and conditions for redistribution..\".\" $Id: sio.3,v 1.1.1.1 2003/02/19 17:29:27 bbraun Exp $.TH SIO 3X "29 May 1992".SH NAMESread, Sgetc, Srdline, Sfetch, Swrite, Sputc, Sprint, Sprintv, Sdone, Sundo, Stie, Suntie, Sflush, Sclose, Sbuftype, Smorefds, Sgetchar, Sputchar, SIOLINELEN - fast stream I/O.SH SYNOPSIS.LP.nf.ft B#include "sio.h"#include <stdarg.h>.LP.ft Bint Sread( fd, buf, nbytes )int fd ;char *buf ;int nbytes ;.LP.ft Bint Sgetc( fd )int fd ;.LP.ft Bchar *Srdline( fd )int fd ;.LP.ft Bchar *Sfetch( fd, length )int fd ;long *length ;.LP.ft Bint Swrite( fd, buf, nbytes )int fd ;char *buf ;int nbytes ;.LP.ft Bint Sputc( fd, c )int fd ;char c ;.LP.ft Bint Sprint( fd, format [ , ... ] )int fd ;char *format ;.LP.ft Bint Sprintv( fd, format, ap )int fd ;char *format ;va_list ap ;.LP.ft Bint Sdone( fd )int fd ;.LP.ft Bint Sundo( fd, type )int fd ;int type ;.LP.ft Bint Stie( ifd, ofd )int ifd, ofd ;.LP.ft Bint Suntie( fd )int fd ;.LP.ft Bint Sbuftype( fd, type )int fd, type ;.LP.ft Bint Smorefds().LP.ft Bint Sflush( fd )int fd ;.LP.ft Bint Sclose( fd )int fd ;.LP.ft Bint Sgetchar( fd )int fd ;.LP.ft Bint Sputchar( fd, c )int fd;char c ;.LP.ft Bint SIOLINELEN( fd )int fd ;.SH DESCRIPTIONThe \fISIO\fR library provides supportfor \fIstream\fR I/O on file descriptors.The first argument of every functionor macro is a file descriptor. The file descriptor may be used either forinput or for output but not both. Attempting to use a descriptor forboth input and output will cause the call to fail. When you aredone with using a file descriptor, you should inform \fISIO\fRby invoking \fBSdone()\fR (unless the program is about to call \fIexit(3)\fR).You can also use \fBSdone()\fR ifyou want to perform a different type of operation on the samefile descriptor (e.g. first you were reading data from the filedescriptor and then you want to write some data).Another possibility is to do stream I/O at different file offsetsby using \fBSdone()\fR before doing the \fBlseek(2)\fR to thenew file offset..LPI/O operations on different file descriptors do not interfere(unless the file descriptors refer to the same file, in which casethe results are undefined)..LPFor disk files I/O always starts at the current file offset.If that offset is not a multiple of the preferred block size for filesystem I/O (the \fIst_blksize\fR field in \fIstruct stat\fR),performance will not be optimal.For optimal performance, it is recommended that no I/O operations(like \fIread(2)\fR or \fIwrite(2)\fR)are applied to the file descriptor if it is to be used by \fISIO\fR..LPRead I/O is either buffered or is done using memory mapping wheneverthat is possible and appropriate..LPThe library functions that do stream I/O resemble system calls(for example \fBSread()\fR resembles \fIread(2)\fR) so that modifyinga program that uses the system calls to use the \fISIO\fR functionsis easy (e.g. just replace \fIread(2)\fR with \fBSread()\fR; the functionsignatures as well as the return values are exactly the same)..LP.B Sread()reads \fInbytes\fR bytes from the stream associated with file descriptor \fIfd\fR into the buffer pointed to by \fIbuf\fR..LP.B Sgetc()reads a character from the streamassociated with file descriptor \fIfd\fR.It returns \fBSIO_EOF\fR if the end of file has been reached..LP.B Sgetchar()(a macro) performs exactly the same function as \fBSgetc()\fR butit is much faster..LP.B Srdline()reads a line from the streamassociated with file descriptor \fIfd\fR.The newline at the end of the line is replaced by a 0 byte. Lineslonger than the maximum line length supported by \fISIO\fR willhave characters deleted..LP.B SIOLINELEN()(a macro) returns the length ofthe line returned by the last call to \fBSrdline()\fR(the value returned by \fBSIOLINELEN()\fR is valid only after\fBSrdline()\fR and as long as no other \fISIO\fR calls are performed on that file descriptor)..LP.B Sfetch()returns a pointer to data coming from the streamassociated with filedescriptor \fIfd\fR. The amount of data available is indicatedby the \fIlength\fR argument. One possible use for this functionis copying of files..LP.B Swrite()writes \fInbytes\fR bytes to the stream associated with filedescriptor \fIfd\fR from the buffer pointed to by \fIbuf\fR..LP.B Sputc()writes a single character to the streamassociated with file descriptor \fIfd\fR..LP.B Sputchar()(a macro) performs exactly the same function as \fBSputc()\fRbut it is much faster..LP.B Sprint()imitates the behavior of printf(3) as defined in theANSI C Standard. There are some limitations. Check the \fBSprint()\fRman page for more information..LP.B Sprintv()is the same as \fBSprint()\fR except that it takes a\fIstdarg\fR argument list..LP.B Sundo()returns the characters returned by the last call to\fBSrdline()\fR, \fBSgetc()\fR or \fBSgetchar()\fR to the streamso that they can be reread. The \fItype\fR argument to \fBSundo()\fRcan be \fBSIO_UNDO_LINE\fR or \fBSIO_UNDO_CHAR\fR dependingon whether the call whose effect needs to be undone was\fBSrdline()\fR or \fBSgetc()\fR/\fBSgetchar()\fR respectively.There is no check onwhether the last function invoked on \fIfd\fR was one of the aboveand the results are undefined if there is no correspondencebetween the \fItype\fR and the last operation on \fIfd\fR.(i.e. the result is undefined if you try \fBSIO_UNDO_CHAR\fR and the last operation was not \fBSgetchar()\fR or \fBSgetc()\fR)..LP.B Stie()ties the file descriptor \fIifd\fR to the file descriptor \fIofd\fR.This means that whenever a \fIread(2)\fR is done on \fIifd\fR, it ispreceded by a \fIwrite(2)\fR on \fIofd\fR.For filters it is useful to do \fIStie( 0, 1 )\fR to maximize concurrency.It is also useful to do the same thing when you issue prompts to theuser and you want the user reply to appear on the same line with theprompt.\fIifd\fR, \fIofd\fR  will be initialized for input, output respectively(if any of them is initialized, it must be for the appropriatestream type (input or output)).If \fIifd\fR was tied to another file descriptor, the old tie is broken..LP.B Suntie()undoes the effect of \fBStie()\fR for the specified input file descriptor..LP.B Sbuftype()determines the buffering type for the output stream associated withfile descriptor \fIfd\fR.By default output directed to terminals is line buffered, outputdirected to file descriptor 2 (standard error) is unbuffered andeverything else is fully buffered.Possible values for the \fItype\fR argument are.RS.TP 15.B SIO_FULLBUFfor full buffering.TP.B SIO_LINEBUFfor line buffering.TP.B SIO_NOBUFfor no buffering.RE.LP.B Smorefds()should be used to inform \fBSIO\fR that the number of available filedescriptors has been increased. \fBSIO\fR uses an array of internalstream descriptors which are indexed by the file descriptor number. Someoperating systems (ex. SunOS 4.1[.x]) allow the number of availablefile descriptors to vary. If that number is increased beyond its initialvalue \fBSIO\fR needs to know in order to allocate more stream descriptors..LP.B Sdone()flushes any buffered output for \fIfd\fR and releases the \fISIO\fR resources used. \fBSdone()\fR is useful in case the program needs to reprocess thedata of a file descriptor (assuming the file descriptor correspondsto a file).  The program can call \fBSdone()\fR,\fIlseek(2)\fR to the beginning of the fileand then proceed to reread the file..LP.B Sflush()causes any buffered stream output to be written to thefile descriptor. If its argument is the special value \fBSIO_FLUSH_ALL\fRthen all output streams will be flushed..LP.B Sclose()closes a file descriptor used for stream I/O, flushesany buffered output and releases the \fISIO\fR resources used..SH EXAMPLES.LPThe following code implements a (poor) substitute for the tee command(it copies standard input to a file as well as to standard output)..ne 10.RS.nf.ft B#include "sio.h".sp .5main( argc, argv )	int argc ;	char *argv[] ;{	char *file = (argc > 1) ? argv[ 1 ] : "tee.file" ;	int fd = creat( file, 0644 ) ;	long length ;	char *s ;.sp .5	while ( s = Sfetch( 0, &length ) )	{		Swrite( 1, s, length ) ;		Swrite( fd, s, length ) ;	}	exit( 0 ) ;}.fi.ft R.RE.SH RETURN VALUES.LP.B Sread()returns the number of bytes read on success(0 means end-of-file)or \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Sgetc()returns the character read on success,SIO_EOF when the end-of-file is reached,or \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Srdline()returns a pointer to the next line on success.On failure or when the end-of-file is reached it returns.SM NULL.If the end-of-file is reached \fIerrno\fR is set to 0, otherwise it indicatesthe error..LP.B Sfetch()returns a pointer to file data on success.(the \fIlength\fR argument indicates how many bytesare available).On failure or when the end-of-file is reached it returns.SM NULL.If the end-of-file is reached \fIerrno\fR is set to 0, otherwise it indicatesthe error..LP.B Swrite()returns the number of bytes written on successor \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Sputc()returns the character it was given as an argument on success.B Sprint()returns the number of characters printed on successor \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Sdone()returns \fB0\fR on successor \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Sundo()returns \fB0\fR on successor \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Stie()returns \fB0\fR on successor \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Suntie()returns \fB0\fR on successor \fBSIO_ERR\fR on failure(\fIerrno\fR is set to \fBEBADF\fR if therewas no tied file descriptor)..LP.B Sbuftype()returns \fB0\fR on successor \fBSIO_ERR\fR on failure(\fIerrno\fR is set to \fBEBADF\fR if this is not an output streamor to \fBEINVAL\fR if an unknown \fItype\fR is specified)..LP.B Smorefds()returns \fB0\fR on successor \fBSIO_ERR\fR on failure (because of lack of memory)..LP.B Sflush()returns \fB0\fR on successor \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Sclose()returns \fB0\fR on successor \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Sgetchar()returns the character read on success,SIO_EOF when the end-of-file is reached,or \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B Sputchar()returns the character it was given as an argument on successor \fBSIO_ERR\fR on failure (\fIerrno\fR is set to indicate the error)..LP.B SIOLINELEN()returns the length of the last line read by \fBSrdline()\fR..LPAttempting a read operation on a descriptor opened for writing or viceversa will cause the operation to fail with \fIerrno\fR set to \fBEBADF\fR..LPThe first \fISIO\fR operation on a descriptor must be a read or writeoperation. It cannot be a control operation (like \fBSflush()\fR). Suchan operation will fail with \fIerrno\fR set to \fBEBADF\fR..LP.IP "\fBNOTE 1:\fR" 15\fBStie()\fR is an input/output operation for therespective file descriptors, not a control operation. \fBSuntie()\fRis a control operation..IP "\fBNOTE 2:\fR"\fBSIO_ERR\fR is defined to be \fB-1\fR..SH "SEE ALSO".LPSprint(3).SH BUGS.LPIf the operating system does not provide for invocation of afinalization function upon exit, the program will have toexplicitly flush all output streams.The following operating systems provide such a facility:SunOS 4.x, Ultrix 4.x..LPSocket file descriptors can be used for input as well as output but\fBSIO\fR does not support this..LPThe current implementation will not try to use memory mapping toread a file if the file offset is not 0 (it will use buffered I/O instead)..LPPointers returned by \fBSfetch()\fR point to read-only memory.Attempting to modify this memory will result in a segmentationviolation.

⌨️ 快捷键说明

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