liblua: Emulate DIR, opendir, fdopendir, closedir
In a similar fashion to FILE, provide thin shims for the standard directory manipulation functions. Reviewed by: imp Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D14417
This commit is contained in:
parent
68bc0c038d
commit
0a4cda7bf6
@ -127,6 +127,42 @@ getc(FILE *stream)
|
||||
return EOF;
|
||||
}
|
||||
|
||||
DIR *
|
||||
opendir(const char *name)
|
||||
{
|
||||
DIR *dp;
|
||||
int fd;
|
||||
|
||||
fd = open(name, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
dp = fdopendir(fd);
|
||||
if (dp == NULL)
|
||||
close(fd);
|
||||
return dp;
|
||||
}
|
||||
|
||||
DIR *
|
||||
fdopendir(int fd)
|
||||
{
|
||||
DIR *dp;
|
||||
|
||||
dp = malloc(sizeof(*dp));
|
||||
if (dp == NULL)
|
||||
return NULL;
|
||||
dp->fd = fd;
|
||||
return dp;
|
||||
}
|
||||
|
||||
int
|
||||
closedir(DIR *dp)
|
||||
{
|
||||
close(dp->fd);
|
||||
dp->fd = -1;
|
||||
free(dp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
luai_writestring(const char *s, int i)
|
||||
{
|
||||
|
@ -43,6 +43,11 @@ typedef struct FILE
|
||||
size_t size;
|
||||
} FILE;
|
||||
|
||||
typedef struct DIR
|
||||
{
|
||||
int fd;
|
||||
} DIR;
|
||||
|
||||
FILE *fopen(const char *filename, const char *mode);
|
||||
FILE *freopen( const char *filename, const char *mode, FILE *stream);
|
||||
size_t fread(void *ptr, size_t size, size_t count, FILE *stream);
|
||||
@ -50,6 +55,9 @@ int fclose(FILE *stream);
|
||||
int ferror(FILE *stream);
|
||||
int feof(FILE *stream);
|
||||
int getc(FILE * stream);
|
||||
DIR *opendir(const char *name);
|
||||
DIR *fdopendir(int fd);
|
||||
int closedir(DIR *);
|
||||
|
||||
#ifndef EOF
|
||||
#define EOF (-1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user