rewind 中文man頁(yè)面
NAME
fgetpos, fseek, fsetpos, ftell, rewind - 重定位某個(gè)流
總覽 (SYNOPSIS)
#include <stdio.h>
int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
void rewind(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, fpos_t *pos);
描述 (DESCRIPTION)
函數(shù) fseek 設(shè)置 stream 流 的 文件位置 標(biāo)志. 新的 文件位置 (以 字節(jié) 為 單位) 根據(jù) whence 指定的 文件位置 加上 offset 獲得. 如果 whence 設(shè)置為 SEEK_SET, SEEK_CUR, 或 SEEK_END, 則 對(duì)應(yīng)的 文件位置 分別是 文件開(kāi)始, 當(dāng)前位置, 或 文件末尾. 成功 調(diào)用 fseek 后, 函數(shù) 清除 流 的 文件末尾 標(biāo)志(end-of-file), 同時(shí) 消除 ungetc(3) 函數(shù) 對(duì) 流 的 影響.
ftell 函數(shù) 能夠 獲取 stream 流 的 當(dāng)前 文件位置.
rewind 函數(shù) 把 stream 流 的 文件位置 設(shè)置到 文件開(kāi)始處. 它 等效于:
- (void)fseek(stream, 0L, SEEK_SET)
另外 它 還能 清除 流 的 錯(cuò)誤標(biāo)志 (見(jiàn) clearerr(3)).
fgetpos 和 fsetpos 函數(shù) 相當(dāng)于 ftell 和 fseek (whence 設(shè)置 為 SEEK_SET) 的 另一種 寫法, 讀取 當(dāng)前 文件位置 并 保存在 pos 中, 或用 pos 指向的值 設(shè)置 當(dāng)前 文件位置. 在 某些 非UNIX系統(tǒng) 中, fpos_t 可以 是 一種 復(fù)雜的 (數(shù)據(jù))對(duì)象, 因而 這兩個(gè)函數(shù) 大概是 *** 可移植的 流定位函數(shù).
返回值 (RETURN VALUE)
rewind 函數(shù) 沒(méi)有 返回值. 如果 操作 成功, fgetpos, fseek, fsetpos 返回 0, 而 ftell 返回 當(dāng)前 偏移 (當(dāng)前 文件位置), 否則 返回 -1, 并 設(shè)置 全局變量 errno, 指出 錯(cuò)誤 類型.
錯(cuò)誤 (ERRORS)
- EBADF
- stream 流 不是 可重定位的 流 (non-seekable stream).
- EINVAL
- fseek 的 whence 參數(shù) 不是 SEEK_SET, SEEK_END, 或 SEEK_CUR.
fgetpos, fseek, fsetpos, 和 ftell 函數(shù) 也可能 失敗后, 把 errno 設(shè)置為 fflush(3), fstat(2), lseek(2), 和 malloc(3) 的 錯(cuò)誤 類型.
遵循 (CONFORMING TO)
fgetpos, fsetpos, fseek, ftell, 和 rewind 函數(shù) 遵循 ANSI X3.159-1989 (``ANSI C'') 標(biāo)準(zhǔn).
另見(jiàn) (SEE ALSO)
lseek(2), fseeko(3)
#p#
NAME
fgetpos, fseek, fsetpos, ftell, rewind - reposition a stream
SYNOPSIS
#include <stdio.h>
int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
void rewind(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, fpos_t *pos);
DESCRIPTION
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.
The ftell function obtains the current value of the file position indicator for the stream pointed to by stream.
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:
- (void)fseek(stream, 0L, SEEK_SET)
except that the error indicator for the stream is also cleared (see clearerr(3)).
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 may be the only way to portably reposition a text stream.
RETURN VALUE
The rewind function returns no value. Upon successful completion, fgetpos, fseek, fsetpos return 0, and ftell returns the current offset. Otherwise, -1 is returned and the global variable errno is set to indicate the error.
ERRORS
- EBADF
- The stream specified is not a seekable stream.
- EINVAL
- The whence argument to fseek was not SEEK_SET, SEEK_END, or SEEK_CUR.
The function fgetpos, fseek, fsetpos, and ftell may also fail and set errno for any of the errors specified for the routines fflush(3), fstat(2), lseek(2), and malloc(3).
CONFORMING TO
The fgetpos, fsetpos, fseek, ftell, and rewind functions conform to ANSI X3.159-1989 (``ANSI C'').
SEE ALSO
lseek(2), fseeko(3)