[prev in list] [next in list] [prev in thread] [next in thread]
List: freebsd-standards
Subject: 1003.1-200x and SUSv2 types
From: Garrett Wollman <wollman () khavrinen ! lcs ! mit ! edu>
Date: 2000-10-04 19:23:19
[Download RAW message or body]
<<On Wed, 4 Oct 2000 19:11:14 +1100 (EST), Bruce Evans <bde@zeta.org.au> said:
> I agree. This makes the treatment of POSIX typedefs more like the treatment
> of Standard C typedefs (<sys/types.h> shouldn't exist; instead, each header
> should declare precisely the types required to use the header, preferably
> without types being defined all over the place).
Here is a multifarious patch which attempts to start the
implementation process. This has not even been compile-tested, but
I'll try to do that when I get home and find any places which get
broken by the new behavior.
The following changes are included in this patch set:
o All of the types which are double-defined in <sys/types.h>
and in <sys/stat.h> under 1003.1-200x are macroized a la
size_t.
o The _POSIX_C_SOURCE and _XOPEN_SOURCE feature-test macros
are implemented in <sys/cdefs.h>, ensuring that the results
of the testing are available to all standard headers.
o <sys/cdefs.h> defines a new macro __restrict, which is a
place-holder for C99's `restrict' qualifier used in function
prototypes in 1003.1-200x.
o All of the new definitions are added to <sys/stat.h> and
everything is feature-test-ized using the macros from
<sys/cdefs.h>. `__restrict' added in the two functions it's
defined for.
I'm thinking that perhaps we should define bogus foo_t types for all
of the other elements in `struct stat' while we're at it.
If I have time and it's not out-of-order, I'll submit a change request
for the next draft to add timespec-based file timestamps; we'll need
a timespec-based analogue to utime() and a pathconf() key to return
the timestamp resolution -- both should be easy.
-GAWollman
Index: i386/include/ansi.h
===================================================================
RCS file: /home/cvs/src/sys/i386/include/ansi.h,v
retrieving revision 1.18
diff -u -r1.18 ansi.h
--- i386/include/ansi.h 2000/01/14 10:41:39 1.18
+++ i386/include/ansi.h 2000/10/04 16:51:52
@@ -46,15 +46,25 @@
* #undef _BSD_SIZE_T_
* #endif
*/
-#define _BSD_CLOCK_T_ unsigned long /* clock()... */
+#define _BSD_BLKCNT_T_ __int64_t /* block count (signed) */
+#define _BSD_BLKSIZE_T_ __int32_t /* block size (signed) */
#define _BSD_CLOCKID_T_ int /* clock_gettime()... */
+#define _BSD_CLOCK_T_ unsigned long /* clock()... */
+#define _BSD_GID_T_ __uint32_t /* group */
+#define _BSD_INO_T_ __uint32_t /* inode number */
+#define _BSD_MODE_T_ __uint16_t /* permissions */
+#define _BSD_OFF_T_ __int64_t /* file offset */
+#define _BSD_PID_T_ int /* process or process group */
#define _BSD_PTRDIFF_T_ int /* ptr1 - ptr2 */
#define _BSD_RUNE_T_ _BSD_CT_RUNE_T_ /* rune_t (see below) */
#define _BSD_SIZE_T_ unsigned int /* sizeof() */
#define _BSD_SSIZE_T_ int /* byte count or error */
-#define _BSD_TIME_T_ long /* time()... */
#define _BSD_TIMER_T_ int /* timer_gettime()... */
+#define _BSD_TIME_T_ long /* time()... */
+#define _BSD_UDEV_T_ __uint32_t /* device number in userland */
+#define _BSD_UID_T_ __uint32_t /* user */
#define _BSD_WCHAR_T_ _BSD_CT_RUNE_T_ /* wchar_t (see below) */
+#define _BSD_NLINK_T_ __uint16_t /* link count */
/*
* Types which are fundamental to the implementation and must be used
@@ -63,8 +73,6 @@
* use _BSD_XXX_T_ without undef'ing it.
*/
#define _BSD_CT_RUNE_T_ int /* arg type for ctype funcs */
-#define _BSD_OFF_T_ __int64_t /* file offset */
-#define _BSD_PID_T_ int /* process [group] */
#define _BSD_VA_LIST_ char * /* va_list */
/*
Index: sys/cdefs.h
===================================================================
RCS file: /home/cvs/src/sys/sys/cdefs.h,v
retrieving revision 1.29
diff -u -r1.29 cdefs.h
--- sys/cdefs.h 2000/03/18 22:26:54 1.29
+++ sys/cdefs.h 2000/10/04 18:50:47
@@ -129,6 +129,13 @@
#endif
/*
+ * Header-file (non-)support for C99's `restrict' qualifier.
+ * When compilers start to support this, it will be [un]defined
+ * as appropriate.
+ */
+#define __restrict
+
+/*
* Compiler-dependent macros to declare that functions take printf-like
* or scanf-like arguments. They are null except for versions of gcc
* that are known to support the features properly (old versions of gcc-2
@@ -208,6 +215,73 @@
#ifndef __COPYRIGHT
#define __COPYRIGHT(s) __IDSTRING(copyright,s)
+#endif
+
+/*
+ * The following definitions are an extension of the behavior
+ * originally implemented in <sys/_posix.h>, but with a different
+ * level of granularity. POSIX.1 requires that the macros we test
+ * be defined before any standard header file is included.
+ *
+ * Here's a quick run-down of the versions:
+ * defined(_POSIX_SOURCE) 1003.1-1988
+ * _POSIX_C_SOURCE == 1 1003.1-1990
+ * _POSIX_C_SOURCE == 199309 1003.1b-1993
+ * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995,
+ * and the omnibus ISO/IEC 9945-1: 1996
+ *
+ * In addition, the X/Open Portability Guide, which is now the Single
+ * UNIX Specification, defines a feature-test macro which indicates the
+ * version of that specification, and which subsumes _POSIX_C_SOURCE.
+ *
+ * Where the version 200010 appears below, it is a placeholder for the
+ * appropriate value from IEEE Std. 1003.1-200x when published.
+ * Our macros begin with two underscores to avoid namespace screwage.
+ */
+
+/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
+#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE < 199309
+# undef _POSIX_C_SOURCE /* probably illegal, but beyond caring now */
+# define _POSIX_C_SOURCE 199009
+#endif
+
+/* Deal with various X/Open Portability Guides and Single UNIX Spec. */
+#if defined(_XOPEN_SOURCE)
+# if _XOPEN_SOURCE >= 600
+# define __XSI_VISIBLE 600
+# ifndef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200010
+# endif
+# elif _XOPEN_SOURCE >= 500
+# define __XSI_VISIBLE 500
+# ifndef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 199506
+# endif
+# endif
+#endif
+
+/*
+ * Deal with all versions of POSIX. The ordering relative to the tests
+ * above is important.
+ */
+#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
+# define _POSIX_C_SOURCE 198808
+#elif defined(_POSIX_C_SOURCE)
+# if _POSIX_C_SOURCE >= 200010
+# define __POSIX_VISIBLE 200010
+# elif _POSIX_C_SOURCE >= 199506
+# define __POSIX_VISIBLE 199506
+# elif _POSIX_C_SOURCE >= 199309
+# define __POSIX_VISIBLE 199309
+# elif _POSIX_C_SOURCE >= 199009
+# define __POSIX_VISIBLE 199009
+# else
+# define __POSIX_VISIBLE 198808
+# endif
+#else
+# define __POSIX_VISIBLE 200010
+# define __XSI_VISIBLE 600
+# define __BSD_VISIBLE 1
#endif
#endif /* !_SYS_CDEFS_H_ */
Index: sys/stat.h
===================================================================
RCS file: /home/cvs/src/sys/sys/stat.h,v
retrieving revision 1.21
diff -u -r1.21 stat.h
--- sys/stat.h 2000/07/04 04:58:34 1.21
+++ sys/stat.h 2000/10/04 19:03:10
@@ -42,7 +42,7 @@
#ifndef _SYS_STAT_H_
#define _SYS_STAT_H_
-#if !defined(_KERNEL) && !defined(_POSIX_SOURCE)
+#if !defined(_KERNEL) && defined(__BSD_VISIBLE)
/*
* XXX we need this for struct timespec. We get miscellaneous namespace
* pollution with it.
@@ -50,13 +50,74 @@
#include <sys/time.h>
#endif
+/*
+ * The following types are required by tradition or POSIX to be defined
+ * both here and in another file. The original definitions are in
+ * <machine/ansi.h>. The idiomatic #ifdef/#undef/#endif preprocessing
+ * prevents redefinitions when both files are included. We don't worry
+ * about feature-test macros here because all the relevant standards
+ * reserve identifiers matching *_t.
+ */
+#ifdef _BSD_BLKCNT_T_
+typedef _BSD_BLKCNT_T_ blkcnt_t; /* block count (as of a file) */
+#undef _BSD_BLKCNT_T_
+#endif
+
+#ifdef _BSD_BLKSIZE_T_
+typedef _BSD_BLKSIZE_T_ blksize_t; /* block size */
+#undef _BSD_BLKSIZE_T_
+#endif
+
+#ifdef _BSD_GID_T_
+typedef _BSD_GID_T_ gid_t; /* group id */
+#undef _BSD_GID_T_
+#endif
+
+#ifdef _BSD_INO_T_
+typedef _BSD_INO_T_ ino_t; /* inode number */
+#undef _BSD_INO_T_
+#endif
+
+#ifdef _BSD_MODE_T_
+typedef _BSD_MODE_T_ mode_t; /* permissions */
+#undef _BSD_MODE_T_
+#endif
+
+#ifdef _BSD_NLINK_T_
+typedef _BSD_NLINK_T_ nlink_t; /* link count */
+#undef _BSD_NLINK_T_
+#endif
+
+#ifdef _BSD_OFF_T_
+typedef _BSD_OFF_T_ off_t; /* file offset */
+#undef _BSD_OFF_T_
+#endif
+
+#ifdef _BSD_TIME_T_
+typedef _BSD_TIME_T_ time_t;
+#undef _BSD_TIME_T_
+#endif
+
+#ifdef _BSD_UID_T_
+typedef _BSD_UID_T_ uid_t; /* user id */
+#undef _BSD_UID_T_
+#endif
+
#ifdef _KERNEL
+#ifdef _BSD_UDEV_T_
+typedef _BSD_UDEV_T_ udev_t; /* device number */
+#undef _BSD_UDEV_T_
+#endif
#define __dev_t udev_t
#else
+#ifdef _BSD_UDEV_T_
+typedef _BSD_UDEV_T_ dev_t; /* device number */
+#undef _BSD_UDEV_T_
+#endif
#define __dev_t dev_t
#endif
-#ifndef _POSIX_SOURCE
+#ifdef __BSD_VISIBLE
struct ostat {
u_int16_t st_dev; /* inode's device */
ino_t st_ino; /* inode's number */
@@ -74,8 +135,9 @@
u_int32_t st_flags; /* user defined flags for file */
u_int32_t st_gen; /* file generation number */
};
-#endif /* !_POSIX_SOURCE */
+#endif /* __BSD_VISIBLE */
+/* Identifiers beginning st_* are reserved. */
struct stat {
__dev_t st_dev; /* inode's device */
ino_t st_ino; /* inode's number */
@@ -83,8 +145,8 @@
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of the file's owner */
gid_t st_gid; /* group ID of the file's group */
- __dev_t st_rdev; /* device type */
-#ifndef _POSIX_SOURCE
+ __dev_t st_rdev; /* device type (XSI) */
+#if __BSD_VISIBLE
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
@@ -95,17 +157,17 @@
long st_mtimensec; /* nsec of last data modification */
time_t st_ctime; /* time of last file status change */
long st_ctimensec; /* nsec of last file status change */
-#endif
+#endif /* !__BSD_VISIBLE */
off_t st_size; /* file size, in bytes */
- int64_t st_blocks; /* blocks allocated for file */
- u_int32_t st_blksize; /* optimal blocksize for I/O */
+ blkcnt_t st_blocks; /* blocks allocated for file (XSI) */
+ blksize_t st_blksize; /* optimal blocksize for I/O (XSI) */
u_int32_t st_flags; /* user defined flags for file */
u_int32_t st_gen; /* file generation number */
int32_t st_lspare;
int64_t st_qspare[2];
};
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
struct nstat {
__dev_t st_dev; /* inode's device */
ino_t st_ino; /* inode's number */
@@ -114,7 +176,7 @@
uid_t st_uid; /* user ID of the file's owner */
gid_t st_gid; /* group ID of the file's group */
__dev_t st_rdev; /* device type */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
struct timespec st_atimespec; /* time of last access */
struct timespec st_mtimespec; /* time of last data modification */
struct timespec st_ctimespec; /* time of last file status change */
@@ -125,19 +187,19 @@
long st_mtimensec; /* nsec of last data modification */
time_t st_ctime; /* time of last file status change */
long st_ctimensec; /* nsec of last file status change */
-#endif
+#endif /* !__BSD_VISIBLE */
off_t st_size; /* file size, in bytes */
- int64_t st_blocks; /* blocks allocated for file */
- u_int32_t st_blksize; /* optimal blocksize for I/O */
+ blkcnt_t st_blocks; /* blocks allocated for file */
+ blksize_t st_blksize; /* optimal blocksize for I/O */
u_int32_t st_flags; /* user defined flags for file */
u_int32_t st_gen; /* file generation number */
int64_t st_qspare[2];
};
-#endif
+#endif /* __BSD_VISIBLE */
#undef __dev_t
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
#define st_atime st_atimespec.tv_sec
#define st_mtime st_mtimespec.tv_sec
#define st_ctime st_ctimespec.tv_sec
@@ -145,7 +207,7 @@
#define S_ISUID 0004000 /* set user id on execution */
#define S_ISGID 0002000 /* set group id on execution */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
#define S_ISTXT 0001000 /* sticky bit */
#endif
@@ -154,7 +216,7 @@
#define S_IWUSR 0000200 /* W for owner */
#define S_IXUSR 0000100 /* X for owner */
-#ifndef _POSIX_SOURCE
+#if __BSD_VISIBLE
#define S_IREAD S_IRUSR
#define S_IWRITE S_IWUSR
#define S_IEXEC S_IXUSR
@@ -169,18 +231,25 @@
#define S_IROTH 0000004 /* R for other */
#define S_IWOTH 0000002 /* W for other */
#define S_IXOTH 0000001 /* X for other */
+
+#if __XSI_VISIBLE >= 402
+#define S_ISVTX 0001000 /* save swapped text even after use */
+#endif
-#ifndef _POSIX_SOURCE
+#if __XSI_VISIBLE /* assume for all XPG */
#define S_IFMT 0170000 /* type of file mask */
#define S_IFIFO 0010000 /* named pipe (fifo) */
#define S_IFCHR 0020000 /* character special */
#define S_IFDIR 0040000 /* directory */
#define S_IFBLK 0060000 /* block special */
#define S_IFREG 0100000 /* regular */
+#if __XSI_VISIBLE >= 402
#define S_IFLNK 0120000 /* symbolic link */
+#endif
#define S_IFSOCK 0140000 /* socket */
+#if __BSD_VISIBLE
#define S_IFWHT 0160000 /* whiteout */
-#define S_ISVTX 0001000 /* save swapped text even after use */
+#endif
#endif
#define S_ISDIR(m) (((m) & 0170000) == 0040000) /* directory */
@@ -188,13 +257,29 @@
#define S_ISBLK(m) (((m) & 0170000) == 0060000) /* block special */
#define S_ISREG(m) (((m) & 0170000) == 0100000) /* regular file */
#define S_ISFIFO(m) (((m) & 0170000) == 0010000) /* fifo or socket */
-#ifndef _POSIX_SOURCE
+#if __POSIX_VISIBLE >= 200010 || __XSI_VISIBLE >= 402
#define S_ISLNK(m) (((m) & 0170000) == 0120000) /* symbolic link */
+#endif
+#if __POSIX_VISIBLE >= 200010
#define S_ISSOCK(m) (((m) & 0170000) == 0140000) /* socket */
+#endif
+#ifdef __BSD_VISIBLE
#define S_ISWHT(m) (((m) & 0170000) == 0160000) /* whiteout */
#endif
+
+/*
+ * 1003.1 says that if these IPC objects are not implemented as distinct
+ * file types, these macros shall evaluate to zero. Unlike the S_IS*
+ * macros, these take a `struct stat *' and not a `mode_t'.
+ */
+#if 0 /* not yet implemented */
+#define S_TYPEISMQ(b) (0)
+#define S_TYPEISSEM(b) (0)
+#define S_TYPEISTMO(b) (0)
+#endif
+#define S_TYPEISSHM(b) (0)
-#ifndef _POSIX_SOURCE
+#ifdef __BSD_VISIBLE
#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
/* 7777 */
#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
@@ -234,7 +319,7 @@
#define NOUNLINK (UF_NOUNLINK | SF_NOUNLINK)
#endif
-#endif /* !_POSIX_SOURCE */
+#endif /* __BSD_VISIBLE */
#ifndef _KERNEL
#include <sys/cdefs.h>
@@ -244,15 +329,33 @@
int fstat __P((int, struct stat *));
int mkdir __P((const char *, mode_t));
int mkfifo __P((const char *, mode_t));
-int stat __P((const char *, struct stat *));
+int stat __P((const char *__restrict, struct stat *__restrict));
mode_t umask __P((mode_t));
+
+#if __XSI_VISIBLE >= 402 || __POSIX_VISIBLE >= 200010
+int fchmod __P((int, mode_t));
+#endif
+#if __XSI_VISIBLE >= 402
+/*
+ * XXX - in XBDd4, lstat is inconsistently shaded; I (wollman@FreeBSD.org)
+ * have submitted a bug report. Assume it will be resolved in the manner
+ * I suggested. (symlink() is shaded XSI in <unistd.h>, so assume that
+ * lstat() should be XSI here.)
+ */
+int lstat __P((const char *__restrict, struct stat *__restrict));
+int mknod __P((const char *, mode_t, dev_t));
+#endif
+
+#if 0 /* not implemented */
+#if __POSIX_VISIBLE >= 200010 /* perhaps will be XSI instead */
+int isfdtype __P((int, int));
+#endif
+#endif
-#ifndef _POSIX_SOURCE
+#ifdef __BSD_VISIBLE
int chflags __P((const char *, u_long));
int fchflags __P((int, u_long));
-int fchmod __P((int, mode_t));
int lchmod __P((const char *, mode_t));
-int lstat __P((const char *, struct stat *));
#endif
__END_DECLS
Index: sys/types.h
===================================================================
RCS file: /home/cvs/src/sys/sys/types.h,v
retrieving revision 1.40
diff -u -r1.40 types.h
--- sys/types.h 2000/02/20 15:01:37 1.40
+++ sys/types.h 2000/10/04 16:52:55
@@ -72,13 +72,7 @@
typedef int32_t daddr_t; /* disk address */
typedef u_int32_t u_daddr_t; /* unsigned disk address */
typedef u_int32_t fixpt_t; /* fixed point number */
-typedef u_int32_t gid_t; /* group id */
-typedef u_int32_t ino_t; /* inode number */
typedef long key_t; /* IPC key (for Sys V IPC) */
-typedef u_int16_t mode_t; /* permissions */
-typedef u_int16_t nlink_t; /* link count */
-typedef _BSD_OFF_T_ off_t; /* file offset */
-typedef _BSD_PID_T_ pid_t; /* process id */
typedef quad_t rlim_t; /* resource limit */
#ifdef __alpha__ /* XXX should be in <machine/types.h> */
typedef int64_t segsz_t; /* segment size */
@@ -87,7 +81,6 @@
#endif
typedef int32_t swblk_t; /* swap offset */
typedef int32_t ufs_daddr_t;
-typedef u_int32_t uid_t; /* user id */
#ifdef _KERNEL
typedef int boolean_t;
@@ -99,12 +92,18 @@
struct specinfo;
-typedef u_int32_t udev_t; /* device number */
+#ifdef _BSD_UDEV_T_
+typedef _BSD_UDEV_T_ udev_t; /* device number */
+#undef _BSD_UDEV_T_
+#endif
typedef struct specinfo *dev_t;
#else /* !_KERNEL */
-typedef u_int32_t dev_t; /* device number */
+#ifdef _BSD_UDEV_T_
+typedef _BSD_UDEV_T_ dev_t; /* device number */
+#undef _BSD_UDEV_T_
+#endif
#define udev_t dev_t
#ifndef _POSIX_SOURCE
@@ -124,6 +123,22 @@
#include <machine/endian.h>
+/*
+ * The following types are required by tradition or POSIX to be defined
+ * both here and in another file. The original definitions are in
+ * <machine/ansi.h>. The idiomatic #ifdef/#undef/#endif preprocessing
+ * prevents redefinitions when both files are included.
+ */
+#ifdef _BSD_BLKCNT_T_
+typedef _BSD_BLKCNT_T_ blkcnt_t; /* block count (as of a file) */
+#undef _BSD_BLKCNT_T_
+#endif
+
+#ifdef _BSD_BLKSIZE_T_
+typedef _BSD_BLKSIZE_T_ blksize_t; /* block size */
+#undef _BSD_BLKSIZE_T_
+#endif
+
#ifdef _BSD_CLOCK_T_
typedef _BSD_CLOCK_T_ clock_t;
#undef _BSD_CLOCK_T_
@@ -134,6 +149,36 @@
#undef _BSD_CLOCKID_T_
#endif
+#ifdef _BSD_GID_T_
+typedef _BSD_GID_T_ gid_t; /* group id */
+#undef _BSD_GID_T_
+#endif
+
+#ifdef _BSD_INO_T_
+typedef _BSD_INO_T_ ino_t; /* inode number */
+#undef _BSD_INO_T_
+#endif
+
+#ifdef _BSD_MODE_T_
+typedef _BSD_MODE_T_ mode_t; /* permissions */
+#undef _BSD_MODE_T_
+#endif
+
+#ifdef _BSD_NLINK_T_
+typedef _BSD_NLINK_T_ nlink_t; /* link count */
+#undef _BSD_NLINK_T_
+#endif
+
+#ifdef _BSD_OFF_T_
+typedef _BSD_OFF_T_ off_t; /* file offset */
+#undef _BSD_OFF_T_
+#endif
+
+#ifdef _BSD_PID_T_
+typedef _BSD_PID_T_ pid_t; /* process id */
+#undef _BSD_PID_T_
+#endif
+
#ifdef _BSD_SIZE_T_
typedef _BSD_SIZE_T_ size_t;
#undef _BSD_SIZE_T_
@@ -152,6 +197,11 @@
#ifdef _BSD_TIMER_T_
typedef _BSD_TIMER_T_ timer_t;
#undef _BSD_TIMER_T_
+#endif
+
+#ifdef _BSD_UID_T_
+typedef _BSD_UID_T_ uid_t; /* user id */
+#undef _BSD_UID_T_
#endif
#ifndef _POSIX_SOURCE
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic