Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-2-0]: src/tools/compat Pull up revision 1.39 via patch (requested...
details: https://anonhg.NetBSD.org/src/rev/3dd6d87669a9
branches: netbsd-2-0
changeset: 561528:3dd6d87669a9
user: tron <tron%NetBSD.org@localhost>
date: Tue Jun 22 07:24:33 2004 +0000
description:
Pull up revision 1.39 via patch (requested by jmc in ticket #527):
Completely rework how tools/compat is done. Purge all uses/references to
_NETBSD_SOURCE as this makes cross building from older/newer versions of
NetBSD harder, not easier (and also makes the resulting tools 'different')
Wrap all required code with the inclusion of nbtool_config.h, attempt to
only use POSIX code in all places (or when reasonable test w. configure and
provide definitions: ala u_int, etc).
Reviewed by lukem. Tested on FreeBSD 4.9, Redhat Linux ES3, NetBSD 1.6.2 x86
NetBSD current (x86 and amd64) and Solaris 9.
Fixes PR's: PR#17762 PR#25944
diffstat:
tools/compat/compat_defs.h | 188 +++++++++++++++++++++++++++++++++++++-------
1 files changed, 155 insertions(+), 33 deletions(-)
diffs (truncated from 342 to 300 lines):
diff -r f800889f64d2 -r 3dd6d87669a9 tools/compat/compat_defs.h
--- a/tools/compat/compat_defs.h Tue Jun 22 07:24:12 2004 +0000
+++ b/tools/compat/compat_defs.h Tue Jun 22 07:24:33 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: compat_defs.h,v 1.31.2.1 2004/06/14 20:19:44 tron Exp $ */
+/* $NetBSD: compat_defs.h,v 1.31.2.2 2004/06/22 07:24:33 tron Exp $ */
#ifndef __NETBSD_COMPAT_DEFS_H__
#define __NETBSD_COMPAT_DEFS_H__
@@ -15,16 +15,25 @@
#include <features.h>
#endif
+/* So _NETBSD_SOURCE doesn't end up defined. Define enough to pull in standard
+ defs. Other platforms may need similiar defines. */
+#ifdef __NetBSD__
+#define _POSIX_SOURCE 1
+#define _POSIX_C_SOURCE 200112L
+#define _XOPEN_SOURCE 600
+#else
#undef _POSIX_SOURCE
#undef _POSIX_C_SOURCE
+#endif
/* System headers needed for (re)definitions below. */
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/param.h>
+/* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
+#include <sys/time.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <errno.h>
#include <fcntl.h>
#include <grp.h>
@@ -32,19 +41,7 @@
#include <paths.h>
#include <stdarg.h>
#include <stdio.h>
-
-/* So extra NetBSD extentions don't get pulled in */
-#ifdef __NetBSD__
-#define _POSIX_C_SOURCE
-#undef _NETBSD_SOURCE
-#endif
-
#include <stdlib.h>
-
-#ifdef __NetBSD__
-#undef _POSIX_C_SOURCE
-#endif
-
#include <string.h>
#if HAVE_SYS_CDEFS_H
@@ -87,6 +84,13 @@
#if !defined(__attribute__) && !defined(__GNUC__)
#define __attribute__(x)
#endif
+#if !defined(__packed)
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+#define __packed __attribute__((__packed__))
+#else
+#define __packed error: no __packed for this compiler
+#endif
+#endif /* !__packed */
#ifndef __RENAME
#define __RENAME(x)
#endif
@@ -130,6 +134,18 @@
typedef unsigned long u_long;
#endif
+#if !HAVE_U_CHAR
+typedef unsigned char u_char;
+#endif
+
+#if !HAVE_U_INT
+typedef unsigned int u_int;
+#endif
+
+#if !HAVE_U_SHORT
+typedef unsigned short u_short;
+#endif
+
/* Prototypes for replacement functions. */
#if !HAVE_ATOLL
@@ -162,9 +178,26 @@
#if HAVE_DIR_DD_FD
#define dirfd(dirp) ((dirp)->dd_fd)
#else
+/*XXX: Very hacky but no other way to bring this into scope w/o defining
+ _NETBSD_SOURCE which we're avoiding. */
+#ifdef __NetBSD__
+struct _dirdesc {
+ int dd_fd; /* file descriptor associated with directory */
+ long dd_loc; /* offset in current buffer */
+ long dd_size; /* amount of data returned by getdents */
+ char *dd_buf; /* data buffer */
+ int dd_len; /* size of data buffer */
+ off_t dd_seek; /* magic cookie returned by getdents */
+ long dd_rewind; /* magic cookie for rewinding */
+ int dd_flags; /* flags for readdir */
+ void *dd_lock; /* lock for concurrent access */
+};
+#define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
+#else
#error cannot figure out how to turn a DIR * into a fd
#endif
#endif
+#endif
#if !HAVE_ERR_H
void err(int, const char *, ...);
@@ -173,7 +206,7 @@
void warnx(const char *, ...);
#endif
-#if !HAVE_FGETLN
+#if !HAVE_FGETLN || defined(__NetBSD__)
char *fgetln(FILE *, size_t *);
#endif
@@ -185,7 +218,7 @@
int flock(int, int);
#endif
-#if !HAVE_FPARSELN
+#if !HAVE_FPARSELN || defined(__NetBSD__)
# define FPARSELN_UNESCESC 0x01
# define FPARSELN_UNESCCONT 0x02
# define FPARSELN_UNESCCOMM 0x04
@@ -214,16 +247,33 @@
int lchown(const char *, uid_t, gid_t);
#endif
-#if !HAVE_MACHINE_BSWAP_H
-#define bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
+#define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
+
+#define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
+ (((x) << 8) & 0x00ff0000) | \
+ (((x) >> 8) & 0x0000ff00) | \
+ (((x) >> 24) & 0x000000ff))
+
+#define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
+ ((u_int64_t)bswap32((x) >> 32)))
-#define bswap32(x) ((((x) << 24) & 0xff000000) | \
- (((x) << 8) & 0x00ff0000) | \
- (((x) >> 8) & 0x0000ff00) | \
- (((x) >> 24) & 0x000000ff))
-
-#define bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
- ((u_int64_t)bswap32((x) >> 32)))
+#if !HAVE_BSWAP16
+#ifdef bswap16
+#undef bswap16
+#endif
+#define bswap16(x) __nbcompat_bswap16(x)
+#endif
+#if !HAVE_BSWAP32
+#ifdef bswap32
+#undef bswap32
+#endif
+#define bswap32(x) __nbcompat_bswap32(x)
+#endif
+#if !HAVE_BSWAP64
+#ifdef bswap64
+#undef bswap64
+#endif
+#define bswap64(x) __nbcompat_bswap64(x)
#endif
#if !HAVE_MKSTEMP
@@ -251,6 +301,10 @@
int pwcache_groupdb(int (*)(int), void (*)(void),
struct group * (*)(const char *), struct group * (*)(gid_t));
#endif
+/* Make them use our version */
+# define user_from_uid __nbcompat_user_from_uid
+/* Make them use our version */
+# define group_from_gid __nbcompat_group_from_gid
#if !HAVE_PWRITE
ssize_t pwrite(int, const void *, size_t, off_t);
@@ -268,7 +322,7 @@
int setpassent(int);
#endif
-#if !HAVE_SETPROGNAME
+#if !HAVE_SETPROGNAME || defined(__NetBSD__)
const char *getprogname(void);
void setprogname(const char *);
#endif
@@ -285,7 +339,7 @@
size_t strlcpy(char *, const char *, size_t);
#endif
-#if !HAVE_STRSEP
+#if !HAVE_STRSEP || defined(__NetBSD__)
char *strsep(char **, const char *);
#endif
@@ -301,6 +355,9 @@
#if !HAVE_USER_FROM_UID
const char *user_from_uid(uid_t, int);
+#endif
+
+#if !HAVE_GROUP_FROM_GID
const char *group_from_gid(gid_t, int);
#endif
@@ -457,10 +514,10 @@
char *cgetcap(char *, const char *, int);
int cgetclose(void);
-int cgetent(char **, char **, const char *);
-int cgetfirst(char **, char **);
+int cgetent(char **, const char * const *, const char *);
+int cgetfirst(char **, const char * const *);
int cgetmatch(const char *, const char *);
-int cgetnext(char **, char **);
+int cgetnext(char **, const char * const *);
int cgetnum(char *, const char *, long *);
int cgetset(const char *);
int cgetstr(char *, const char *, char **);
@@ -468,29 +525,61 @@
/* <sys/endian.h> */
-#ifdef HAVE_SYS_ENDIAN_H
-#include <sys/endian.h>
-#else
#if WORDS_BIGENDIAN
+#if !HAVE_HTOBE16
#define htobe16(x) (x)
+#endif
+#if !HAVE_HTOBE32
#define htobe32(x) (x)
+#endif
+#if !HAVE_HTOBE64
#define htobe64(x) (x)
+#endif
+#if !HAVE_HTOLE16
#define htole16(x) bswap16((u_int16_t)(x))
+#endif
+#if !HAVE_HTOLE32
#define htole32(x) bswap32((u_int32_t)(x))
+#endif
+#if !HAVE_HTOLE64
#define htole64(x) bswap64((u_int64_t)(x))
+#endif
#else
+#if !HAVE_HTOBE16
#define htobe16(x) bswap16((u_int16_t)(x))
+#endif
+#if !HAVE_HTOBE32
#define htobe32(x) bswap32((u_int32_t)(x))
+#endif
+#if !HAVE_HTOBE64
#define htobe64(x) bswap64((u_int64_t)(x))
+#endif
+#if !HAVE_HTOLE16
#define htole16(x) (x)
+#endif
+#if !HAVE_HTOLE32
#define htole32(x) (x)
+#endif
+#if !HAVE_HTOLE64
#define htole64(x) (x)
#endif
+#endif
+#if !HAVE_BE16TOH
#define be16toh(x) htobe16(x)
+#endif
+#if !HAVE_BE32TOH
#define be32toh(x) htobe32(x)
+#endif
+#if !HAVE_BE64TOH
#define be64toh(x) htobe64(x)
+#endif
+#if !HAVE_LE16TOH
#define le16toh(x) htole16(x)
+#endif
+#if !HAVE_LE32TOH
#define le32toh(x) htole32(x)
+#endif
+#if !HAVE_LE64TOH
#define le64toh(x) htole64(x)
#endif
@@ -576,6 +665,19 @@
#endif
#endif
+/* Protected by _NETBSD_SOURCE otherwise. */
Home |
Main Index |
Thread Index |
Old Index