home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixtools
/
util
/
c
/
dir
< prev
next >
Wrap
Text File
|
1992-07-21
|
1KB
|
65 lines
/* C.Dir: Directory handling */
#include "kernel.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "sys/dir.h"
#define ReadDir 9
#define OS_GBPB 0x0C
DIR *opendir (char *name)
{
register DIR *dirp;
dirp = malloc(sizeof(DIR) + strlen(name));
if ( dirp == 0 )
return NULL;
dirp->dd_loc = 0;
if ( *name )
strcpy(dirp->dd_name,name);
else
strcpy(dirp->dd_name,"@");
return dirp;
}
struct direct *readdir (DIR *dirp)
{
static struct direct dir;
_kernel_swi_regs regs;
if ( dirp->dd_loc == -1 )
return NULL;
regs.r[0] = ReadDir;
regs.r[1] = (int)dirp->dd_name;
regs.r[2] = (int)&dir.d_name;
regs.r[3] = 1;
regs.r[4] = (int)dirp->dd_loc;
regs.r[5] = MAXNAMELEN+1;
regs.r[6] = (int)"*";
if ( _kernel_swi(OS_GBPB,®s,®s) != NULL )
return NULL;
dir.d_ino = 0;
dir.d_reclen = dir.d_namlen = strlen(dir.d_name);
dirp->dd_loc = regs.r[4];
if ( regs.r[3] == 0 )
return NULL;
else
return &dir;
}
extern void closedir (DIR *dirp)
{
if ( dirp != NULL )
free(dirp);
}