mailing list of musl libc
 help / color / mirror / code / Atom feed
* Namespace issues, missing functions, _BSD_SOURCE for unistd.h
@ 2012-04-05 22:55 Isaac Dunham
  2012-04-06  0:10 ` Rich Felker
  0 siblings, 1 reply; 12+ messages in thread
From: Isaac Dunham @ 2012-04-05 22:55 UTC (permalink / raw)
  To: musl

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

Attached is a patch that should add proper BSD_SOURCE support for
<unistd.h>. I'm not sure that the formatting/style is proper, and the
exact arrangement is rather arbitrary.  But I've moved a lot of things
that were wrongly grouped in either ANSI namespace or GNU-only
namespace.

BSD || XOPEN means the macro test should be
#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
I see glibc turns on both of these with _GNU_SOURCE.

Misplaced (should be BSD || XOPEN):
(Properly, these require XOPEN >= 500)
usleep, ualarm, fchown, fchdir, lchown,vhangup,
apparently fsync?

Missing (BSD || XOPEN):
getwd,ttyslot,sethostid,get/setdomainname,revoke,profil,acct,get/end/setusershell

BSD||GNU:
setlogin, getpass

These and chroot also should be available with lower values of
_XOPEN_SOURCE

Incompatible:
BSD uses setpgrp the same way everyone else uses setpgid--a
substitution macro will do the job. That's what glibc does and what I
did.

And there may be one or two more that I didn't mention in here because
I lost track.

Isaac Dunham

[-- Attachment #2: unistd.diff --]
[-- Type: text/x-patch, Size: 3488 bytes --]

diff --git a/include/unistd.h b/include/unistd.h
index 7662e51..de173dc 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
+#define L_INCR
+#define L_XTND
+#endif
+
 #undef NULL
 #ifdef __cplusplus
 #define NULL 0
@@ -47,13 +53,10 @@ ssize_t pread(int, void *, size_t, off_t);
 ssize_t pwrite(int, const void *, size_t, off_t);
 
 int chown(const char *, uid_t, gid_t);
-int fchown(int, uid_t, gid_t);
-int lchown(const char *, uid_t, gid_t);
 int fchownat(int, const char *, uid_t, gid_t, int);
 
 int link(const char *, const char *);
 int linkat(int, const char *, int, const char *, int);
-int symlink(const char *, const char *);
 int symlinkat(const char *, int, const char *);
 ssize_t readlink(const char *, char *, size_t);
 ssize_t readlinkat(int, const char *, char *, size_t);
@@ -61,7 +64,6 @@ int unlink(const char *);
 int unlinkat(int, const char *, int);
 int rmdir(const char *);
 int truncate(const char *, off_t);
-int ftruncate(int, off_t);
 
 #define F_OK 0
 #define R_OK 4
@@ -71,7 +73,6 @@ int access(const char *, int);
 int faccessat(int, const char *, int, int);
 
 int chdir(const char *);
-int fchdir(int);
 char *getcwd(char *, size_t);
 
 unsigned alarm(unsigned);
@@ -101,21 +102,23 @@ int isatty(int);
 pid_t tcgetpgrp(int);
 int tcsetpgrp(int, pid_t);
 
+#if defined(_BSD_SOURCE) && !defined(_POSIX_C_SOURCE) \
+ && !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE) \
+ && !defined(_GNU_SOURCE)
+#define setpgrp setpgid
+int symlink(const char *, const char *);
+#endif
+
 uid_t getuid(void);
 uid_t geteuid(void);
 gid_t getgid(void);
 gid_t getegid(void);
 int getgroups(int, gid_t []);
 int setuid(uid_t);
-int setreuid(uid_t, uid_t);
-int seteuid(uid_t);
 int setgid(gid_t);
-int setregid(gid_t, gid_t);
-int setegid(gid_t);
 
 char *getlogin(void);
 int getlogin_r(char *, size_t);
-int gethostname(char *, size_t);
 char *ctermid(char *);
 
 int getopt(int, char * const [], const char *);
@@ -138,23 +141,52 @@ pid_t setpgrp(void);
 char *crypt(const char *, const char *);
 void encrypt(char *, int);
 void swab(const void *, void *, ssize_t);
-long gethostid(void);
 int nice(int);
 void sync(void);
 int getdtablesize(void);
 #endif
 
+#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) \
+ || defined(_POSIX_SOURCE) || defined(_GNU_SOURCE)
+
+#if !( (_POSIX_SOURCE - 0) < 200112L )
+int seteuid(uid_t);
+int setegid(gid_t);
+#endif
+
+int ftruncate(int, off_t);
+int sethostname(const char *, size_t);
+#endif
+
+#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+int setreuid(uid_t, uid_t);
+int setregid(gid_t, gid_t);
+
+int fchown(int, uid_t, gid_t);
+int lchown(const char *, uid_t, gid_t);
+
+int fchdir(int);
+
+pid_t vfork(void);
+int vhangup(void);
+int usleep(unsigned);
+unsigned ualarm(unsigned, unsigned);
+
+long gethostid(void);
+#endif
+
+#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
+int gethostname(char *, size_t);
+int chroot(const char *); /* Also old 
+#endif
+
+
 #ifdef _GNU_SOURCE
 int brk(void *);
 void *sbrk(intptr_t);
 pid_t forkall(void);
-pid_t vfork(void);
-int vhangup(void);
-int chroot(const char *);
 int getpagesize(void);
-int sethostname(const char *, size_t);
-int usleep(unsigned);
-unsigned ualarm(unsigned, unsigned);
+
 int setgroups(size_t, const gid_t []);
 int setresuid(uid_t, uid_t, uid_t);
 int setresgid(gid_t, gid_t, gid_t);

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

end of thread, other threads:[~2012-04-07  5:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-05 22:55 Namespace issues, missing functions, _BSD_SOURCE for unistd.h Isaac Dunham
2012-04-06  0:10 ` Rich Felker
2012-04-06  1:03   ` Isaac Dunham
2012-04-06  1:52     ` Rich Felker
2012-04-06  1:45   ` [PATCH] _BSD_SOURCE for unistd.h, take 2 Isaac Dunham
2012-04-06  2:04     ` Rich Felker
2012-04-06  2:40       ` Isaac Dunham
2012-04-06  2:51         ` Rich Felker
2012-04-06 14:48     ` Rich Felker
2012-04-06 15:48       ` Isaac Dunham
2012-04-06 23:32         ` Rich Felker
2012-04-07  5:47           ` 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).