2012-06-03 15:11:32 +00:00
|
|
|
/*
|
2014-07-17 11:05:10 +00:00
|
|
|
** 2012-06-03, Ullrich von Bassewitz. Based on code by Groepaz.
|
|
|
|
** 2014-07-16, Greg King
|
2014-06-30 09:10:35 +00:00
|
|
|
*/
|
2012-06-03 15:11:32 +00:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "dir.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void __fastcall__ seekdir (register DIR* dir, long offs)
|
|
|
|
{
|
|
|
|
unsigned o;
|
|
|
|
unsigned char count;
|
|
|
|
unsigned char buf[128];
|
|
|
|
|
2014-07-17 11:05:10 +00:00
|
|
|
/* Make sure that we have a reasonable value for offs. We reject
|
|
|
|
** negative numbers by converting them to (very high) unsigned values.
|
|
|
|
*/
|
|
|
|
if ((unsigned long)offs > 0x1000uL) {
|
2012-06-03 15:11:32 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the directory file descriptor */
|
|
|
|
close (dir->fd);
|
|
|
|
|
|
|
|
/* Reopen it using the old name */
|
|
|
|
dir->fd = open (dir->name, O_RDONLY);
|
|
|
|
if (dir->fd < 0) {
|
|
|
|
/* Oops! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip until we've reached the target offset in the directory */
|
2014-07-17 11:05:10 +00:00
|
|
|
o = dir->off = (unsigned)offs;
|
2012-06-03 15:11:32 +00:00
|
|
|
while (o) {
|
|
|
|
|
|
|
|
/* Determine size of next chunk to read */
|
2014-07-17 11:05:10 +00:00
|
|
|
if (o > sizeof (buf)) {
|
2012-06-03 15:11:32 +00:00
|
|
|
count = sizeof (buf);
|
|
|
|
o -= sizeof (buf);
|
|
|
|
} else {
|
2014-07-17 11:05:10 +00:00
|
|
|
count = (unsigned char)o;
|
2012-06-03 15:11:32 +00:00
|
|
|
o = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip */
|
|
|
|
if (!_dirread (dir, buf, count)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|