summaryrefslogtreecommitdiff
path: root/src/seek.c
blob: d03b7984ed7898c71e5ea54cd95d764b64880e83 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "seek.h"

#include <sys/types.h>

/**
  @file seek.c
  @author djb
  @ref qmail
  @brief seek in an open file descritor
*/

off_t lseek(int fd, off_t offset, int whence);
int ftruncate(int fd, off_t length);

#define CUR 1 /* sigh */

seek_pos seek_cur(int fd)
{
  return lseek(fd, (off_t)0, CUR);
}

#define END 2 /* sigh */

int seek_end(int fd)
{
  if (lseek(fd, (off_t)0, END) == -1) return -1;
  return 0;
}

#define SET 0 /* sigh */

int seek_set(int fd, seek_pos pos)
{
  if (lseek(fd, (off_t)pos, SET) == -1) return -1;
  return 0;
}

int seek_trunc(int fd, seek_pos pos)
{
  return ftruncate(fd, (off_t)pos);
}