Move the file position without fseek in C -


how can move file position x bytes in c?

i don't want use fseek(), because i'm reading lines of file open(fd, buf, buflength), not fopen().

i'd avoid reading entire file memory.

what want basically:

  1. read x + = y bytes.
  2. do first x bytes.
  3. move file pointer backwards bytes.
  4. read y bytes there.

i know how except step 3. know how?

according http://rabbit.eng.miami.edu/info/functions/unixio.html use lseek:

int lseek(int fd, int position, int startpoint)   include: <unistd.h>   sets file position effective next read or write operation.   fd = file descriptor returned open   position = position within file:     number of bytes between startpoint , desired position, may negative.   startpoint = location in file position relative to, 1 of:     seek_set        position number of bytes beginning of file     seek_end        position number of bytes after end of file     seek_cur        position number of bytes after current position   returns <0 error,     or resulting file position relative beginning of file.    moving beyond end of file permitted; file extended in length   if write occurs beyond current end of file. moving before   beginning of file not permitted. write operation after move   overwrites number of bytes written. 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -