I use this simple program to test seekdir

#include <assert.h>
#include <dirent.h>
#include <stdio.h>
#include <sys/types.h>


int main(int argc, char** argv)
{
    off_t offset;
    DIR* pDir;
    struct dirent* pDirent;

    assert (argc == 2);
    printf ("Opening dir: %s\n", argv[1]);
    pDir = opendir(argv[1]);

    pDirent = readdir(pDir);
    printf("1st entry: %s \n", pDirent->d_name);
    pDirent = readdir(pDir);
    printf("2nd entry: %s \n", pDirent->d_name);
    pDirent = readdir(pDir);
    if (pDirent == NULL)
        return 1;
    printf("3rd entry: %s\n", pDirent->d_name);
    offset = telldir(pDir);
    printf("The offset (telldir) for the 4th entry is %d,\n", offset);
    pDirent = readdir(pDir);
    if (pDirent == NULL)
        return 1;
    printf("4th entry: %s\n", pDirent->d_name);
    pDirent = readdir(pDir);
    if (pDirent == NULL)
        return 1;
    printf("5th entry: %s\n", pDirent->d_name);
    pDirent = readdir(pDir);
    if (pDirent == NULL)
        return 1;
    printf("6th entry: %s\n", pDirent->d_name);
    printf("Using seekdir to get back to the 4th entry\n");
    seekdir(pDir, offset);
    pDirent = readdir(pDir);
    printf("4th entry (using seekdir): %s\n", pDirent->d_name);
    return 0;
}

and the output is

root@amber:/mnt/yaffs> ls
lost+found
root@amber:/mnt/yaffs> touch a b c d e f g
root@amber:/mnt/yaffs> ls -al
total 12
drw-rw-rw-  1 root root 2048 Jan  1 00:03 .
drwxr-xr-x  4 root root 4096 Mar 27  2007 ..
-rw-r--r--  1 root root    0 Jan  1 00:03 a
-rw-r--r--  1 root root    0 Jan  1 00:03 b
-rw-r--r--  1 root root    0 Jan  1 00:03 c
-rw-r--r--  1 root root    0 Jan  1 00:03 d
-rw-r--r--  1 root root    0 Jan  1 00:03 e
-rw-r--r--  1 root root    0 Jan  1 00:03 f
-rw-r--r--  1 root root    0 Jan  1 00:03 g
drw-rw-rw-  1 root root 2048 Jan  1 00:03 lost+found
root@amber:/mnt/yaffs> seekDirTest .
Opening dir: .
1st entry: .
2nd entry: ..
3rd entry: g
The offset (telldir) for the 4th entry is 3,
4th entry: f
5th entry: e
6th entry: d
Using seekdir to get back to the 4th entry
4th entry (using seekdir): f
root@amber:/mnt/yaffs> rm g
root@amber:/mnt/yaffs> seekDirTest .
Opening dir: .
1st entry: .
2nd entry: ..
3rd entry: f
The offset (telldir) for the 4th entry is 3,
4th entry: e
5th entry: d
6th entry: c
Using seekdir to get back to the 4th entry
4th entry (using seekdir): f
root@amber:/mnt/yaffs>

After deleting g, the 4th entry is f, but supposed to be e.

Anthony





Now that's room service! Choose from over 150,000 hotels
in 45,000 destinations on Yahoo! Travel
to find your fit.