Discussion:
[PATCH 6/6] Add generic implementation of fdopendir()
Sebastian Huber
2018-10-08 13:39:00 UTC
Permalink
Signed-off-by: Sebastian Huber <***@embedded-brains.de>
---
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 650cbfe8d..2cf1ba541 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 */
--
2.16.4
Sebastian Huber
2018-10-08 13:38:56 UTC
Permalink
Use O_RDONLY since you are not supposed to write to a directory.

Use O_DIRECTORY as mandated by POSIX (The Open Group Base Specifications
Issue 7, 2018 edition IEEE Std 1003.1-2017):

"If the type DIR is implemented using a file descriptor, the descriptor
shall be obtained as if the O_DIRECTORY flag was passed to open()."

Use O_CLOEXEC as mandated by POSIX:

"When a file descriptor is used to implement the directory stream, it
behaves as if the FD_CLOEXEC had been set for the file descriptor."

Drop the fcntl() call in favour of O_CLOEXEC.

Signed-off-by: Sebastian Huber <***@embedded-brains.de>
---
newlib/libc/posix/opendir.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/newlib/libc/posix/opendir.c b/newlib/libc/posix/opendir.c
index 1416f1053..650cbfe8d 100644
--- a/newlib/libc/posix/opendir.c
+++ b/newlib/libc/posix/opendir.c
@@ -49,17 +49,12 @@ static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91";
DIR *
opendir (const char *name)
{
- register DIR *dirp;
- register int fd;
- int rc = 0;
+ DIR *dirp;
+ int fd;

- if ((fd = open(name, 0)) == -1)
+ if ((fd = open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1)
return NULL;
-#ifdef HAVE_FCNTL
- rc = fcntl(fd, F_SETFD, 1);
-#endif
- if (rc == -1 ||
- (dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
+ if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
close (fd);
return NULL;
}
--
2.16.4
Corinna Vinschen
2018-10-10 09:50:19 UTC
Permalink
Post by Sebastian Huber
Use O_RDONLY since you are not supposed to write to a directory.
Use O_DIRECTORY as mandated by POSIX (The Open Group Base Specifications
"If the type DIR is implemented using a file descriptor, the descriptor
shall be obtained as if the O_DIRECTORY flag was passed to open()."
"When a file descriptor is used to implement the directory stream, it
behaves as if the FD_CLOEXEC had been set for the file descriptor."
Drop the fcntl() call in favour of O_CLOEXEC.
Yeah, that really makes sense, but what about targets not (yet)
implementing O_CLOEXEC??? I'm not sure how to handle this, if
we have to handle that at all.


Thoughts?
Corinna
Post by Sebastian Huber
---
newlib/libc/posix/opendir.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/newlib/libc/posix/opendir.c b/newlib/libc/posix/opendir.c
index 1416f1053..650cbfe8d 100644
--- a/newlib/libc/posix/opendir.c
+++ b/newlib/libc/posix/opendir.c
@@ -49,17 +49,12 @@ static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91";
DIR *
opendir (const char *name)
{
- register DIR *dirp;
- register int fd;
- int rc = 0;
+ DIR *dirp;
+ int fd;
- if ((fd = open(name, 0)) == -1)
+ if ((fd = open(name, O_RDONLY | O_DIRECTORY | O_CLOEXEC)) == -1)
return NULL;
-#ifdef HAVE_FCNTL
- rc = fcntl(fd, F_SETFD, 1);
-#endif
- if (rc == -1 ||
- (dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
+ if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
close (fd);
return NULL;
}
--
2.16.4
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber
2018-10-10 11:16:23 UTC
Permalink
Post by Corinna Vinschen
Post by Sebastian Huber
Use O_RDONLY since you are not supposed to write to a directory.
Use O_DIRECTORY as mandated by POSIX (The Open Group Base Specifications
"If the type DIR is implemented using a file descriptor, the descriptor
shall be obtained as if the O_DIRECTORY flag was passed to open()."
"When a file descriptor is used to implement the directory stream, it
behaves as if the FD_CLOEXEC had been set for the file descriptor."
Drop the fcntl() call in favour of O_CLOEXEC.
Yeah, that really makes sense, but what about targets not (yet)
implementing O_CLOEXEC??? I'm not sure how to handle this, if
we have to handle that at all.
In RTEMS there are no processes (fork(), exec(), etc. don't work). So,
it is trivial to support the O_CLOEXEC. The situation in which this flag
is relevant simply cannot happen.

Are Cygwin and Linux the only Newlib systems which supports processes?
--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : ***@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Corinna Vinschen
2018-10-10 11:35:49 UTC
Permalink
Post by Corinna Vinschen
Post by Sebastian Huber
Use O_RDONLY since you are not supposed to write to a directory.
Use O_DIRECTORY as mandated by POSIX (The Open Group Base Specifications
"If the type DIR is implemented using a file descriptor, the descriptor
shall be obtained as if the O_DIRECTORY flag was passed to open()."
"When a file descriptor is used to implement the directory stream, it
behaves as if the FD_CLOEXEC had been set for the file descriptor."
Drop the fcntl() call in favour of O_CLOEXEC.
Yeah, that really makes sense, but what about targets not (yet)
implementing O_CLOEXEC??? I'm not sure how to handle this, if
we have to handle that at all.
In RTEMS there are no processes (fork(), exec(), etc. don't work). So, it is
trivial to support the O_CLOEXEC. The situation in which this flag is
relevant simply cannot happen.
Are Cygwin and Linux the only Newlib systems which supports processes?
I really don't know, but the other problem is to use a flag in a target
dependent call which might be unsupported, but tested. This is backed
by POSIX allowing open to return EINVAL for invalid flags.

We should probably define _FNOINHERIT only on targets known to support
it (even if trivially) and to call open(O_CLOEXEC) or fcntl() depending
on that test, no?


Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber
2018-10-10 11:55:59 UTC
Permalink
Post by Corinna Vinschen
Post by Corinna Vinschen
Post by Sebastian Huber
Use O_RDONLY since you are not supposed to write to a directory.
Use O_DIRECTORY as mandated by POSIX (The Open Group Base Specifications
"If the type DIR is implemented using a file descriptor, the descriptor
shall be obtained as if the O_DIRECTORY flag was passed to open()."
"When a file descriptor is used to implement the directory stream, it
behaves as if the FD_CLOEXEC had been set for the file descriptor."
Drop the fcntl() call in favour of O_CLOEXEC.
Yeah, that really makes sense, but what about targets not (yet)
implementing O_CLOEXEC??? I'm not sure how to handle this, if
we have to handle that at all.
In RTEMS there are no processes (fork(), exec(), etc. don't work). So, it is
trivial to support the O_CLOEXEC. The situation in which this flag is
relevant simply cannot happen.
Are Cygwin and Linux the only Newlib systems which supports processes?
I really don't know, but the other problem is to use a flag in a target
dependent call which might be unsupported, but tested. This is backed
by POSIX allowing open to return EINVAL for invalid flags.
We should probably define _FNOINHERIT only on targets known to support
it (even if trivially) and to call open(O_CLOEXEC) or fcntl() depending
on that test, no?
POSIX says there is an O_CLOEXEC, so I think this is a valid oflag
value. An unsupported close on execute would be more an ENOSYS which is
not mentioned in the error list:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html

I would define the POSIX flags unconditionally and in case errors show
up on a particular system, then we can find a solution, e.g. not define
it on system X.
--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : ***@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Corinna Vinschen
2018-10-10 13:21:13 UTC
Permalink
Post by Corinna Vinschen
Post by Corinna Vinschen
Post by Sebastian Huber
Use O_RDONLY since you are not supposed to write to a directory.
Use O_DIRECTORY as mandated by POSIX (The Open Group Base Specifications
"If the type DIR is implemented using a file descriptor, the descriptor
shall be obtained as if the O_DIRECTORY flag was passed to open()."
"When a file descriptor is used to implement the directory stream, it
behaves as if the FD_CLOEXEC had been set for the file descriptor."
Drop the fcntl() call in favour of O_CLOEXEC.
Yeah, that really makes sense, but what about targets not (yet)
implementing O_CLOEXEC??? I'm not sure how to handle this, if
we have to handle that at all.
In RTEMS there are no processes (fork(), exec(), etc. don't work). So, it is
trivial to support the O_CLOEXEC. The situation in which this flag is
relevant simply cannot happen.
Are Cygwin and Linux the only Newlib systems which supports processes?
I really don't know, but the other problem is to use a flag in a target
dependent call which might be unsupported, but tested. This is backed
by POSIX allowing open to return EINVAL for invalid flags.
We should probably define _FNOINHERIT only on targets known to support
it (even if trivially) and to call open(O_CLOEXEC) or fcntl() depending
on that test, no?
POSIX says there is an O_CLOEXEC, so I think this is a valid oflag value. An
unsupported close on execute would be more an ENOSYS which is not mentioned
http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html
I would define the POSIX flags unconditionally and in case errors show up on
a particular system, then we can find a solution, e.g. not define it on
system X.
Ok, ACK.


Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber
2018-10-08 13:38:57 UTC
Permalink
Move common content of the various <sys/dirent.h> and the latest FreeBSD
<dirent.h> to <dirent.h>.

Signed-off-by: Sebastian Huber <***@embedded-brains.de>
---
newlib/libc/include/dirent.h | 81 +++++++++++++++++++++++++++---
newlib/libc/machine/spu/sys/dirent.h | 8 ---
newlib/libc/sys/decstation/sys/dirent.h | 7 ---
newlib/libc/sys/phoenix/sys/dirent.h | 13 -----
newlib/libc/sys/rtems/include/sys/dirent.h | 20 --------
newlib/libc/sys/sparc64/sys/dirent.h | 7 ---
newlib/libc/sys/sun4/sys/dirent.h | 7 ---
newlib/libc/sys/sysvi386/sys/dirent.h | 7 ---
winsup/cygwin/include/sys/dirent.h | 32 ------------
9 files changed, 75 insertions(+), 107 deletions(-)

diff --git a/newlib/libc/include/dirent.h b/newlib/libc/include/dirent.h
index 6135b9f6e..5d566a81e 100644
--- a/newlib/libc/include/dirent.h
+++ b/newlib/libc/include/dirent.h
@@ -1,8 +1,40 @@
+/*-
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)dirent.h 8.3 (Berkeley) 8/10/94
+ * $FreeBSD: head/include/dirent.h 326024 2017-11-20 19:45:28Z pfg $
+ */
+
#ifndef _DIRENT_H_
-#define _DIRENT_H_
-#ifdef __cplusplus
-extern "C" {
-#endif
+#define _DIRENT_H_
+
#include <sys/cdefs.h>
#include <sys/dirent.h>

@@ -10,7 +42,44 @@ extern "C" {
#define MAXNAMLEN 1024
#endif

-#ifdef __cplusplus
-}
+__BEGIN_DECLS
+#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
+int alphasort(const struct dirent **, const struct dirent **);
+int dirfd(DIR *);
+#endif
+#if __BSD_VISIBLE
+int fdclosedir(DIR *);
+#endif
+DIR *opendir(const char *);
+DIR *fdopendir(int);
+struct dirent *
+ readdir(DIR *);
+#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500
+int readdir_r(DIR *__restrict, struct dirent *__restrict,
+ struct dirent **__restrict);
+#endif
+void rewinddir(DIR *);
+#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 700
+int scandir(const char *, struct dirent ***,
+ int (*)(const struct dirent *), int (*)(const struct dirent **,
+ const struct dirent **));
#endif
+#ifdef _COMPILING_NEWLIB
+void _seekdir(DIR *, long);
+#endif
+#if __MISC_VISIBLE || __XSI_VISIBLE
+#ifndef __INSIDE_CYGWIN__
+void seekdir(DIR *, long);
+long telldir(DIR *);
+#endif
+#endif
+int closedir(DIR *);
+#if __GNU_VISIBLE
+int scandirat(int, const char *, struct dirent ***,
+ int (*) (const struct dirent *), int (*) (const struct dirent **,
+ const struct dirent **));
+int versionsort(const struct dirent **, const struct dirent **);
+#endif
+__END_DECLS
+
#endif /*_DIRENT_H_*/
diff --git a/newlib/libc/machine/spu/sys/dirent.h b/newlib/libc/machine/spu/sys/dirent.h
index 60da65a62..00ed41429 100644
--- a/newlib/libc/machine/spu/sys/dirent.h
+++ b/newlib/libc/machine/spu/sys/dirent.h
@@ -51,14 +51,6 @@ typedef struct {
struct dirent dirent;
} DIR;

-DIR *opendir(const char *);
-int closedir(DIR *);
-struct dirent *readdir (DIR *);
-int readdir_r (DIR *__restrict, struct dirent *__restrict,
- struct dirent **__restrict);
-void rewinddir(DIR *);
-void seekdir(DIR *dir, off_t offset);
-off_t telldir(DIR *dir);
#ifdef __cplusplus
}
#endif
diff --git a/newlib/libc/sys/decstation/sys/dirent.h b/newlib/libc/sys/decstation/sys/dirent.h
index c3abda639..f5febb077 100644
--- a/newlib/libc/sys/decstation/sys/dirent.h
+++ b/newlib/libc/sys/decstation/sys/dirent.h
@@ -23,13 +23,6 @@ typedef struct __dirdesc {

# define __dirfd(dp) ((dp)->dd_fd)

-DIR *opendir (const char *);
-struct dirent *readdir (DIR *);
-int readdir_r (DIR *__restrict, struct dirent *__restrict,
- struct dirent **__restrict);
-void rewinddir (DIR *);
-int closedir (DIR *);
-
#include <sys/types.h>

#define MAXNAMLEN 255
diff --git a/newlib/libc/sys/phoenix/sys/dirent.h b/newlib/libc/sys/phoenix/sys/dirent.h
index f8c72de02..3db267372 100644
--- a/newlib/libc/sys/phoenix/sys/dirent.h
+++ b/newlib/libc/sys/phoenix/sys/dirent.h
@@ -45,19 +45,6 @@ typedef struct {

#define __dirfd(dir) (dir)->dd_fd

-DIR *opendir(const char *name);
-struct dirent *readdir(DIR *dirp);
-void rewinddir(DIR *dirp);
-int closedir(DIR *dirp);
-
-long telldir(DIR *dirp);
-void seekdir(DIR *dirp, off_t loc);
-int scandir(const char *__dir,
- struct dirent ***__namelist,
- int (*select) (const struct dirent *),
- int (*compar) (const struct dirent **, const struct dirent **));
-int alphasort(const struct dirent **__a, const struct dirent **__b);
-
#define _seekdir seekdir

/* Declare which dirent fields are available in Phoenix-RTOS. */
diff --git a/newlib/libc/sys/rtems/include/sys/dirent.h b/newlib/libc/sys/rtems/include/sys/dirent.h
index bedb4e484..cb64307f9 100644
--- a/newlib/libc/sys/rtems/include/sys/dirent.h
+++ b/newlib/libc/sys/rtems/include/sys/dirent.h
@@ -24,19 +24,6 @@ typedef struct _dirdesc {

# define __dirfd(dp) ((dp)->dd_fd)

-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *__restrict, struct dirent *__restrict,
- struct dirent **__restrict);
-void rewinddir(DIR *);
-int closedir(DIR *);
-void seekdir(DIR *dir, long loc);
-long telldir(DIR *dir);
-
-#ifdef _COMPILING_NEWLIB
-void _seekdir(DIR *dir, long offset);
-#endif
-
#include <sys/types.h>

#include <limits.h>
@@ -54,13 +41,6 @@ struct dirent {
#define MAXNAMLEN NAME_MAX
#endif

-int alphasort(const struct dirent **, const struct dirent **);
-int scandir ( const char *dirname,
- struct dirent *** namelist,
- int (*select)(const struct dirent *),
- int (*dcomp)(const struct dirent **, const struct dirent **)
-);
-
#ifdef __cplusplus
}
#endif
diff --git a/newlib/libc/sys/sparc64/sys/dirent.h b/newlib/libc/sys/sparc64/sys/dirent.h
index cb933b457..ec6df0c83 100644
--- a/newlib/libc/sys/sparc64/sys/dirent.h
+++ b/newlib/libc/sys/sparc64/sys/dirent.h
@@ -19,13 +19,6 @@ typedef struct __dirdesc {

# define __dirfd(dp) ((dp)->dd_fd)

-DIR *opendir (const char *);
-struct dirent *readdir (DIR *);
-int readdir_r (DIR *__restrict, struct dirent *__restrict,
- struct dirent **__restrict);
-void rewinddir (DIR *);
-int closedir (DIR *);
-
#include <sys/types.h>

#undef MAXNAMLEN /* from unistd.h */
diff --git a/newlib/libc/sys/sun4/sys/dirent.h b/newlib/libc/sys/sun4/sys/dirent.h
index 2e6fc456f..02943fe6d 100644
--- a/newlib/libc/sys/sun4/sys/dirent.h
+++ b/newlib/libc/sys/sun4/sys/dirent.h
@@ -21,13 +21,6 @@ typedef struct __dirdesc {

# define __dirfd(dp) ((dp)->dd_fd)

-DIR *opendir (const char *);
-struct dirent *readdir (DIR *);
-int readdir_r (DIR *__restrict, struct dirent *__restrict,
- struct dirent **__restrict);
-void rewinddir (DIR *);
-int closedir (DIR *);
-
#include <sys/types.h>

#define MAXNAMLEN 255
diff --git a/newlib/libc/sys/sysvi386/sys/dirent.h b/newlib/libc/sys/sysvi386/sys/dirent.h
index 06af4faac..7851390c0 100644
--- a/newlib/libc/sys/sysvi386/sys/dirent.h
+++ b/newlib/libc/sys/sysvi386/sys/dirent.h
@@ -18,13 +18,6 @@ typedef struct _dirdesc {

# define __dirfd(dp) ((dp)->dd_fd)

-DIR *opendir (const char *);
-struct dirent *readdir (DIR *);
-int readdir_r (DIR *__restrict, struct dirent *__restrict,
- struct dirent **__restrict);
-void rewinddir (DIR *);
-int closedir (DIR *);
-
#include <sys/types.h>

struct dirent {
diff --git a/winsup/cygwin/include/sys/dirent.h b/winsup/cygwin/include/sys/dirent.h
index 48688efe4..177a553b2 100644
--- a/winsup/cygwin/include/sys/dirent.h
+++ b/winsup/cygwin/include/sys/dirent.h
@@ -60,38 +60,6 @@ typedef struct __DIR
#pragma pack(pop)
#endif

-DIR *opendir (const char *);
-DIR *fdopendir (int);
-struct dirent *readdir (DIR *);
-int readdir_r (DIR * __restrict, struct dirent * __restrict,
- struct dirent ** __restrict);
-void rewinddir (DIR *);
-int closedir (DIR *);
-
-int dirfd (DIR *);
-
-#if __MISC_VISIBLE || __XSI_VISIBLE
-#ifndef __INSIDE_CYGWIN__
-long telldir (DIR *);
-void seekdir (DIR *, long loc);
-#endif
-#endif
-
-#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200809
-int scandir (const char *__dir,
- struct dirent ***__namelist,
- int (*select) (const struct dirent *),
- int (*compar) (const struct dirent **, const struct dirent **));
-int alphasort (const struct dirent **__a, const struct dirent **__b);
-#endif
-
-#if __GNU_VISIBLE
-int scandirat (int __dirfd, const char *__dir, struct dirent ***__namelist,
- int (*select) (const struct dirent *),
- int (*compar) (const struct dirent **, const struct dirent **));
-int versionsort (const struct dirent **__a, const struct dirent **__b);
-#endif
-
#if __BSD_VISIBLE
#ifdef _DIRENT_HAVE_D_TYPE
/* File types for `d_type'. */
--
2.16.4
Corinna Vinschen
2018-10-10 09:54:37 UTC
Permalink
Post by Sebastian Huber
Move common content of the various <sys/dirent.h> and the latest FreeBSD
<dirent.h> to <dirent.h>.
Looks right to me.


Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber
2018-10-08 13:38:58 UTC
Permalink
This post might be inappropriate. Click to display it.
Sebastian Huber
2018-10-08 13:38:59 UTC
Permalink
Use existing HAVE_OPENDIR define to determine if a generic
implementation should be provided. Cygwin for example has its own
implementation of opendir() and dirfd().

Signed-off-by: Sebastian Huber <***@embedded-brains.de>
---
newlib/libc/posix/Makefile.am | 2 +-
newlib/libc/posix/Makefile.in | 28 +++++++++++++++++-----------
newlib/libc/posix/dirfd.c | 38 ++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+), 12 deletions(-)
create mode 100644 newlib/libc/posix/dirfd.c

diff --git a/newlib/libc/posix/Makefile.am b/newlib/libc/posix/Makefile.am
index 481849cb3..6cdee1df0 100644
--- a/newlib/libc/posix/Makefile.am
+++ b/newlib/libc/posix/Makefile.am
@@ -5,7 +5,7 @@ AUTOMAKE_OPTIONS = cygnus
INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)

GENERAL_SOURCES = \
- closedir.c collate.c collcmp.c creat.c \
+ closedir.c collate.c collcmp.c creat.c dirfd.c \
fnmatch.c glob.c _isatty.c isatty.c \
opendir.c readdir.c readdir_r.c \
regcomp.c regerror.c regexec.c regfree.c \
diff --git a/newlib/libc/posix/Makefile.in b/newlib/libc/posix/Makefile.in
index 147476a33..6dff00b8e 100644
--- a/newlib/libc/posix/Makefile.in
+++ b/newlib/libc/posix/Makefile.in
@@ -74,14 +74,14 @@ lib_a_AR = $(AR) $(ARFLAGS)
lib_a_LIBADD =
am__objects_1 = lib_a-closedir.$(OBJEXT) lib_a-collate.$(OBJEXT) \
lib_a-collcmp.$(OBJEXT) lib_a-creat.$(OBJEXT) \
- lib_a-fnmatch.$(OBJEXT) lib_a-glob.$(OBJEXT) \
- lib_a-_isatty.$(OBJEXT) lib_a-isatty.$(OBJEXT) \
- lib_a-opendir.$(OBJEXT) lib_a-readdir.$(OBJEXT) \
- lib_a-readdir_r.$(OBJEXT) lib_a-regcomp.$(OBJEXT) \
- lib_a-regerror.$(OBJEXT) lib_a-regexec.$(OBJEXT) \
- lib_a-regfree.$(OBJEXT) lib_a-rewinddir.$(OBJEXT) \
- lib_a-sleep.$(OBJEXT) lib_a-usleep.$(OBJEXT) \
- lib_a-telldir.$(OBJEXT)
+ lib_a-dirfd.$(OBJEXT) lib_a-fnmatch.$(OBJEXT) \
+ lib_a-glob.$(OBJEXT) lib_a-_isatty.$(OBJEXT) \
+ lib_a-isatty.$(OBJEXT) lib_a-opendir.$(OBJEXT) \
+ lib_a-readdir.$(OBJEXT) lib_a-readdir_r.$(OBJEXT) \
+ lib_a-regcomp.$(OBJEXT) lib_a-regerror.$(OBJEXT) \
+ lib_a-regexec.$(OBJEXT) lib_a-regfree.$(OBJEXT) \
+ lib_a-rewinddir.$(OBJEXT) lib_a-sleep.$(OBJEXT) \
+ lib_a-usleep.$(OBJEXT) lib_a-telldir.$(OBJEXT)
am__objects_2 = lib_a-scandir.$(OBJEXT) lib_a-seekdir.$(OBJEXT)
am__objects_3 = lib_a-execl.$(OBJEXT) lib_a-execle.$(OBJEXT) \
lib_a-execlp.$(OBJEXT) lib_a-execv.$(OBJEXT) \
@@ -100,8 +100,8 @@ am__objects_4 = lib_a-popen.$(OBJEXT) lib_a-posix_spawn.$(OBJEXT)
lib_a_OBJECTS = $(am_lib_a_OBJECTS)
LTLIBRARIES = $(noinst_LTLIBRARIES)
libposix_la_LIBADD =
-am__objects_6 = closedir.lo collate.lo collcmp.lo creat.lo fnmatch.lo \
- glob.lo _isatty.lo isatty.lo opendir.lo readdir.lo \
+am__objects_6 = closedir.lo collate.lo collcmp.lo creat.lo dirfd.lo \
+ fnmatch.lo glob.lo _isatty.lo isatty.lo opendir.lo readdir.lo \
readdir_r.lo regcomp.lo regerror.lo regexec.lo regfree.lo \
rewinddir.lo sleep.lo usleep.lo telldir.lo
am__objects_7 = scandir.lo seekdir.lo
@@ -290,7 +290,7 @@ top_srcdir = @top_srcdir@
AUTOMAKE_OPTIONS = cygnus
INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
GENERAL_SOURCES = \
- closedir.c collate.c collcmp.c creat.c \
+ closedir.c collate.c collcmp.c creat.c dirfd.c \
fnmatch.c glob.c _isatty.c isatty.c \
opendir.c readdir.c readdir_r.c \
regcomp.c regerror.c regexec.c regfree.c \
@@ -428,6 +428,12 @@ lib_a-creat.o: creat.c
lib_a-creat.obj: creat.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-creat.obj `if test -f 'creat.c'; then $(CYGPATH_W) 'creat.c'; else $(CYGPATH_W) '$(srcdir)/creat.c'; fi`

+lib_a-dirfd.o: dirfd.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-dirfd.o `test -f 'dirfd.c' || echo '$(srcdir)/'`dirfd.c
+
+lib_a-dirfd.obj: dirfd.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-dirfd.obj `if test -f 'dirfd.c'; then $(CYGPATH_W) 'dirfd.c'; else $(CYGPATH_W) '$(srcdir)/dirfd.c'; fi`
+
lib_a-fnmatch.o: fnmatch.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fnmatch.o `test -f 'fnmatch.c' || echo '$(srcdir)/'`fnmatch.c

diff --git a/newlib/libc/posix/dirfd.c b/newlib/libc/posix/dirfd.c
new file mode 100644
index 000000000..439dfa2f6
--- /dev/null
+++ b/newlib/libc/posix/dirfd.c
@@ -0,0 +1,38 @@
+#ifndef HAVE_OPENDIR
+
+/*-
+ * Copyright (c) 2018 embedded brains GmbH
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <dirent.h>
+
+int
+dirfd(DIR *dirp)
+{
+
+ return (__dirfd(dirp));
+}
+
+#endif /* ! HAVE_OPENDIR */
--
2.16.4
Corinna Vinschen
2018-10-10 10:06:54 UTC
Permalink
Post by Sebastian Huber
Use existing HAVE_OPENDIR define to determine if a generic
implementation should be provided. Cygwin for example has its own
implementation of opendir() and dirfd().
ACK


Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber
2018-10-09 10:09:10 UTC
Permalink
+#if defined (__CYGWIN__)
#define O_BINARY _FBINARY
#define O_TEXT _FTEXT
#define O_DSYNC _FSYNC
#define O_RSYNC _FSYNC
-#define O_EXEC _FEXECSRCH
#define O_SEARCH _FEXECSRCH
I just noticed that O_SEARCH is a POSIX flag as well, so this should
move out of the Cygwin-specific block too.
--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : ***@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Corinna Vinschen
2018-10-10 09:47:13 UTC
Permalink
Make O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_DIRECT available
to non-Cygwin systems.
---
newlib/libc/include/sys/_default_fcntl.h | 46 ++++++++++++++++++--------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/newlib/libc/include/sys/_default_fcntl.h b/newlib/libc/include/sys/_default_fcntl.h
index 33b462285..19fe65cfd 100644
--- a/newlib/libc/include/sys/_default_fcntl.h
+++ b/newlib/libc/include/sys/_default_fcntl.h
@@ -23,6 +23,19 @@ extern "C" {
#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
+#if defined (__CYGWIN__)
+#define _FBINARY 0x10000
+#define _FTEXT 0x20000
+#endif
+#define _FNOINHERIT 0x40000
+#define _FDIRECT 0x80000
+#define _FNOFOLLOW 0x100000
+#define _FDIRECTORY 0x200000
+#define _FEXECSRCH 0x400000
+#if defined (__CYGWIN__)
+#define _FTMPFILE 0x800000
+#define _FNOATIME 0x1000000
+#endif
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
@@ -43,35 +56,28 @@ extern "C" {
/* O_NDELAY _FNBIO set in include/fcntl.h */
#define O_NONBLOCK _FNONBLOCK
#define O_NOCTTY _FNOCTTY
-/* For machines which care - */
-#if defined (__CYGWIN__)
-#define _FBINARY 0x10000
-#define _FTEXT 0x20000
-#define _FNOINHERIT 0x40000
-#define _FDIRECT 0x80000
-#define _FNOFOLLOW 0x100000
-#define _FDIRECTORY 0x200000
-#define _FEXECSRCH 0x400000
-#define _FTMPFILE 0x800000
-#define _FNOATIME 0x1000000
+/* POSIX-1.2008 specific flags */
+#if __POSIX_VISIBLE >= 200809
+#define O_CLOEXEC _FNOINHERIT
+#define O_NOFOLLOW _FNOFOLLOW
+#define O_DIRECTORY _FDIRECTORY
+#define O_EXEC _FEXECSRCH
+#endif
+
+#if __GNU_VISIBLE || __BSD_VISIBLE
+#define O_DIRECT _FDIRECT
+#endif
This is actually a BSD flag? If so, `#if __BSD_VISIBLE' should
suffice since that's implied by setting _GNU_SOURCE.


Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Corinna Vinschen
2018-10-10 09:54:07 UTC
Permalink
Make O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_DIRECT available
to non-Cygwin systems.
Btw., for patchset it would be nice to add a cover letter. It's easier
to follow the thread for comments related to single patches vs. comments
related to the entire series.


Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber
2018-10-10 11:20:12 UTC
Permalink
Post by Corinna Vinschen
Make O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_DIRECT available
to non-Cygwin systems.
---
newlib/libc/include/sys/_default_fcntl.h | 46 ++++++++++++++++++--------------
1 file changed, 26 insertions(+), 20 deletions(-)
diff --git a/newlib/libc/include/sys/_default_fcntl.h b/newlib/libc/include/sys/_default_fcntl.h
index 33b462285..19fe65cfd 100644
--- a/newlib/libc/include/sys/_default_fcntl.h
+++ b/newlib/libc/include/sys/_default_fcntl.h
@@ -23,6 +23,19 @@ extern "C" {
#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
+#if defined (__CYGWIN__)
+#define _FBINARY 0x10000
+#define _FTEXT 0x20000
+#endif
+#define _FNOINHERIT 0x40000
+#define _FDIRECT 0x80000
+#define _FNOFOLLOW 0x100000
+#define _FDIRECTORY 0x200000
+#define _FEXECSRCH 0x400000
+#if defined (__CYGWIN__)
+#define _FTMPFILE 0x800000
+#define _FNOATIME 0x1000000
+#endif
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
@@ -43,35 +56,28 @@ extern "C" {
/* O_NDELAY _FNBIO set in include/fcntl.h */
#define O_NONBLOCK _FNONBLOCK
#define O_NOCTTY _FNOCTTY
-/* For machines which care - */
-#if defined (__CYGWIN__)
-#define _FBINARY 0x10000
-#define _FTEXT 0x20000
-#define _FNOINHERIT 0x40000
-#define _FDIRECT 0x80000
-#define _FNOFOLLOW 0x100000
-#define _FDIRECTORY 0x200000
-#define _FEXECSRCH 0x400000
-#define _FTMPFILE 0x800000
-#define _FNOATIME 0x1000000
+/* POSIX-1.2008 specific flags */
+#if __POSIX_VISIBLE >= 200809
+#define O_CLOEXEC _FNOINHERIT
+#define O_NOFOLLOW _FNOFOLLOW
+#define O_DIRECTORY _FDIRECTORY
+#define O_EXEC _FEXECSRCH
+#endif
+
+#if __GNU_VISIBLE || __BSD_VISIBLE
+#define O_DIRECT _FDIRECT
+#endif
This is actually a BSD flag? If so, `#if __BSD_VISIBLE' should
suffice since that's implied by setting _GNU_SOURCE.
The O_DIRECT is documented in the FreeBSD man page:

https://www.freebsd.org/cgi/man.cgi?sektion=2&query=open

The guard is __BSD_VISIBLE:

https://github.com/freebsd/freebsd/blob/master/sys/sys/fcntl.h#L116

I will change this to use __BSD_VISIBLE only.
--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : ***@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Corinna Vinschen
2018-10-10 10:08:36 UTC
Permalink
Post by Sebastian Huber
---
newlib/libc/posix/opendir.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
Depends on the O_CLOEXEC thingy but otherwise ACK.


Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber
2018-10-10 13:32:37 UTC
Permalink
Make the POSIX O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_SEARCH
open() flags available also to non-Cygwin systems.

Make the BSD/glibc O_DIRECT open() flag available also to non-Cygwin
systems.

Signed-off-by: Sebastian Huber <***@embedded-brains.de>
---
newlib/libc/include/sys/_default_fcntl.h | 48 ++++++++++++++++++--------------
1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/newlib/libc/include/sys/_default_fcntl.h b/newlib/libc/include/sys/_default_fcntl.h
index 33b462285..22fa10688 100644
--- a/newlib/libc/include/sys/_default_fcntl.h
+++ b/newlib/libc/include/sys/_default_fcntl.h
@@ -23,6 +23,19 @@ extern "C" {
#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
+#if defined (__CYGWIN__)
+#define _FBINARY 0x10000
+#define _FTEXT 0x20000
+#endif
+#define _FNOINHERIT 0x40000
+#define _FDIRECT 0x80000
+#define _FNOFOLLOW 0x100000
+#define _FDIRECTORY 0x200000
+#define _FEXECSRCH 0x400000
+#if defined (__CYGWIN__)
+#define _FTMPFILE 0x800000
+#define _FNOATIME 0x1000000
+#endif

#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)

@@ -43,35 +56,28 @@ extern "C" {
/* O_NDELAY _FNBIO set in include/fcntl.h */
#define O_NONBLOCK _FNONBLOCK
#define O_NOCTTY _FNOCTTY
-/* For machines which care - */
-#if defined (__CYGWIN__)
-#define _FBINARY 0x10000
-#define _FTEXT 0x20000
-#define _FNOINHERIT 0x40000
-#define _FDIRECT 0x80000
-#define _FNOFOLLOW 0x100000
-#define _FDIRECTORY 0x200000
-#define _FEXECSRCH 0x400000
-#define _FTMPFILE 0x800000
-#define _FNOATIME 0x1000000

+/* POSIX-1.2008 specific flags */
+#if __POSIX_VISIBLE >= 200809
+#define O_CLOEXEC _FNOINHERIT
+#define O_NOFOLLOW _FNOFOLLOW
+#define O_DIRECTORY _FDIRECTORY
+#define O_EXEC _FEXECSRCH
+#define O_SEARCH _FEXECSRCH
+#endif
+
+#if __BSD_VISIBLE
+#define O_DIRECT _FDIRECT
+#endif
+
+#if defined (__CYGWIN__)
#define O_BINARY _FBINARY
#define O_TEXT _FTEXT
#define O_DSYNC _FSYNC
#define O_RSYNC _FSYNC
-#define O_EXEC _FEXECSRCH
-#define O_SEARCH _FEXECSRCH
-
-/* POSIX-1.2008 specific flags */
-#if __POSIX_VISIBLE >= 200809
-#define O_CLOEXEC _FNOINHERIT
-#define O_NOFOLLOW _FNOFOLLOW
-#define O_DIRECTORY _FDIRECTORY
-#endif

/* Linux-specific flags */
#if __GNU_VISIBLE
-#define O_DIRECT _FDIRECT
#define O_TMPFILE _FTMPFILE
#define O_NOATIME _FNOATIME
#endif
--
2.16.4
Corinna Vinschen
2018-10-10 15:00:31 UTC
Permalink
Post by Sebastian Huber
Make the POSIX O_CLOEXEC, O_NOFOLLOW, O_DIRECTORY, O_EXEC, and O_SEARCH
open() flags available also to non-Cygwin systems.
Make the BSD/glibc O_DIRECT open() flag available also to non-Cygwin
systems.
LGTM, but one last question.
Post by Sebastian Huber
+/* POSIX-1.2008 specific flags */
+#if __POSIX_VISIBLE >= 200809
+#define O_CLOEXEC _FNOINHERIT
+#define O_NOFOLLOW _FNOFOLLOW
+#define O_DIRECTORY _FDIRECTORY
+#define O_EXEC _FEXECSRCH
+#define O_SEARCH _FEXECSRCH
+#endif
+
+#if __BSD_VISIBLE
+#define O_DIRECT _FDIRECT
+#endif
+
+#if defined (__CYGWIN__)
#define O_BINARY _FBINARY
#define O_TEXT _FTEXT
#define O_DSYNC _FSYNC
#define O_RSYNC _FSYNC
-#define O_EXEC _FEXECSRCH
-#define O_SEARCH _FEXECSRCH
-
-/* POSIX-1.2008 specific flags */
-#if __POSIX_VISIBLE >= 200809
Doesn't that require to #define _POSIX_C_SOURCE 200809L in your
libc/posix/opendir.c patch?
Post by Sebastian Huber
-#define O_CLOEXEC _FNOINHERIT
-#define O_NOFOLLOW _FNOFOLLOW
-#define O_DIRECTORY _FDIRECTORY
-#endif
/* Linux-specific flags */
#if __GNU_VISIBLE
-#define O_DIRECT _FDIRECT
#define O_TMPFILE _FTMPFILE
#define O_NOATIME _FNOATIME
#endif
--
2.16.4
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Sebastian Huber
2018-10-11 05:35:16 UTC
Permalink
Post by Corinna Vinschen
+/* POSIX-1.2008 specific flags */
+#if __POSIX_VISIBLE >= 200809
+#define O_CLOEXEC _FNOINHERIT
+#define O_NOFOLLOW _FNOFOLLOW
+#define O_DIRECTORY _FDIRECTORY
+#define O_EXEC _FEXECSRCH
+#define O_SEARCH _FEXECSRCH
+#endif
+
+#if __BSD_VISIBLE
+#define O_DIRECT _FDIRECT
+#endif
+
+#if defined (__CYGWIN__)
#define O_BINARY _FBINARY
#define O_TEXT _FTEXT
#define O_DSYNC _FSYNC
#define O_RSYNC _FSYNC
-#define O_EXEC _FEXECSRCH
-#define O_SEARCH _FEXECSRCH
-
-/* POSIX-1.2008 specific flags */
-#if __POSIX_VISIBLE >= 200809
Doesn't that require to #define _POSIX_C_SOURCE 200809L in your
libc/posix/opendir.c patch?
This POSIX standard is visible by default:

echo "#include <sys/cdefs.h>" > test.c
arm-rtems5-gcc -E test.c -o - -Wp,-dD | grep VISIBLE
#define __ATFILE_VISIBLE 1
#define __BSD_VISIBLE 1
#define __GNU_VISIBLE 0
#define __ISO_C_VISIBLE 2011
#define __LARGEFILE_VISIBLE 0
#define __MISC_VISIBLE 1
#define __POSIX_VISIBLE 200809
#define __SVID_VISIBLE 1
#define __XSI_VISIBLE 0
--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : ***@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
Corinna Vinschen
2018-10-11 07:13:40 UTC
Permalink
Post by Sebastian Huber
Post by Corinna Vinschen
+/* POSIX-1.2008 specific flags */
+#if __POSIX_VISIBLE >= 200809
+#define O_CLOEXEC _FNOINHERIT
+#define O_NOFOLLOW _FNOFOLLOW
+#define O_DIRECTORY _FDIRECTORY
+#define O_EXEC _FEXECSRCH
+#define O_SEARCH _FEXECSRCH
+#endif
+
+#if __BSD_VISIBLE
+#define O_DIRECT _FDIRECT
+#endif
+
+#if defined (__CYGWIN__)
#define O_BINARY _FBINARY
#define O_TEXT _FTEXT
#define O_DSYNC _FSYNC
#define O_RSYNC _FSYNC
-#define O_EXEC _FEXECSRCH
-#define O_SEARCH _FEXECSRCH
-
-/* POSIX-1.2008 specific flags */
-#if __POSIX_VISIBLE >= 200809
Doesn't that require to #define _POSIX_C_SOURCE 200809L in your
libc/posix/opendir.c patch?
echo "#include <sys/cdefs.h>" > test.c
arm-rtems5-gcc -E test.c -o - -Wp,-dD | grep VISIBLE
#define __ATFILE_VISIBLE 1
#define __BSD_VISIBLE 1
#define __GNU_VISIBLE 0
#define __ISO_C_VISIBLE 2011
#define __LARGEFILE_VISIBLE 0
#define __MISC_VISIBLE 1
#define __POSIX_VISIBLE 200809
#define __SVID_VISIBLE 1
#define __XSI_VISIBLE 0
Oh, right. _DEFAULT_SOURCE implies POSIX 200809. Sorry for the noise.


Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
Loading...