_seekdir.c

Go to the documentation of this file.
00001 /*      seekdir()                                       Author: Kees J. Bot
00002  *                                                              24 Apr 1989
00003  */
00004 #define nil 0
00005 #include <lib.h>
00006 #define lseek   _lseek
00007 #define readdir _readdir
00008 #define seekdir _seekdir
00009 #include <sys/types.h>
00010 #include <dirent.h>
00011 #include <unistd.h>
00012 #include <errno.h>
00013 
00014 int seekdir(DIR *dp, off_t pos)
00015 /* Seek to position pos in a directory. */
00016 {
00017         int off;
00018 
00019         if (dp == nil) { errno= EBADF; return -1; }
00020 
00021         dp->_count= 0;
00022         dp->_ptr= dp->_buf;
00023 
00024         off= pos & (sizeof(dp->_buf) - 1);
00025         dp->_pos= pos - off;
00026 
00027         if (lseek(dp->_fd, dp->_pos, SEEK_SET) == -1) return -1;
00028 
00029         while (dp->_pos < pos && readdir(dp) != nil) {}
00030 
00031         return 0;
00032 }

Generated on Fri Apr 14 22:57:26 2006 for minix by  doxygen 1.4.6