문제

I'm currently programming my own implementation of fseek function and I want to ask on what happens in several causes. Here they are:

  1. If seek origin is set to SEEK_SET or SEEK_CUR and result of next position exceeds file size?
  2. If seek origin is set to SEEK_END and result of next position is less than 0

Is the file resized for position to fit in it, or is there some error code returned (what happens then with position pointer)?

Please help.

도움이 되었습니까?

해결책

Try man fseek to get more details:

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.

Upon successful completion, fgetpos(), fseek(), fsetpos() return 0, and ftell() returns the current offset. Otherwise, -1 is returned and errno is set to indicate the error.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top