From owner-svn-src-head@freebsd.org Sat Feb 17 22:18:40 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 72E6CF15731; Sat, 17 Feb 2018 22:18:40 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 279D46FDB4; Sat, 17 Feb 2018 22:18:40 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 220D422BBE; Sat, 17 Feb 2018 22:18:40 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1HMIeQG094466; Sat, 17 Feb 2018 22:18:40 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1HMId5X094464; Sat, 17 Feb 2018 22:18:39 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201802172218.w1HMId5X094464@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Sat, 17 Feb 2018 22:18:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r329474 - head/stand/liblua X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/stand/liblua X-SVN-Commit-Revision: 329474 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Feb 2018 22:18:40 -0000 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)