Date: Sat, 17 Feb 2018 22:18:39 +0000 (UTC) From: Conrad Meyer <cem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329474 - head/stand/liblua Message-ID: <201802172218.w1HMId5X094464@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: cem Date: Sat Feb 17 22:18:39 2018 New Revision: 329474 URL: https://svnweb.freebsd.org/changeset/base/329474 Log: 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 Modified: head/stand/liblua/lstd.c head/stand/liblua/lstd.h Modified: head/stand/liblua/lstd.c ============================================================================== --- head/stand/liblua/lstd.c Sat Feb 17 22:17:21 2018 (r329473) +++ head/stand/liblua/lstd.c Sat Feb 17 22:18:39 2018 (r329474) @@ -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) { Modified: head/stand/liblua/lstd.h ============================================================================== --- head/stand/liblua/lstd.h Sat Feb 17 22:17:21 2018 (r329473) +++ head/stand/liblua/lstd.h Sat Feb 17 22:18:39 2018 (r329474) @@ -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)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802172218.w1HMId5X094464>