From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 122639 invoked by alias); 11 Oct 2018 08:22:54 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 116684 invoked by uid 10080); 11 Oct 2018 08:22:49 -0000 Date: Thu, 11 Oct 2018 08:22:00 -0000 Message-ID: <20181011082249.116677.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Add generic implementation of fdopendir() X-Act-Checkin: newlib-cygwin X-Git-Author: Sebastian Huber X-Git-Refname: refs/heads/master X-Git-Oldrev: ab4fdab5d555504a90191959546142f797913d84 X-Git-Newrev: 103b055035fea328f8bc7826801760fb1c055683 X-SW-Source: 2018-q4/txt/msg00015.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=103b055035fea328f8bc7826801760fb1c055683 commit 103b055035fea328f8bc7826801760fb1c055683 Author: Sebastian Huber Date: Mon Oct 8 13:52:14 2018 +0200 Add generic implementation of fdopendir() Signed-off-by: Sebastian Huber Diff: --- newlib/libc/posix/opendir.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/newlib/libc/posix/opendir.c b/newlib/libc/posix/opendir.c index 650cbfe..2cf1ba5 100644 --- a/newlib/libc/posix/opendir.c +++ b/newlib/libc/posix/opendir.c @@ -43,17 +43,11 @@ static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91"; #include #include -/* - * open a directory. - */ -DIR * -opendir (const char *name) +static DIR * +_opendir_common(int fd) { DIR *dirp; - int fd; - if ((fd = open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1) - return NULL; if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) { close (fd); return NULL; @@ -87,4 +81,23 @@ opendir (const char *name) return dirp; } +DIR * +opendir(const char *name) +{ + int fd; + + if ((fd = open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1) + return (NULL); + return (_opendir_common(fd)); +} + +DIR * +fdopendir(int fd) +{ + + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) + return (NULL); + return (_opendir_common(fd)); +} + #endif /* ! HAVE_OPENDIR */