mailing list of musl libc
 help / color / mirror / code / Atom feed
* _BSD_SOURCE support for musl ready
@ 2012-05-21  6:26 Isaac Dunham
  2012-05-21 12:42 ` Isaac Dunham
  2012-05-21 13:36 ` Rich Felker
  0 siblings, 2 replies; 8+ messages in thread
From: Isaac Dunham @ 2012-05-21  6:26 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 294 bytes --]

I think the _BSD_SOURCE support is ready to merge now.
It is available from 
https://github.com/idunham/musl bsd

Alternately, I attached the diff against master (master-bsd.diff, 604
lines total touching about 25 files)

If there are any issues with this, I can try to fix them.

Isaac Dunham

[-- Attachment #2: master-bsd.diff --]
[-- Type: text/x-patch, Size: 17723 bytes --]

diff --git a/include/ctype.h b/include/ctype.h
index a85e907..8ceaa9f 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -30,7 +30,8 @@ int   toupper(int);
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 #define __NEED_locale_t
 #include <bits/alltypes.h>
diff --git a/include/dirent.h b/include/dirent.h
index d0a6b44..8162356 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -36,7 +36,7 @@ int            dirfd(DIR *);
 int alphasort(const struct dirent **, const struct dirent **);
 int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **));
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define DT_UNKNOWN 0
 #define DT_FIFO 1
 #define DT_CHR 2
diff --git a/include/fcntl.h b/include/fcntl.h
index 63f1beb..b776d38 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -80,12 +80,24 @@ int posix_fallocate(int, off_t, off_t);
 #define S_IRWXO 0007
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define FAPPEND O_APPEND
 #define FFSYNC O_FSYNC
 #define FASYNC O_ASYNC
 #define FNONBLOCK O_NONBLOCK
 #define FNDELAY O_NDELAY
+
+#ifndef _UNISTD_H
+#define F_OK 0
+#define R_OK 4
+#define W_OK 2
+#define X_OK 1
+#define F_ULOCK 0
+#define F_LOCK  1
+#define F_TLOCK 2
+#define F_TEST  3
+int lockf(int, int, off_t);
+#endif
 #endif
 
 #ifdef _LARGEFILE64_SOURCE
diff --git a/include/grp.h b/include/grp.h
index 5185185..0a55c62 100644
--- a/include/grp.h
+++ b/include/grp.h
@@ -28,7 +28,7 @@ struct group  *getgrent(void);
 void           endgrent(void);
 void           setgrent(void);
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int getgrouplist(const char *, gid_t, gid_t *, int *);
 int setgroups(size_t, const gid_t *);
 int initgroups(const char *, gid_t);
diff --git a/include/math.h b/include/math.h
index 61738e6..d732648 100644
--- a/include/math.h
+++ b/include/math.h
@@ -330,8 +330,7 @@ double      trunc(double);
 float       truncf(float);
 long double truncl(long double);
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
-#define MAXFLOAT        3.40282347e+38F
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define M_E             2.7182818284590452354   /* e */
 #define M_LOG2E         1.4426950408889634074   /* log_2 e */
 #define M_LOG10E        0.43429448190325182765  /* log_10 e */
@@ -345,7 +344,13 @@ long double truncl(long double);
 #define M_2_SQRTPI      1.12837916709551257390  /* 2/sqrt(pi) */
 #define M_SQRT2         1.41421356237309504880  /* sqrt(2) */
 #define M_SQRT1_2       0.70710678118654752440  /* 1/sqrt(2) */
+#endif
 
+#if defined(_XOPEN_SOURCE)
+#define MAXFLOAT        3.40282347e+38F
+#endif
+
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
 extern int signgam;
 
 double      j0(double);
@@ -358,6 +363,7 @@ double      yn(int, double);
 #endif
 
 #ifdef _GNU_SOURCE
+#define HUGE        3.40282347e+38F
 double      scalb(double, double);
 float       scalbf(float, float);
 long double scalbl(long double, long double);
diff --git a/include/net/if.h b/include/net/if.h
index 00c763a..e862c7c 100644
--- a/include/net/if.h
+++ b/include/net/if.h
@@ -21,7 +21,7 @@ void if_freenameindex (struct if_nameindex *);
 
 
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 
 #include <sys/socket.h>
 
diff --git a/include/netdb.h b/include/netdb.h
index 33b7a0a..d1fe9a8 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -5,7 +5,7 @@
 extern "C" {
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define __NEED_size_t
 #endif
 
@@ -118,7 +118,7 @@ struct protoent *getprotoent (void);
 struct protoent *getprotobyname (const char *);
 struct protoent *getprotobynumber (int);
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 const char *hstrerror(int);
 struct hostent *gethostbyname (const char *);
 int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
@@ -147,6 +147,8 @@ int *__h_errno_location(void);
 #define TRY_AGAIN      2
 #define NO_RECOVERY    3
 #define NO_DATA        4
+
+int innetgr(const char *, const char *, const char *, const char *);
 #endif
 
 
diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
index c8a1a4b..8180a83 100644
--- a/include/netinet/tcp.h
+++ b/include/netinet/tcp.h
@@ -2,5 +2,22 @@
 #define _NETINET_TCP_H
 
 #define TCP_NODELAY 1
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#include <sys/types.h>
+#include <sys/socket.h>
+#define	TCP_MAXSEG	 2
+#define TCP_CORK	 3
+#define TCP_KEEPIDLE	 4
+#define TCP_KEEPINTVL	 5
+#define TCP_KEEPCNT	 6
+#define TCP_SYNCNT	 7
+#define TCP_LINGER2	 8
+#define TCP_DEFER_ACCEPT 9
+#define TCP_WINDOW_CLAMP 10
+#define TCP_INFO	 11
+#define	TCP_QUICKACK	 12
+#define TCP_CONGESTION	 13
+#define TCP_MD5SIG	 14
+#endif
 
 #endif
diff --git a/include/setjmp.h b/include/setjmp.h
index b024c44..88fb950 100644
--- a/include/setjmp.h
+++ b/include/setjmp.h
@@ -9,7 +9,8 @@ extern "C" {
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 typedef unsigned long sigjmp_buf[(128+sizeof(jmp_buf))/sizeof(long)];
 #ifdef _GNU_SOURCE
 #define jmp_buf sigjmp_buf
@@ -19,7 +20,8 @@ void siglongjmp (sigjmp_buf, int);
 #endif
 
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 int _setjmp (jmp_buf);
 void _longjmp (jmp_buf, int);
 #endif
diff --git a/include/signal.h b/include/signal.h
index 38f369b..ba3b3a5 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -6,7 +6,8 @@ extern "C" {
 #endif
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 #ifdef _GNU_SOURCE
 #define __siginfo siginfo
@@ -204,9 +205,13 @@ void (*sigset(int, void (*)(int)))(int);
 #define SIGSTKSZ 8192
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 typedef void (*sighandler_t)(int);
+typedef sighandler_t sig_t;
 void (*bsd_signal(int, void (*)(int)))(int);
+#endif
+
+#ifdef _GNU_SOURCE
 int sigisemptyset(const sigset_t *);
 #define SA_NOMASK SA_NODEFER
 #define SA_ONESHOT SA_RESETHAND
diff --git a/include/stdio.h b/include/stdio.h
index 355f425..e4740eb 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -10,7 +10,8 @@ extern "C" {
 #define __NEED_size_t
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 #define __NEED_ssize_t
 #define __NEED_off_t
 #endif
@@ -120,7 +121,8 @@ char *tmpnam(char *);
 FILE *tmpfile(void);
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 FILE *fmemopen(void *, size_t, const char *);
 FILE *open_memstream(char **, size_t *);
 FILE *fdopen(int, const char *);
@@ -146,12 +148,13 @@ char *ctermid(char *);
 #endif
 
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 #define P_tmpdir "/tmp"
 char *tempnam(const char *, const char *);
 #endif
 
-#if defined(_GNU_SOURCE)
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define L_cuserid 20
 char *cuserid(char *);
 #undef off64_t
diff --git a/include/stdlib.h b/include/stdlib.h
index 11331d9..644325e 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -78,7 +78,8 @@ size_t wcstombs (char *, const wchar_t *, size_t);
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 #ifndef WEXITSTATUS
 #define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
@@ -102,20 +103,24 @@ int rand_r (unsigned *);
 #endif
 
 
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
+char *realpath (const char *, char *);
+long int random (void);
+void srandom (unsigned int);
+char *initstate (unsigned int, char *, size_t);
+char *setstate (char *);
+#endif
+
 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
 int putenv (char *);
 int posix_openpt (int);
 int grantpt (int);
 int unlockpt (int);
 char *ptsname (int);
-char *realpath (const char *, char *);
 char *l64a (long);
 long a64l (const char *);
 void setkey (const char *);
-long int random (void);
-void srandom (unsigned int);
-char *initstate (unsigned int, char *, size_t);
-char *setstate (char *);
 double drand48 (void);
 double erand48 (unsigned short [3]);
 long int lrand48 (void);
@@ -127,11 +132,14 @@ unsigned short *seed48 (unsigned short [3]);
 void lcong48 (unsigned short [7]);
 #endif
 
-#if defined(_GNU_SOURCE)
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #include <alloca.h>
 char *mktemp (char *);
 void *valloc (size_t);
 void *memalign(size_t, size_t);
+#endif
+
+#ifdef _GNU_SOURCE
 int clearenv(void);
 int ptsname_r(int, char *, size_t);
 char *ecvt(double, int, int *, int *);
diff --git a/include/string.h b/include/string.h
index 8cf0ee9..9715713 100644
--- a/include/string.h
+++ b/include/string.h
@@ -14,7 +14,7 @@ extern "C" {
 
 #define __NEED_size_t
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define __NEED_locale_t
 #endif
 
@@ -53,7 +53,7 @@ char *strerror (int);
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 char *strtok_r (char *, const char *, char **);
 int strerror_r (int, char *, size_t);
 char *stpcpy(char *, const char *);
@@ -67,19 +67,31 @@ int strcoll_l (const char *, const char *, locale_t);
 size_t strxfrm_l (char *, const char *, size_t, locale_t);
 #endif
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 void *memccpy (void *, const void *, int, size_t);
 #endif
 
+#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
+int bcmp (const void *, const void *, size_t);
+void bcopy (const void *, void *, size_t);
+void bzero (void *, size_t);
+int strcasecmp (const char *, const char *);
+int strncasecmp (const char *, const char *, size_t);
+char *index (const char *, int);
+char *rindex (const char *, int);
+int ffs (int);
+#endif
+
 #ifdef _BSD_SOURCE
 size_t strlcat (char *, const char *, size_t);
 size_t strlcpy (char *, const char *, size_t);
 #endif
 
 #ifdef _GNU_SOURCE
+#define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
 int strverscmp (const char *, const char *);
-int strcasecmp (const char *, const char *);
-int strncasecmp (const char *, const char *, size_t);
+int strcasecmp_l (const char *, const char *, locale_t);
+int strncasecmp_l (const char *, const char *, size_t, locale_t);
 char *strchrnul(const char *, int);
 char *strcasestr(const char *, const char *);
 char *strsep(char **, const char *);
diff --git a/include/sys/mman.h b/include/sys/mman.h
index a48c2b4..a45f11d 100644
--- a/include/sys/mman.h
+++ b/include/sys/mman.h
@@ -27,6 +27,9 @@ int munlockall (void);
 
 #ifdef _GNU_SOURCE
 void *mremap (void *, size_t, size_t, int, ...);
+#endif
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int madvise (void *, size_t, int);
 #endif
 
diff --git a/include/sys/stat.h b/include/sys/stat.h
index 5d50ae7..14a5424 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -90,7 +90,7 @@ int utimensat(int, const char *, const struct timespec [2], int);
 int lchmod(const char *, mode_t);
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define S_IREAD S_IRUSR
 #define S_IWRITE S_IWUSR
 #define S_IEXEC S_IXUSR
diff --git a/include/sys/time.h b/include/sys/time.h
index fa98944..144dd23 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -8,7 +8,8 @@ extern "C" {
 
 int gettimeofday (struct timeval *, void *);
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 #define ITIMER_REAL    0
 #define ITIMER_VIRTUAL 1
@@ -26,7 +27,7 @@ int utimes (const char *, const struct timeval [2]);
 
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int futimes(int, const struct timeval [2]);
 int lutimes(const char *, const struct timeval [2]);
 int settimeofday (const struct timeval *, void *);
diff --git a/include/sys/types.h b/include/sys/types.h
index b9b65f6..4b1e374 100644
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -58,7 +58,7 @@ typedef __uint16_t u_int16_t;
 typedef __uint32_t u_int32_t;
 typedef __uint64_t u_int64_t;
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 typedef char *caddr_t;
 typedef unsigned char u_char;
 typedef unsigned short u_short, ushort;
diff --git a/include/sys/wait.h b/include/sys/wait.h
index e73594a..5e3012b 100644
--- a/include/sys/wait.h
+++ b/include/sys/wait.h
@@ -17,7 +17,7 @@ pid_t wait (int *);
 int waitid (idtype_t, id_t, siginfo_t *, int);
 pid_t waitpid (pid_t, int *, int );
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #include <sys/resource.h>
 pid_t wait3 (int *, int, struct rusage *);
 pid_t wait4 (pid_t, int *, int, struct rusage *);
diff --git a/include/syslog.h b/include/syslog.h
index e0d86c0..278945f 100644
--- a/include/syslog.h
+++ b/include/syslog.h
@@ -59,7 +59,8 @@ void openlog (const char *, int, int);
 int setlogmask (int);
 void syslog (int, const char *, ...);
 
-#if defined(_GNU_SOURCE)
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define _PATH_LOG "/dev/log"
 #define __NEED_va_list
 #include <bits/alltypes.h>
 void vsyslog (int, const char *, va_list);
diff --git a/include/termios.h b/include/termios.h
index 7690883..1041759 100644
--- a/include/termios.h
+++ b/include/termios.h
@@ -32,7 +32,7 @@ int tcflow (int, int);
 
 pid_t tcgetsid (int);
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 void cfmakeraw(struct termios *);
 int cfsetspeed(struct termios *, speed_t);
 #endif
diff --git a/include/time.h b/include/time.h
index 98d0111..067b519 100644
--- a/include/time.h
+++ b/include/time.h
@@ -18,7 +18,8 @@ extern "C" {
 #define __NEED_clock_t
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 #define __NEED_struct_timespec
 #define __NEED_clockid_t
 #define __NEED_timer_t
@@ -57,7 +58,8 @@ char *ctime (const time_t *);
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 size_t strftime_l (char *, size_t, const char *, const struct tm *, locale_t);
 
diff --git a/include/unistd.h b/include/unistd.h
index b1a84d7..12f8feb 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -16,6 +16,12 @@ extern "C" {
 #define SEEK_CUR 1
 #define SEEK_END 2
 
+#if defined(_BSD_SOURCE) && !defined(L_SET)
+#define L_SET	SEEK_SET
+#define L_INCR	SEEK_CUR
+#define L_XTND	SEEK_END
+#endif
+
 #undef NULL
 #ifdef __cplusplus
 #define NULL 0
@@ -143,10 +149,9 @@ int nice(int);
 void sync(void);
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int brk(void *);
 void *sbrk(intptr_t);
-pid_t forkall(void);
 pid_t vfork(void);
 int vhangup(void);
 int chroot(const char *);
@@ -155,6 +160,11 @@ int sethostname(const char *, size_t);
 int usleep(unsigned);
 unsigned ualarm(unsigned, unsigned);
 int setgroups(size_t, const gid_t []);
+char *getpass(const char *);
+#endif
+
+#ifdef _GNU_SOURCE
+pid_t forkall(void);
 int setresuid(uid_t, uid_t, uid_t);
 int setresgid(gid_t, gid_t, gid_t);
 int getresuid(uid_t *, uid_t *, uid_t *);
@@ -166,7 +176,6 @@ int getdtablesize(void);
 void setusershell(void);
 void endusershell(void);
 char *getusershell(void);
-char *getpass(const char *);
 #endif
 
 #ifdef _LARGEFILE64_SOURCE
diff --git a/include/utmp.h b/include/utmp.h
index b145a11..8ffe3d7 100644
--- a/include/utmp.h
+++ b/include/utmp.h
@@ -33,6 +33,7 @@ struct utmp *pututline(const struct utmp *);
 void         setutent(void);
 
 void updwtmp(const char *, const struct utmp *);
+void logwtmp(const char *, const char *, const char *);
 
 #define _PATH_UTMP "/dev/null"
 #define _PATH_WTMP "/dev/null"
diff --git a/src/stub/innetgr.c b/src/stub/innetgr.c
new file mode 100644
index 0000000..a9495a5
--- /dev/null
+++ b/src/stub/innetgr.c
@@ -0,0 +1,8 @@
+/* stub for innetgr */
+#define _GNU_SOURCE
+#include <netdb.h>
+int innetgr(const char *netgroup, const char *host, 
+	const char *user, const char *domain) 
+{
+	return 0;
+}
diff --git a/src/stub/utmpx.c b/src/stub/utmpx.c
index c483e4e..1d51d96 100644
--- a/src/stub/utmpx.c
+++ b/src/stub/utmpx.c
@@ -34,6 +34,10 @@ void updwtmpx(const char *f, const struct utmpx *u)
 {
 }
 
+void logwtmp(const char *l, const char *n, const char *h)
+{
+}
+
 weak_alias(endutxent, endutent);
 weak_alias(setutxent, setutent);
 weak_alias(getutxent, getutent);

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: _BSD_SOURCE support for musl ready
  2012-05-21  6:26 _BSD_SOURCE support for musl ready Isaac Dunham
@ 2012-05-21 12:42 ` Isaac Dunham
  2012-05-21 13:36 ` Rich Felker
  1 sibling, 0 replies; 8+ messages in thread
From: Isaac Dunham @ 2012-05-21 12:42 UTC (permalink / raw)
  To: musl

On Sun, 20 May 2012 23:26:51 -0700
Isaac Dunham <idunham@lavabit.com> wrote:

> I think the _BSD_SOURCE support is ready to merge now.
> It is available from 
> https://github.com/idunham/musl bsd
> 
> Alternately, I attached the diff against master (master-bsd.diff, 604
> lines total touching about 25 files)
> 
> If there are any issues with this, I can try to fix them.

Here are the things that I'm not sure about:
1. logwtmp was added as a stub to src/stub/utmpx.c--fairly sure this is
the right place.
2. innetgr was added as src/stub/innetgr.c
3. HUGE vs MAXFLOAT for _GNU_SOURCE
4. Whitespace/line wrap (sometimes I went 3 feature test macros wide,
where everything else wraps after 2 macros) 
5. I added some macros and two includes to netinet/tcp.h (protected by
_BSD_SOURCE || _GNU_SOURCE). This still doesn't approach complete
coverage.

Isaac Dunham



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: _BSD_SOURCE support for musl ready
  2012-05-21  6:26 _BSD_SOURCE support for musl ready Isaac Dunham
  2012-05-21 12:42 ` Isaac Dunham
@ 2012-05-21 13:36 ` Rich Felker
  2012-05-21 17:19   ` Isaac Dunham
  2012-05-21 18:31   ` [PATCH]_BSD_SOURCE for musl, take 2 Isaac Dunham
  1 sibling, 2 replies; 8+ messages in thread
From: Rich Felker @ 2012-05-21 13:36 UTC (permalink / raw)
  To: musl

On Sun, May 20, 2012 at 11:26:51PM -0700, Isaac Dunham wrote:
> I think the _BSD_SOURCE support is ready to merge now.

Great. Quick review; not sure I caught all the issues...

> diff --git a/include/fcntl.h b/include/fcntl.h
> index 63f1beb..b776d38 100644
> --- a/include/fcntl.h
> +++ b/include/fcntl.h
> [...]
> +
> +#ifndef _UNISTD_H
> +#define F_OK 0
> +#define R_OK 4
> [...]

All _XXX_H macros should be considered entirely internal to the header
they're used to protect. Aside from that, this sort of mechanism makes
the logic in unistd.h very ugly (since it would have to check if
fcntl.h was already included with _GNU_SOURCE or _BSD_SOURCE defined).

Since the definitions are exactly the same, multiple #defines are
legal in C. If they work in C++ too, and if the compiler does not
issue ugly warnings, I would just leave it be. Otherwise you could
#undef them all first, or use #ifdef F_OK.

> diff --git a/include/netdb.h b/include/netdb.h
> index 33b7a0a..d1fe9a8 100644
> --- a/include/netdb.h
> +++ b/include/netdb.h
> @@ -5,7 +5,7 @@
> [...]
> +
> +int innetgr(const char *, const char *, const char *, const char *);

This should be a separate patch, and should add stubs for the rest of
the netgr functions at the same time (weak aliases in ent.c). Of
course innetgr needs to be in its own file since it's not a weak alias
and would pollute the standard namespace if put in ent.c.

> diff --git a/include/signal.h b/include/signal.h
> [...]
> -#ifdef _GNU_SOURCE
> +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
>  typedef void (*sighandler_t)(int);
> +typedef sighandler_t sig_t;
>  void (*bsd_signal(int, void (*)(int)))(int);
> +#endif

I think sig_t should be BSD-only. That's how it is in glibc, and since
it's so illogically named and short, I'd rather keep it out of the
namespace even with _GNU_SOURCE.

In glibc, sighandler_t is GNU-only (not in BSD). So it might make
sense to just have these be separate #ifdefs.

> diff --git a/include/string.h b/include/string.h
> index 8cf0ee9..9715713 100644
> --- a/include/string.h
> +++ b/include/string.h
> [...]
>  
> +#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
> +int bcmp (const void *, const void *, size_t);
> +void bcopy (const void *, void *, size_t);
> +void bzero (void *, size_t);
> +int strcasecmp (const char *, const char *);
> +int strncasecmp (const char *, const char *, size_t);
> +char *index (const char *, int);
> +char *rindex (const char *, int);
> +int ffs (int);
> +#endif

Wasn't all of this already coming from strings.h?


That was just from a quick glance, so there might be some other issues
remaining, but overall it looks good. Thanks!

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: _BSD_SOURCE support for musl ready
  2012-05-21 13:36 ` Rich Felker
@ 2012-05-21 17:19   ` Isaac Dunham
  2012-05-21 17:43     ` Rich Felker
  2012-05-21 18:31   ` [PATCH]_BSD_SOURCE for musl, take 2 Isaac Dunham
  1 sibling, 1 reply; 8+ messages in thread
From: Isaac Dunham @ 2012-05-21 17:19 UTC (permalink / raw)
  To: musl

On Mon, 21 May 2012 09:36:29 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> On Sun, May 20, 2012 at 11:26:51PM -0700, Isaac Dunham wrote:
> > I think the _BSD_SOURCE support is ready to merge now.
> 
> Great. Quick review; not sure I caught all the issues...
> 
> > diff --git a/include/fcntl.h b/include/fcntl.h
> > index 63f1beb..b776d38 100644
> > --- a/include/fcntl.h
> > +++ b/include/fcntl.h
> > [...]
> > +
> > +#ifndef _UNISTD_H
> > +#define F_OK 0
> > +#define R_OK 4
> > [...]
> 
> All _XXX_H macros should be considered entirely internal to the header
> they're used to protect. Aside from that, this sort of mechanism makes
> the logic in unistd.h very ugly (since it would have to check if
> fcntl.h was already included with _GNU_SOURCE or _BSD_SOURCE defined).
> 
> Since the definitions are exactly the same, multiple #defines are
> legal in C. If they work in C++ too, and if the compiler does not
> issue ugly warnings, I would just leave it be. Otherwise you could
> #undef them all first, or use #ifdef F_OK.
Will use #ifdef F_OK, I think. 
> > diff --git a/include/netdb.h b/include/netdb.h
> > index 33b7a0a..d1fe9a8 100644
> > --- a/include/netdb.h
> > +++ b/include/netdb.h
> > @@ -5,7 +5,7 @@
> > [...]
> > +
> > +int innetgr(const char *, const char *, const char *, const char
> > *);
> 
> This should be a separate patch, and should add stubs for the rest of
> the netgr functions at the same time (weak aliases in ent.c). Of
> course innetgr needs to be in its own file since it's not a weak alias
> and would pollute the standard namespace if put in ent.c.
OK.
I've put innetgr in its own file under src/stubs/
This probably means I'd need to change logwtmp, also (I had it in
stubs/utmpx.c)
> > diff --git a/include/signal.h b/include/signal.h
> > [...]
> > -#ifdef _GNU_SOURCE
> > +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> >  typedef void (*sighandler_t)(int);
> > +typedef sighandler_t sig_t;
> >  void (*bsd_signal(int, void (*)(int)))(int);
> > +#endif
> 
> I think sig_t should be BSD-only. That's how it is in glibc, and since
> it's so illogically named and short, I'd rather keep it out of the
> namespace even with _GNU_SOURCE.
> 
> In glibc, sighandler_t is GNU-only (not in BSD). So it might make
> sense to just have these be separate #ifdefs.

Maybe.

> > diff --git a/include/string.h b/include/string.h
> > index 8cf0ee9..9715713 100644
> > --- a/include/string.h
> > +++ b/include/string.h
> > [...]
> >  
> > +#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
> > +int bcmp (const void *, const void *, size_t);
> > +void bcopy (const void *, void *, size_t);
> > +void bzero (void *, size_t);
> > +int strcasecmp (const char *, const char *);
> > +int strncasecmp (const char *, const char *, size_t);
> > +char *index (const char *, int);
> > +char *rindex (const char *, int);
> > +int ffs (int);
> > +#endif
> 
> Wasn't all of this already coming from strings.h?

I think I did that before _GNU_SOURCE included strings.h ...

By the way, I noticed that strings.h seems to be specified (without
bzero & co.) in X/Open 2008. I'm inclined to test like so:

#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) \
 || !defined(_XOPEN_SOURCE)

That way, the X/Open namespace is respected, but -D_BSD_SOURCE
-D_XOPEN_SOURCE will get everything.

> That was just from a quick glance, so there might be some other issues
> remaining, but overall it looks good. Thanks!
Whitespace, I think.

Iswaac Dunham



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: _BSD_SOURCE support for musl ready
  2012-05-21 17:19   ` Isaac Dunham
@ 2012-05-21 17:43     ` Rich Felker
  0 siblings, 0 replies; 8+ messages in thread
From: Rich Felker @ 2012-05-21 17:43 UTC (permalink / raw)
  To: musl

On Mon, May 21, 2012 at 10:19:26AM -0700, Isaac Dunham wrote:
> OK.
> I've put innetgr in its own file under src/stubs/
> This probably means I'd need to change logwtmp, also (I had it in
> stubs/utmpx.c)

utmpx.c is not a big deal because it's no longer in the standard (it
was removed by POSIX 2008).

> > Wasn't all of this already coming from strings.h?
> 
> I think I did that before _GNU_SOURCE included strings.h ...
> 
> By the way, I noticed that strings.h seems to be specified (without
> bzero & co.) in X/Open 2008. I'm inclined to test like so:

These functions were removed in POSIX 2008; previously, they were
specified to be declared in strings.h.

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH]_BSD_SOURCE for musl, take 2.
  2012-05-21 13:36 ` Rich Felker
  2012-05-21 17:19   ` Isaac Dunham
@ 2012-05-21 18:31   ` Isaac Dunham
  2012-05-22 15:22     ` Rich Felker
  1 sibling, 1 reply; 8+ messages in thread
From: Isaac Dunham @ 2012-05-21 18:31 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 2753 bytes --]

Here's a second verion of the patch, with all the issues below
addressed.
I'm still declaring bsd_signal if _BSD_SOURCE is defined, because it
uses the signature of BSD signal().
On Mon, 21 May 2012 09:36:29 -0400
Rich Felker <dalias@aerifal.cx> wrote
> On Sun, May 20, 2012 at 11:26:51PM -0700, Isaac Dunham wrote:
> > diff --git a/include/fcntl.h b/include/fcntl.h
> > index 63f1beb..b776d38 100644
> > --- a/include/fcntl.h
> > +++ b/include/fcntl.h
> > [...]
> > +
> > +#ifndef _UNISTD_H
> > +#define F_OK 0
> > +#define R_OK 4
> > [...]
> 
> All _XXX_H macros should be considered entirely internal to the header
> they're used to protect. Aside from that, this sort of mechanism makes
> the logic in unistd.h very ugly (since it would have to check if
> fcntl.h was already included with _GNU_SOURCE or _BSD_SOURCE defined).
Fixed.
> > diff --git a/include/netdb.h b/include/netdb.h
> > index 33b7a0a..d1fe9a8 100644
> > --- a/include/netdb.h
> > +++ b/include/netdb.h
> > @@ -5,7 +5,7 @@
> > [...]
> > +
> > +int innetgr(const char *, const char *, const char *, const char
> > *);
> 
> This should be a separate patch, and should add stubs for the rest of
> the netgr functions at the same time (weak aliases in ent.c). Of
> course innetgr needs to be in its own file since it's not a weak alias
> and would pollute the standard namespace if put in ent.c.
Dropped from headers, along with logwtmp.h
Stubs have been left in place for now, so don't merge src/ ...
> > diff --git a/include/signal.h b/include/signal.h
> > [...]
> > -#ifdef _GNU_SOURCE
> > +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> >  typedef void (*sighandler_t)(int);
> > +typedef sighandler_t sig_t;
> >  void (*bsd_signal(int, void (*)(int)))(int);
> > +#endif
> 
> I think sig_t should be BSD-only. That's how it is in glibc, and since
> it's so illogically named and short, I'd rather keep it out of the
> namespace even with _GNU_SOURCE. 
> In glibc, sighandler_t is GNU-only (not in BSD). So it might make
> sense to just have these be separate #ifdefs.
Fixed
> > diff --git a/include/string.h b/include/string.h
> > index 8cf0ee9..9715713 100644
> > --- a/include/string.h
> > +++ b/include/string.h
> > [...]
> >  
> > +#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
> > +int bcmp (const void *, const void *, size_t);
> > +void bcopy (const void *, void *, size_t);
> > +void bzero (void *, size_t);
> > +int strcasecmp (const char *, const char *);
> > +int strncasecmp (const char *, const char *, size_t);
> > +char *index (const char *, int);
> > +char *rindex (const char *, int);
> > +int ffs (int);
> > +#endif
> 
> Wasn't all of this already coming from strings.h?
On inclusion of string.h with _GNU_SOURCE ? It doesn't seem so.
Fixed.

Isaac Dunham


[-- Attachment #2: master-bsd.diff --]
[-- Type: text/x-patch, Size: 16749 bytes --]

diff --git a/include/ctype.h b/include/ctype.h
index a85e907..8ceaa9f 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -30,7 +30,8 @@ int   toupper(int);
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 #define __NEED_locale_t
 #include <bits/alltypes.h>
diff --git a/include/dirent.h b/include/dirent.h
index d0a6b44..8162356 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -36,7 +36,7 @@ int            dirfd(DIR *);
 int alphasort(const struct dirent **, const struct dirent **);
 int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **));
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define DT_UNKNOWN 0
 #define DT_FIFO 1
 #define DT_CHR 2
diff --git a/include/fcntl.h b/include/fcntl.h
index 63f1beb..f826a5e 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -80,12 +80,24 @@ int posix_fallocate(int, off_t, off_t);
 #define S_IRWXO 0007
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define FAPPEND O_APPEND
 #define FFSYNC O_FSYNC
 #define FASYNC O_ASYNC
 #define FNONBLOCK O_NONBLOCK
 #define FNDELAY O_NDELAY
+
+#ifndef F_OK
+#define F_OK 0
+#define R_OK 4
+#define W_OK 2
+#define X_OK 1
+#define F_ULOCK 0
+#define F_LOCK  1
+#define F_TLOCK 2
+#define F_TEST  3
+int lockf(int, int, off_t);
+#endif
 #endif
 
 #ifdef _LARGEFILE64_SOURCE
diff --git a/include/grp.h b/include/grp.h
index 5185185..0a55c62 100644
--- a/include/grp.h
+++ b/include/grp.h
@@ -28,7 +28,7 @@ struct group  *getgrent(void);
 void           endgrent(void);
 void           setgrent(void);
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int getgrouplist(const char *, gid_t, gid_t *, int *);
 int setgroups(size_t, const gid_t *);
 int initgroups(const char *, gid_t);
diff --git a/include/math.h b/include/math.h
index 61738e6..d732648 100644
--- a/include/math.h
+++ b/include/math.h
@@ -330,8 +330,7 @@ double      trunc(double);
 float       truncf(float);
 long double truncl(long double);
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
-#define MAXFLOAT        3.40282347e+38F
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define M_E             2.7182818284590452354   /* e */
 #define M_LOG2E         1.4426950408889634074   /* log_2 e */
 #define M_LOG10E        0.43429448190325182765  /* log_10 e */
@@ -345,7 +344,13 @@ long double truncl(long double);
 #define M_2_SQRTPI      1.12837916709551257390  /* 2/sqrt(pi) */
 #define M_SQRT2         1.41421356237309504880  /* sqrt(2) */
 #define M_SQRT1_2       0.70710678118654752440  /* 1/sqrt(2) */
+#endif
 
+#if defined(_XOPEN_SOURCE)
+#define MAXFLOAT        3.40282347e+38F
+#endif
+
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
 extern int signgam;
 
 double      j0(double);
@@ -358,6 +363,7 @@ double      yn(int, double);
 #endif
 
 #ifdef _GNU_SOURCE
+#define HUGE        3.40282347e+38F
 double      scalb(double, double);
 float       scalbf(float, float);
 long double scalbl(long double, long double);
diff --git a/include/net/if.h b/include/net/if.h
index 00c763a..e862c7c 100644
--- a/include/net/if.h
+++ b/include/net/if.h
@@ -21,7 +21,7 @@ void if_freenameindex (struct if_nameindex *);
 
 
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 
 #include <sys/socket.h>
 
diff --git a/include/netdb.h b/include/netdb.h
index 33b7a0a..82c78dc 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -5,7 +5,7 @@
 extern "C" {
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define __NEED_size_t
 #endif
 
@@ -118,7 +118,7 @@ struct protoent *getprotoent (void);
 struct protoent *getprotobyname (const char *);
 struct protoent *getprotobynumber (int);
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 const char *hstrerror(int);
 struct hostent *gethostbyname (const char *);
 int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
index c8a1a4b..797ce68 100644
--- a/include/netinet/tcp.h
+++ b/include/netinet/tcp.h
@@ -2,5 +2,22 @@
 #define _NETINET_TCP_H
 
 #define TCP_NODELAY 1
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#include <sys/types.h>
+#include <sys/socket.h>
+#define TCP_MAXSEG	 2
+#define TCP_CORK	 3
+#define TCP_KEEPIDLE	 4
+#define TCP_KEEPINTVL	 5
+#define TCP_KEEPCNT	 6
+#define TCP_SYNCNT	 7
+#define TCP_LINGER2	 8
+#define TCP_DEFER_ACCEPT 9
+#define TCP_WINDOW_CLAMP 10
+#define TCP_INFO	 11
+#define	TCP_QUICKACK	 12
+#define TCP_CONGESTION	 13
+#define TCP_MD5SIG	 14
+#endif
 
 #endif
diff --git a/include/setjmp.h b/include/setjmp.h
index b024c44..88fb950 100644
--- a/include/setjmp.h
+++ b/include/setjmp.h
@@ -9,7 +9,8 @@ extern "C" {
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 typedef unsigned long sigjmp_buf[(128+sizeof(jmp_buf))/sizeof(long)];
 #ifdef _GNU_SOURCE
 #define jmp_buf sigjmp_buf
@@ -19,7 +20,8 @@ void siglongjmp (sigjmp_buf, int);
 #endif
 
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 int _setjmp (jmp_buf);
 void _longjmp (jmp_buf, int);
 #endif
diff --git a/include/signal.h b/include/signal.h
index 38f369b..616801b 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -6,7 +6,8 @@ extern "C" {
 #endif
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 #ifdef _GNU_SOURCE
 #define __siginfo siginfo
@@ -204,9 +205,16 @@ void (*sigset(int, void (*)(int)))(int);
 #define SIGSTKSZ 8192
 #endif
 
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+void (*bsd_signal(int, void (*)(int)))(int);
+#endif
+
+#ifdef _BSD_SOURCE
+typedef void (*sig_t)(int);
+#endif
+
 #ifdef _GNU_SOURCE
 typedef void (*sighandler_t)(int);
-void (*bsd_signal(int, void (*)(int)))(int);
 int sigisemptyset(const sigset_t *);
 #define SA_NOMASK SA_NODEFER
 #define SA_ONESHOT SA_RESETHAND
diff --git a/include/stdio.h b/include/stdio.h
index 355f425..e4740eb 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -10,7 +10,8 @@ extern "C" {
 #define __NEED_size_t
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 #define __NEED_ssize_t
 #define __NEED_off_t
 #endif
@@ -120,7 +121,8 @@ char *tmpnam(char *);
 FILE *tmpfile(void);
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 FILE *fmemopen(void *, size_t, const char *);
 FILE *open_memstream(char **, size_t *);
 FILE *fdopen(int, const char *);
@@ -146,12 +148,13 @@ char *ctermid(char *);
 #endif
 
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 #define P_tmpdir "/tmp"
 char *tempnam(const char *, const char *);
 #endif
 
-#if defined(_GNU_SOURCE)
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define L_cuserid 20
 char *cuserid(char *);
 #undef off64_t
diff --git a/include/stdlib.h b/include/stdlib.h
index 11331d9..644325e 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -78,7 +78,8 @@ size_t wcstombs (char *, const wchar_t *, size_t);
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 #ifndef WEXITSTATUS
 #define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
@@ -102,20 +103,24 @@ int rand_r (unsigned *);
 #endif
 
 
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
+char *realpath (const char *, char *);
+long int random (void);
+void srandom (unsigned int);
+char *initstate (unsigned int, char *, size_t);
+char *setstate (char *);
+#endif
+
 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
 int putenv (char *);
 int posix_openpt (int);
 int grantpt (int);
 int unlockpt (int);
 char *ptsname (int);
-char *realpath (const char *, char *);
 char *l64a (long);
 long a64l (const char *);
 void setkey (const char *);
-long int random (void);
-void srandom (unsigned int);
-char *initstate (unsigned int, char *, size_t);
-char *setstate (char *);
 double drand48 (void);
 double erand48 (unsigned short [3]);
 long int lrand48 (void);
@@ -127,11 +132,14 @@ unsigned short *seed48 (unsigned short [3]);
 void lcong48 (unsigned short [7]);
 #endif
 
-#if defined(_GNU_SOURCE)
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #include <alloca.h>
 char *mktemp (char *);
 void *valloc (size_t);
 void *memalign(size_t, size_t);
+#endif
+
+#ifdef _GNU_SOURCE
 int clearenv(void);
 int ptsname_r(int, char *, size_t);
 char *ecvt(double, int, int *, int *);
diff --git a/include/string.h b/include/string.h
index 8cf0ee9..24cb1ca 100644
--- a/include/string.h
+++ b/include/string.h
@@ -14,7 +14,8 @@ extern "C" {
 
 #define __NEED_size_t
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 #define __NEED_locale_t
 #endif
 
@@ -51,9 +52,13 @@ size_t strlen (const char *);
 
 char *strerror (int);
 
+#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
+#include <strings.h>
+#endif
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 char *strtok_r (char *, const char *, char **);
 int strerror_r (int, char *, size_t);
 char *stpcpy(char *, const char *);
@@ -67,7 +72,8 @@ int strcoll_l (const char *, const char *, locale_t);
 size_t strxfrm_l (char *, const char *, size_t, locale_t);
 #endif
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 void *memccpy (void *, const void *, int, size_t);
 #endif
 
@@ -77,9 +83,10 @@ size_t strlcpy (char *, const char *, size_t);
 #endif
 
 #ifdef _GNU_SOURCE
+#define	strdupa(x)	strcpy(alloca(strlen(x)+1),x)
 int strverscmp (const char *, const char *);
-int strcasecmp (const char *, const char *);
-int strncasecmp (const char *, const char *, size_t);
+int strcasecmp_l (const char *, const char *, locale_t);
+int strncasecmp_l (const char *, const char *, size_t, locale_t);
 char *strchrnul(const char *, int);
 char *strcasestr(const char *, const char *);
 char *strsep(char **, const char *);
diff --git a/include/sys/mman.h b/include/sys/mman.h
index a48c2b4..a45f11d 100644
--- a/include/sys/mman.h
+++ b/include/sys/mman.h
@@ -27,6 +27,9 @@ int munlockall (void);
 
 #ifdef _GNU_SOURCE
 void *mremap (void *, size_t, size_t, int, ...);
+#endif
+
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int madvise (void *, size_t, int);
 #endif
 
diff --git a/include/sys/stat.h b/include/sys/stat.h
index 5d50ae7..14a5424 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -90,7 +90,7 @@ int utimensat(int, const char *, const struct timespec [2], int);
 int lchmod(const char *, mode_t);
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #define S_IREAD S_IRUSR
 #define S_IWRITE S_IWUSR
 #define S_IEXEC S_IXUSR
diff --git a/include/sys/time.h b/include/sys/time.h
index fa98944..144dd23 100644
--- a/include/sys/time.h
+++ b/include/sys/time.h
@@ -8,7 +8,8 @@ extern "C" {
 
 int gettimeofday (struct timeval *, void *);
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 #define ITIMER_REAL    0
 #define ITIMER_VIRTUAL 1
@@ -26,7 +27,7 @@ int utimes (const char *, const struct timeval [2]);
 
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int futimes(int, const struct timeval [2]);
 int lutimes(const char *, const struct timeval [2]);
 int settimeofday (const struct timeval *, void *);
diff --git a/include/sys/types.h b/include/sys/types.h
index b9b65f6..4b1e374 100644
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -58,7 +58,7 @@ typedef __uint16_t u_int16_t;
 typedef __uint32_t u_int32_t;
 typedef __uint64_t u_int64_t;
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 typedef char *caddr_t;
 typedef unsigned char u_char;
 typedef unsigned short u_short, ushort;
diff --git a/include/sys/wait.h b/include/sys/wait.h
index e73594a..5e3012b 100644
--- a/include/sys/wait.h
+++ b/include/sys/wait.h
@@ -17,7 +17,7 @@ pid_t wait (int *);
 int waitid (idtype_t, id_t, siginfo_t *, int);
 pid_t waitpid (pid_t, int *, int );
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #include <sys/resource.h>
 pid_t wait3 (int *, int, struct rusage *);
 pid_t wait4 (pid_t, int *, int, struct rusage *);
diff --git a/include/syslog.h b/include/syslog.h
index e0d86c0..278945f 100644
--- a/include/syslog.h
+++ b/include/syslog.h
@@ -59,7 +59,8 @@ void openlog (const char *, int, int);
 int setlogmask (int);
 void syslog (int, const char *, ...);
 
-#if defined(_GNU_SOURCE)
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+#define _PATH_LOG "/dev/log"
 #define __NEED_va_list
 #include <bits/alltypes.h>
 void vsyslog (int, const char *, va_list);
diff --git a/include/termios.h b/include/termios.h
index 7690883..1041759 100644
--- a/include/termios.h
+++ b/include/termios.h
@@ -32,7 +32,7 @@ int tcflow (int, int);
 
 pid_t tcgetsid (int);
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 void cfmakeraw(struct termios *);
 int cfsetspeed(struct termios *, speed_t);
 #endif
diff --git a/include/time.h b/include/time.h
index 98d0111..067b519 100644
--- a/include/time.h
+++ b/include/time.h
@@ -18,7 +18,8 @@ extern "C" {
 #define __NEED_clock_t
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 #define __NEED_struct_timespec
 #define __NEED_clockid_t
 #define __NEED_timer_t
@@ -57,7 +58,8 @@ char *ctime (const time_t *);
 
 
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
- || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
+ || defined(_BSD_SOURCE)
 
 size_t strftime_l (char *, size_t, const char *, const struct tm *, locale_t);
 
diff --git a/include/unistd.h b/include/unistd.h
index b1a84d7..0112276 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -16,6 +16,12 @@ extern "C" {
 #define SEEK_CUR 1
 #define SEEK_END 2
 
+#if defined(_BSD_SOURCE) && !defined(L_SET)
+#define L_SET	SEEK_SET
+#define L_INCR	SEEK_CUR
+#define L_XTND	SEEK_END
+#endif
+
 #undef NULL
 #ifdef __cplusplus
 #define NULL 0
@@ -63,10 +69,13 @@ int rmdir(const char *);
 int truncate(const char *, off_t);
 int ftruncate(int, off_t);
 
+#ifndef F_OK
 #define F_OK 0
 #define R_OK 4
 #define W_OK 2
 #define X_OK 1
+#endif
+
 int access(const char *, int);
 int faccessat(int, const char *, int, int);
 
@@ -127,10 +136,12 @@ long fpathconf(int, int);
 long sysconf(int);
 size_t confstr(int, char *, size_t);
 
+#ifndef F_ULOCK
 #define F_ULOCK 0
 #define F_LOCK  1
 #define F_TLOCK 2
 #define F_TEST  3
+#endif
 
 #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
 int lockf(int, int, off_t);
@@ -143,10 +154,9 @@ int nice(int);
 void sync(void);
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int brk(void *);
 void *sbrk(intptr_t);
-pid_t forkall(void);
 pid_t vfork(void);
 int vhangup(void);
 int chroot(const char *);
@@ -155,6 +165,11 @@ int sethostname(const char *, size_t);
 int usleep(unsigned);
 unsigned ualarm(unsigned, unsigned);
 int setgroups(size_t, const gid_t []);
+char *getpass(const char *);
+#endif
+
+#ifdef _GNU_SOURCE
+pid_t forkall(void);
 int setresuid(uid_t, uid_t, uid_t);
 int setresgid(gid_t, gid_t, gid_t);
 int getresuid(uid_t *, uid_t *, uid_t *);
@@ -166,7 +181,6 @@ int getdtablesize(void);
 void setusershell(void);
 void endusershell(void);
 char *getusershell(void);
-char *getpass(const char *);
 #endif
 
 #ifdef _LARGEFILE64_SOURCE

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH]_BSD_SOURCE for musl, take 2.
  2012-05-21 18:31   ` [PATCH]_BSD_SOURCE for musl, take 2 Isaac Dunham
@ 2012-05-22 15:22     ` Rich Felker
  2012-05-22 23:19       ` Isaac Dunham
  0 siblings, 1 reply; 8+ messages in thread
From: Rich Felker @ 2012-05-22 15:22 UTC (permalink / raw)
  To: musl

On Mon, May 21, 2012 at 11:31:58AM -0700, Isaac Dunham wrote:
> Here's a second verion of the patch, with all the issues below
> addressed.

Looks good. A few more things, mostly just questions to make sure
stuff is ok..

> I'm still declaring bsd_signal if _BSD_SOURCE is defined, because it
> uses the signature of BSD signal().

Is there a reason for this? bsd_signal was a legacy SUSv3 function
removed in SUSv4/POSIX-2008, which was originally added mainly so that
programs written for BSD signal semantics could do:

#define signal bsd_signal

on non-BSD systems and still work. On glibc and musl it's utterly
useless since signal, by default, has BSD semantics. (POSIX allows
either and only BSD is sane.)

I doubt any code for BSD would ever be calling bsd_signal, as the
whole purpose of it is to provide an alternate function with BSD
behavior on non-BSD systems.

> diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
> index c8a1a4b..797ce68 100644
> --- a/include/netinet/tcp.h
> +++ b/include/netinet/tcp.h
> @@ -2,5 +2,22 @@
>  #define _NETINET_TCP_H
>  
>  #define TCP_NODELAY 1
> +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> +#include <sys/types.h>
> +#include <sys/socket.h>
> +#define TCP_MAXSEG	 2
> +#define TCP_CORK	 3
> +#define TCP_KEEPIDLE	 4
> [...]

TCP_* is in the reserved namespace for this header, so I think it
would be reasonable to define all the macros unconditionally. What
about the two includes, though? If they're needed to make GNU/BSD
programs work, we should still keep the check just for them.

> diff --git a/include/setjmp.h b/include/setjmp.h
> index b024c44..88fb950 100644
> --- a/include/setjmp.h
> +++ b/include/setjmp.h
> @@ -9,7 +9,8 @@ extern "C" {
>  
>  
>  #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
> - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
> + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
> + || defined(_BSD_SOURCE)
>  typedef unsigned long sigjmp_buf[(128+sizeof(jmp_buf))/sizeof(long)];
>  #ifdef _GNU_SOURCE
>  #define jmp_buf sigjmp_buf
   ^^^^^^^^^^^^^^^^^^^^^^^^^^
Just reminding myself this define is at best useless and at worst
harmful (big bloat). But changing it is separate; I'll do it after the
BSD commit.

> +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> +void (*bsd_signal(int, void (*)(int)))(int);
> +#endif

See comments at the top of this email. Unless there's a really good
reason to declare this with BSD_SOURCE I'd like to leave it just under
_GNU_SOURCE.

> diff --git a/include/unistd.h b/include/unistd.h
> index b1a84d7..0112276 100644
> --- a/include/unistd.h
> +++ b/include/unistd.h
> @@ -16,6 +16,12 @@ extern "C" {
>  #define SEEK_CUR 1
>  #define SEEK_END 2
>  
> +#if defined(_BSD_SOURCE) && !defined(L_SET)
> +#define L_SET	SEEK_SET
> +#define L_INCR	SEEK_CUR
> +#define L_XTND	SEEK_END

Is L_SET defined somewhere else?

> +#ifdef _GNU_SOURCE
> +pid_t forkall(void);

Also mainly a reminder to me: forkall is actually no longer supported
(and was never in glibc) and should just be removed, but I'll do that
in a separate patch too. (The semantics the function intends to meet
are just logically contradictory/impossible).

Rich


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH]_BSD_SOURCE for musl, take 2.
  2012-05-22 15:22     ` Rich Felker
@ 2012-05-22 23:19       ` Isaac Dunham
  0 siblings, 0 replies; 8+ messages in thread
From: Isaac Dunham @ 2012-05-22 23:19 UTC (permalink / raw)
  To: musl

On Tue, 22 May 2012 11:22:56 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> On Mon, May 21, 2012 at 11:31:58AM -0700, Isaac Dunham wrote:
> > Here's a second verion of the patch, with all the issues below
> > addressed.
> 
> Looks good. A few more things, mostly just questions to make sure
> stuff is ok..
> 
> > I'm still declaring bsd_signal if _BSD_SOURCE is defined, because it
> > uses the signature of BSD signal().
> 
> Is there a reason for this? bsd_signal was a legacy SUSv3 function
> removed in SUSv4/POSIX-2008, which was originally added mainly so that
> programs written for BSD signal semantics could do:
> 
> #define signal bsd_signal
> 
> on non-BSD systems and still work. On glibc and musl it's utterly
> useless since signal, by default, has BSD semantics. (POSIX allows
> either and only BSD is sane.)

> I doubt any code for BSD would ever be calling bsd_signal, as the
> whole purpose of it is to provide an alternate function with BSD
> behavior on non-BSD systems.

I had not realized that musl used BSD semantics.  You can drop that, if
you want.
 
> > diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
> > index c8a1a4b..797ce68 100644
> > --- a/include/netinet/tcp.h
> > +++ b/include/netinet/tcp.h
> > @@ -2,5 +2,22 @@
> >  #define _NETINET_TCP_H
> >  
> >  #define TCP_NODELAY 1
> > +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> > +#include <sys/types.h>
> > +#include <sys/socket.h>
> > +#define TCP_MAXSEG	 2
> > +#define TCP_CORK	 3
> > +#define TCP_KEEPIDLE	 4
> > [...]
> 
> TCP_* is in the reserved namespace for this header, so I think it
> would be reasonable to define all the macros unconditionally. What
> about the two includes, though? If they're needed to make GNU/BSD
> programs work, we should still keep the check just for them.

I'm not sure whether the includes are expected by some programs.

> > diff --git a/include/unistd.h b/include/unistd.h
> > index b1a84d7..0112276 100644
> > --- a/include/unistd.h
> > +++ b/include/unistd.h
> > @@ -16,6 +16,12 @@ extern "C" {
> >  #define SEEK_CUR 1
> >  #define SEEK_END 2
> >  
> > +#if defined(_BSD_SOURCE) && !defined(L_SET)
> > +#define L_SET	SEEK_SET
> > +#define L_INCR	SEEK_CUR
> > +#define L_XTND	SEEK_END
> 
> Is L_SET defined somewhere else?
Not in the patch; glibc has it in sys/file.h, which I somehow missed.
I'm inclined to say keep the test and I'll send a patch for that, but
take your pick.

For unknown reasons it looks like sys/file.h has no content except that
protected by _GNU_SOURCE | _BSD_SOURCE -- which sounds like an
unnecessary test.

Isaac Dunham



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-05-22 23:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-21  6:26 _BSD_SOURCE support for musl ready Isaac Dunham
2012-05-21 12:42 ` Isaac Dunham
2012-05-21 13:36 ` Rich Felker
2012-05-21 17:19   ` Isaac Dunham
2012-05-21 17:43     ` Rich Felker
2012-05-21 18:31   ` [PATCH]_BSD_SOURCE for musl, take 2 Isaac Dunham
2012-05-22 15:22     ` Rich Felker
2012-05-22 23:19       ` Isaac Dunham

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).