fseek.c

来自「操作系统源代码」· C语言 代码 · 共 45 行

C
45
字号
/* * fseek.c - perform an fseek *//* $Header: fseek.c,v 1.4 90/01/22 11:12:00 eck Exp $ */#include	<stdio.h>#if	(SEEK_CUR != 1) || (SEEK_END != 2) || (SEEK_SET != 0)#error SEEK_* values are wrong#endif#include	"loc_incl.h"#include	<sys/types.h>off_t _lseek(int fildes, off_t offset, int whence);intfseek(FILE *stream, long int offset, int whence){	int adjust = 0;	long pos;	stream->_flags &= ~(_IOEOF | _IOERR);	/* Clear both the end of file and error flags */	if (io_testflag(stream, _IOREADING)) {		if (whence == SEEK_CUR		    && stream->_buf		    && !io_testflag(stream,_IONBF))			adjust = stream->_count;		stream->_count = 0;	} else if (io_testflag(stream,_IOWRITING)) {		fflush(stream);	} else	/* neither reading nor writing. The buffer must be empty */		/* EMPTY */ ;	pos = _lseek(fileno(stream), offset - adjust, whence);	if (io_testflag(stream, _IOREAD) && io_testflag(stream, _IOWRITE))		stream->_flags &= ~(_IOREADING | _IOWRITING);	stream->_ptr = stream->_buf;	return ((pos == -1) ? -1 : 0);}

⌨️ 快捷键说明

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