📄 0927-0929.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Complete Command Reference:Library Functions:EarthWeb Inc.-</TITLE>
</HEAD>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311046 //-->
<!-- TITLE=Linux Complete Command Reference//-->
<!-- AUTHOR=Red Hat//-->
<!-- PUBLISHER=Macmillan Computer Publishing//-->
<!-- IMPRINT=Sams//-->
<!-- CHAPTER=03 //-->
<!-- PAGES=0891-1062 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0922-0926.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0930-0933.html">Next</A></CENTER></P>
<A NAME="PAGENUM-927"><P>Page 927</P></A>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <stdio.h>
size_t fread(void *ptr, size_t size, size_t nmemb,FILE*stream);
size_t fwrite(void *ptr, size_t size, size_t nmemb,FILE*stream);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The function fread reads nmemb elements of data, each
size bytes long, from the stream pointed to by
stream, storing them at the location given by ptr.</P>
<P>The function fwrite writes nmemb elements of data, each
size bytes long, to the stream pointed to by
stream, obtaining them from the location given by
ptr.</P>
<P><B>RETURN VALUE
</P></B>
<P>fread and fwrite return the number of items successfully read or written (that is, not the number of characters). If an
error occurs, or the end-of-file is reached, the return value is a short item count (or
0).</P>
<P>fread does not distinguish between end-of-file and error, and callers must use
feof(3) and ferror(3) to determine which occurred.</P>
<P></B>SEE ALSO
</P></B>
<P>feof(3), ferror(3), read(2), write(2)</P>
<P></B>STANDARDS
</P></B>
<P>The functions fread and fwrite conform to ANSI C3.159-1989 ("ANSI C").</P>
<P>BSD Man Page, 17 May 1996</P>
<H3><A NAME="ch03_ 70">
frexp
</A></H3>
<P>frexp—Converts floating-point number to fractional and integral components</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <math.h>
double frexp(double x, int *exp);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The frexp() function is used to split the number
x into a normalized fraction and an exponent that is stored in
exp.</P>
<P><B>RETURN VALUE
</P></B>
<P>The frexp() function returns the normalized fraction. If the argument
x is not 0, the normalized fraction is x times a
power of 2, and is always in the range <SUP>1</SUP>
¦<SUB>2</SUB> (inclusive) to 1 (exclusive). If
x is 0, the normalized fraction is 0, and 0 is stored in
exp.</P>
<P><B>CONFORMS TO
</P></B>
<P>SVID 3, POSIX, BSD 4.3, ISO 9899</P>
<P></B>SEE ALSO
</P></B>
<P>ldexp(3), modf(3)</P>
<P>GNU, 6 June 1993</P>
<H3><A NAME="ch03_ 71">
fgetpos, fseek, fsetpos, ftell, rewind
</A></H3>
<P>fgetpos, fseek, fsetpos, ftell, rewind—Reposition a stream</P>
<A NAME="PAGENUM-928"><P>Page 928</P></A>
<P><B>SYNOPSIS
</P></B>
<!-- CODE //-->
<PRE>
#include <stdio.h>
int fseek(FILE *stream, longo ffset, int whence);
long ftell(FILE *stream);
void rewind(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, fpos_t *pos);
</PRE>
<!-- END CODE //-->
<P><B>DESCRIPTION
</P></B>
<P>The fseek function sets the file position indicator for the stream pointed to by
stream. The new position, measured in bytes, is obtained by adding offset bytes to the position specified by
whence. If whence is set to SEEK_SET, SEEK_CUR, or
SEEK_END, the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively. A successful call to the
fseek function clears the end-of-file indicator for the stream and undoes any effects of the
ungetc(3) function on the same stream.</P>
<P>The ftell function obtains the current value of the file position indicator for the stream pointed to by
stream.</P>
<P>The rewind function sets the file position indicator for the stream pointed to by
stream to the beginning of the file. It is equivalent to</P>
<!-- CODE SNIP //-->
<PRE>
(void)fseek(stream, 0L, SEEK_SET);
</PRE>
<!-- END CODE SNIP //-->
<P>except that the error indicator for the stream is also cleared. (See
clearerr(3).)</P>
<P>The fgetpos and fsetpos functions are alternate interfaces equivalent to
ftell and fseek (with whence set to SEEK_SET),
setting and storing the current value of the file offset into or from the object referenced by
pos. On some non-UNIX systems, an fpos_t object may be a complex object, and these routines might be the only way to portably reposition a text stream.</P>
<P><B>RETURN VALUE
</P></B>
<P>The rewind function returns no value. Upon successful completion,
fgetpos, fseek, and fsetpos return 0, and ftell
returns the current offset. Otherwise, _1 is returned, and the global variable
errno is set to indicate the error.</P>
<P><B>ERRORS
</P></B>
<TABLE>
<TR><TD>
EBADF
</TD><TD>
The stream specified is not a seekable stream.
</TD></TR><TR><TD>
EINVAL
</TD><TD>
The whence argument to fseek was not
SEEK_SET, SEEK_END, or SEEK_CUR.
</TD></TR></TABLE>
<P>The function fgetpos, fseek, fsetpos, and ftell might also fail and set
errno for any of the errors specified for the
routines fflush(3), fstat(2), lseek(2), and malloc(3).</P>
<P></B>SEE ALSO
</P></B>
<P>lseek(2)</P>
<P></B>STANDARDS
</P></B>
<P>The fgetpos, fsetpos, fseek, ftell, and rewind functions conform to ANSI C3.159-1989 (ANSI C).</P>
<P>BSD Man Page, 29 November 1993</P>
<H3><A NAME="ch03_ 72">
ftime
</A></H3>
<P>ftime—Returns date and time</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <sys/timeb.h>
int ftime(struct timeb *tp);
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-929"><P>Page 929</P></A>
<P><B>DESCRIPTION
</P></B>
<P>Return current date and time in tp, which is declared as follows:</P>
<!-- CODE SNIP //-->
<PRE>
struct timeb {
time_t time;
unsigned short millitm;
short timezone;
short dstflag;
};
</PRE>
<!-- END CODE SNIP //-->
<P><B>RETURN VALUE
</P></B>
<P>This function always returns 0.</P>
<P><B>NOTES
</P></B>
<P>Under Linux, this function is implemented in a compatibility library instead of in the kernel.</P>
<P><B>CONFORMS TO
</P></B>
<P>Version 7, BSD 4.3</P>
<P>Under BSD 4.3, this call is obsoleted by
gettimeofday(2).</P>
<P></B>SEE ALSO
</P></B>
<P>time(2)</P>
<P>Linux, 24 July 1993</P>
<H3><A NAME="ch03_ 73">
ftok
</A></H3>
<P>ftok—Converts a pathname and a project identifier to a System V IPC key</P>
<P><B>SYNOPSIS
</P></B>
<!-- CODE SNIP //-->
<PRE>
#include <sys/types.h>
#include <sys/ipc.h>
key_t ftok (char *pathname, char proj);
</PRE>
<!-- END CODE SNIP //-->
<P><B>DESCRIPTION
</P></B>
<P>The function converts the pathname of an existing accessible file and a project identifier into a
key_t type System V IPC key.</P>
<P><B>RETURN VALUE
</P></B>
<P>On success, the return value will be the converted
key_t value; otherwise it will be _1, with
errno indicating the error as for the stat(2) system call.</P>
<P><B>BUGS
</P></B>
<P>The generated key_t value is obtained by stating the disk file corresponding to
pathname in order to get its i_node number and the minor device number of the filesystem on which the disk file resides, then by combining the 8-bit
proj value along with the lower 16 bits of the inode number with the 8 bits of the minor device number. The algorithm does not guarantee
a unique key value. In fact,</P>
<UL>
<LI> Two different names linking to the same file produce the same key values.
<LI> Using the lower 16 bits of the i_node number gives some chance (although usually small) to have the same key
values for filenames referring to different inodes.
<LI> Not discriminating among major device numbers gives some chance of collision (also usually small) for systems
with multiple disk controllers.
</UL>
<P><CENTER>
<a href="0922-0926.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0930-0933.html">Next</A></CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -