public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Sebastian Huber <sh@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin] Add generic implementation of fdopendir()
Date: Thu, 11 Oct 2018 08:22:00 -0000	[thread overview]
Message-ID: <20181011082249.116677.qmail@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=103b055035fea328f8bc7826801760fb1c055683

commit 103b055035fea328f8bc7826801760fb1c055683
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Mon Oct 8 13:52:14 2018 +0200

    Add generic implementation of fdopendir()
    
    Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>

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 <unistd.h>
 #include <sys/lock.h>
 
-/*
- * 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 */


                 reply	other threads:[~2018-10-11  8:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181011082249.116677.qmail@sourceware.org \
    --to=sh@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).