[PATCH] Declare *at() functions according to POSIX

Sebastian Huber sebastian.huber@embedded-brains.de
Wed Jan 1 18:49:00 GMT 2014


This patch uses the FreeBSD mechanism to declare the various *at()
functions according to the relevant POSIX standard revision.

newlib/ChangeLog
2014-01-01  Sebastian Huber  <sebastian.huber@embedded-brains.de>

	* libc/include/sys/_default_fcntl.h (AT_FDCWD): Define according
	to POSIX.
	(AT_EACCESS): Likewise.
	(AT_SYMLINK_NOFOLLOW): Likewise.
	(AT_SYMLINK_FOLLOW): Likewise.
	(AT_REMOVEDIR): Likewise.
	(openat): Declare according to POSIX.
	* libc/include/stdio.h (renameat): Likewise.
	* libc/include/sys/stat.h (fchmodat): Likewise.
	(fstatat): Likewise.
	(mkdirat): Likewise.
	(mkfifoat): Likewise.
	(mknodat): Likewise.
	(utimensat): Likewise.
	(futimens): Likewise.
	* libc/include/sys/unistd.h (faccessat): Likewise.
	(fchownat): Likewise.
	(linkat): Likewise.
	(readlinkat): Likewise.
	(symlinkat): Likewise.
	(unlinkat): Likewise.
---
 newlib/libc/include/stdio.h              |  3 ++-
 newlib/libc/include/sys/_default_fcntl.h |  7 +++++--
 newlib/libc/include/sys/stat.h           |  9 ++++++++-
 newlib/libc/include/sys/unistd.h         | 17 +++++++++++------
 4 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h
index c2418fa..95a6d49 100644
--- a/newlib/libc/include/stdio.h
+++ b/newlib/libc/include/stdio.h
@@ -32,6 +32,7 @@
 
 #define __need_size_t
 #define __need_NULL
+#include <sys/cdefs.h>
 #include <stddef.h>
 
 #define __need___va_list
@@ -336,7 +337,7 @@ FILE *	_EXFUN(fmemopen, (void *__restrict, size_t, const char *__restrict));
 /* getdelim - see __getdelim for now */
 /* getline - see __getline for now */
 FILE *	_EXFUN(open_memstream, (char **, size_t *));
-#if defined (__CYGWIN__)
+#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined(__CYGWIN__)
 int	_EXFUN(renameat, (int, const char *, int, const char *));
 #endif
 int	_EXFUN(vdprintf, (int, const char *__restrict, __VALIST)
diff --git a/newlib/libc/include/sys/_default_fcntl.h b/newlib/libc/include/sys/_default_fcntl.h
index 1884136..40d8fae 100644
--- a/newlib/libc/include/sys/_default_fcntl.h
+++ b/newlib/libc/include/sys/_default_fcntl.h
@@ -5,6 +5,7 @@ extern "C" {
 #endif
 #define	_SYS__DEFAULT_FCNTL_H_
 #include <_ansi.h>
+#include <sys/cdefs.h>
 #define	_FOPEN		(-1)	/* from sys/file.h, kernel use only */
 #define	_FREAD		0x0001	/* read enabled */
 #define	_FWRITE		0x0002	/* write enabled */
@@ -136,7 +137,7 @@ extern "C" {
 #define	F_UNLKSYS	4	/* remove remote locks for a given system */
 #endif	/* !_POSIX_SOURCE */
 
-#ifdef __CYGWIN__
+#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined(__CYGWIN__)
 /* Special descriptor value to denote the cwd in calls to openat(2) etc. */
 #define AT_FDCWD -2
 
@@ -180,12 +181,14 @@ struct eflock {
 #include <sys/stat.h>		/* sigh. for the mode bits for open/creat */
 
 extern int open _PARAMS ((const char *, int, ...));
+#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined(__CYGWIN__)
+extern int openat _PARAMS ((int, const char *, int, ...));
+#endif
 extern int creat _PARAMS ((const char *, mode_t));
 extern int fcntl _PARAMS ((int, int, ...));
 #ifdef __CYGWIN__
 #include <sys/time.h>
 extern int futimesat _PARAMS ((int, const char *, const struct timeval *));
-extern int openat _PARAMS ((int, const char *, int, ...));
 #endif
 
 /* Provide _<systemcall> prototypes for functions provided by some versions
diff --git a/newlib/libc/include/sys/stat.h b/newlib/libc/include/sys/stat.h
index dbd85ee..11b9d80 100644
--- a/newlib/libc/include/sys/stat.h
+++ b/newlib/libc/include/sys/stat.h
@@ -7,6 +7,7 @@ extern "C" {
 
 #include <_ansi.h>
 #include <time.h>
+#include <sys/cdefs.h>
 #include <sys/types.h>
 
 /* dj's stat defines _STAT_H_ */
@@ -155,12 +156,18 @@ int	_EXFUN(lstat,( const char *__restrict __path, struct stat *__restrict __buf
 int	_EXFUN(mknod,( const char *__path, mode_t __mode, dev_t __dev ));
 #endif
 
-#if defined (__CYGWIN__) && !defined(__INSIDE_CYGWIN__)
+#if (__POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__)
 int	_EXFUN(fchmodat, (int, const char *, mode_t, int));
+#endif
+#if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__)
 int	_EXFUN(fstatat, (int, const char *__restrict , struct stat *__restrict, int));
 int	_EXFUN(mkdirat, (int, const char *, mode_t));
 int	_EXFUN(mkfifoat, (int, const char *, mode_t));
+#endif
+#if (__BSD_VISIBLE || __XSI_VISIBLE >= 700 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__)
 int	_EXFUN(mknodat, (int, const char *, mode_t, dev_t));
+#endif
+#if (__BSD_VISIBLE || __POSIX_VISIBLE >= 200809 || defined (__CYGWIN__)) && !defined(__INSIDE_CYGWIN__)
 int	_EXFUN(utimensat, (int, const char *, const struct timespec *, int));
 int	_EXFUN(futimens, (int, const struct timespec *));
 #endif
diff --git a/newlib/libc/include/sys/unistd.h b/newlib/libc/include/sys/unistd.h
index d85195f..cd7640f 100644
--- a/newlib/libc/include/sys/unistd.h
+++ b/newlib/libc/include/sys/unistd.h
@@ -6,10 +6,11 @@ extern "C" {
 #endif
 
 #include <_ansi.h>
-#include <sys/types.h>
-#include <sys/_types.h>
 #define __need_size_t
 #define __need_ptrdiff_t
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <sys/_types.h>
 #include <stddef.h>
 
 extern char **environ;
@@ -54,6 +55,8 @@ int     _EXFUN(execve, (const char *__path, char * const __argv[], char * const
 int     _EXFUN(execvp, (const char *__file, char * const __argv[] ));
 #if defined(__CYGWIN__)
 int     _EXFUN(execvpe, (const char *__file, char * const __argv[], char * const __envp[] ));
+#endif
+#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
 int	_EXFUN(faccessat, (int __dirfd, const char *__path, int __mode, int __flags));
 #endif
 #if defined(__CYGWIN__) || defined(__rtems__) || defined(__SPU__)
@@ -63,8 +66,10 @@ int     _EXFUN(fchmod, (int __fildes, mode_t __mode ));
 #if !defined(__INSIDE_CYGWIN__)
 int     _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group ));
 #endif
-#if defined(__CYGWIN__)
+#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
 int	_EXFUN(fchownat, (int __dirfd, const char *__path, uid_t __owner, gid_t __group, int __flags));
+#endif
+#if defined(__CYGWIN__)
 int	_EXFUN(fexecve, (int __fd, char * const __argv[], char * const __envp[] ));
 #endif
 pid_t   _EXFUN(fork, (void ));
@@ -116,7 +121,7 @@ int     _EXFUN(isatty, (int __fildes ));
 int     _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group ));
 #endif
 int     _EXFUN(link, (const char *__path1, const char *__path2 ));
-#if defined(__CYGWIN__)
+#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
 int     _EXFUN(linkat, (int __dirfd1, const char *__path1, int __dirfd2, const char *__path2, int __flags ));
 #endif
 int	_EXFUN(nice, (int __nice_value ));
@@ -246,12 +251,12 @@ void    _EXFUN(sync, (void));
 
 ssize_t _EXFUN(readlink, (const char *__restrict __path,
                           char *__restrict __buf, size_t __buflen));
-#if defined(__CYGWIN__)
+#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
 ssize_t        _EXFUN(readlinkat, (int __dirfd1, const char *__restrict __path,
                             char *__restrict __buf, size_t __buflen));
 #endif
 int     _EXFUN(symlink, (const char *__name1, const char *__name2));
-#if defined(__CYGWIN__)
+#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE || defined(__CYGWIN__)
 int	_EXFUN(symlinkat, (const char *, int, const char *));
 int	_EXFUN(unlinkat, (int, const char *, int));
 #endif
-- 
1.8.1.4



More information about the Newlib mailing list