Line | |
---|
1 | /* seekdir() Author: Kees J. Bot
|
---|
2 | * 24 Apr 1989
|
---|
3 | */
|
---|
4 | #define nil 0
|
---|
5 | #include <lib.h>
|
---|
6 | #define lseek _lseek
|
---|
7 | #define readdir _readdir
|
---|
8 | #define seekdir _seekdir
|
---|
9 | #include <sys/types.h>
|
---|
10 | #include <dirent.h>
|
---|
11 | #include <unistd.h>
|
---|
12 | #include <errno.h>
|
---|
13 |
|
---|
14 | int seekdir(DIR *dp, off_t pos)
|
---|
15 | /* Seek to position pos in a directory. */
|
---|
16 | {
|
---|
17 | int off;
|
---|
18 |
|
---|
19 | if (dp == nil) { errno= EBADF; return -1; }
|
---|
20 |
|
---|
21 | dp->_count= 0;
|
---|
22 | dp->_ptr= dp->_buf;
|
---|
23 |
|
---|
24 | off= pos & (sizeof(dp->_buf) - 1);
|
---|
25 | dp->_pos= pos - off;
|
---|
26 |
|
---|
27 | if (lseek(dp->_fd, dp->_pos, SEEK_SET) == -1) return -1;
|
---|
28 |
|
---|
29 | while (dp->_pos < pos && readdir(dp) != nil) {}
|
---|
30 |
|
---|
31 | return 0;
|
---|
32 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.