home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
LIBSRC.ZOO
/
libsrc
/
local
/
readdir.c
< prev
next >
Wrap
Text File
|
1992-04-06
|
1KB
|
56 lines
#define INCL_DOSFILEMGR
#include <os2.h>
#define __DIRENT_PRIVATE__
#include <dirent.h>
#ifdef DEBUG
#include <stdio.h>
#endif
ULONG Dos32FindFirst() asm ("Dos32FindFirst");
ULONG Dos32FindNext() asm ("Dos32FindNext");
struct dirent *readdir(dir)
DIR *dir;
{
ULONG ret;
FILEFINDBUF3 buf;
ULONG cnt;
cnt = 1;
if (dir->reset) {
/* opendir() also calls DosFindFirst, so this is sometimes */
/* unnecessary */
#ifdef DEBUG
fprintf(stderr, "readdir: calling findfirst\n");
#endif
dir->reset = 0;
ret = Dos32FindFirst(dir->searchname, &dir->dirhandle,
DIRENT_ALLFILES, &buf, sizeof(buf), &cnt,
1);
} else {
#ifdef DEBUG
fprintf(stderr, "readdir: calling findnext\n");
#endif
ret = Dos32FindNext(dir->dirhandle, &buf, sizeof(buf), &cnt);
}
if (ret != 0 || cnt != 1)
return NULL;
else {
strcpy(dir->ent.d_name, buf.achName);
dir->ent.d_namelen = strlen(dir->ent.d_name);
dir->ent.d_reclen = dir->ent.d_namelen;
dir->ent.d_fileno = 0;
return &dir->ent;
}
}