nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

seek.h (485B)


      1 #ifndef SEEK_H
      2 #define SEEK_H
      3 
      4 #include <sys/types.h>
      5 #include <unistd.h>
      6 
      7 typedef off_t seek_pos;
      8 
      9 #define seek_cur(fd) (lseek((fd), 0, SEEK_CUR))
     10 
     11 static inline int seek_set(int fd, seek_pos pos)
     12 {
     13   if (lseek(fd, pos, SEEK_SET) == -1)
     14     return -1;
     15   return 0;
     16 }
     17 
     18 
     19 static inline int seek_end(int fd)
     20 {
     21   if (lseek(fd, 0, SEEK_END) == -1)
     22     return -1;
     23   return 0;
     24 }
     25 
     26 #define seek_trunc(fd, pos) (ftruncate((fd),(pos)))
     27 #define seek_begin(fd) (seek_set((fd),(seek_pos) 0))
     28 
     29 #endif