home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
LIBSRC.ZOO
/
libsrc
/
local
/
opendir.c
< prev
next >
Wrap
Text File
|
1992-04-06
|
1KB
|
63 lines
#define INCL_DOSFILEMGR
#include <os2.h>
#define __DIRENT_PRIVATE__
#include <stdlib.h>
#ifdef DEBUG
#include <stdio.h>
#endif
#include <dirent.h>
ULONG Dos32FindFirst() asm ("Dos32FindFirst");
DIR *opendir(const char *dirname)
{
DIR *dir;
ULONG ret;
FILEFINDBUF3 buf;
unsigned long int cnt;
int namelen;
#ifdef DEBUG
fprintf(stderr, "opendir: starting\n");
#endif
dir = (DIR *) malloc(sizeof(DIR));
if (dir == NULL)
return NULL;
/* Remember to allocate enough bytes to hold the maximum number */
/* of characters that may be appended to the file name, plus a NULL */
namelen = strlen(dirname);
dir->searchname = (char *) malloc(namelen + 3);
if (dir->searchname == NULL) {
free(dir);
return NULL;
}
strcpy(dir->searchname, dirname);
if (dir->searchname[namelen-1] != '\\') {
strcat(dir->searchname, "\\");
namelen += 1;
}
strcat(dir->searchname, "*");
namelen += 1;
#ifdef DEBUG
fprintf(stderr, "opendir: calling findfirst, searchname = %s\n",
dir->searchname);
#endif
dir->reset = 1;
dir->dirhandle = HDIR_CREATE;
cnt = 1;
ret = Dos32FindFirst(dir->searchname, &dir->dirhandle,
DIRENT_ALLFILES, &buf, sizeof(buf), &cnt, 1);
if (ret != 0) {
free(dir->searchname);
free(dir);
return NULL;
} else
return dir;
}