File: ibuf_seek.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (26 lines) | stat: -rw-r--r-- 572 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include "ibuf.h"

/** Set the effective read position. */
int ibuf_seek(ibuf* in, unsigned offset)
{
  iobuf* io;
  unsigned buf_start;
  
  io = &(in->io);
  buf_start = io->offset - io->buflen;
  if (offset >= buf_start && offset <= io->offset)
    io->bufstart = offset - buf_start;
  else {
    if (lseek(io->fd, offset, SEEK_SET) != (off_t)offset)
      IOBUF_SET_ERROR(io);
    io->offset = offset;
    io->buflen = 0;
    io->bufstart = 0;
  }
  in->count = 0;
  io->flags &= ~IOBUF_EOF;
  return 1;
}