libbsd: Branch 'master' - 6 commits

Guillem Jover guillem at kemper.freedesktop.org
Tue Mar 13 01:32:06 UTC 2018


 include/bsd/libutil.h        |    5 ++++-
 include/bsd/md5.h            |    4 ++++
 include/bsd/nlist.h          |    4 ++++
 include/bsd/readpassphrase.h |    4 ++++
 include/bsd/stdlib.h         |    7 ++++++-
 include/bsd/string.h         |    7 ++++++-
 include/bsd/stringlist.h     |    5 +++++
 include/bsd/sys/cdefs.h      |    8 ++++++++
 include/bsd/sys/queue.h      |    4 ++++
 include/bsd/sys/tree.h       |    4 ++++
 include/bsd/timeconv.h       |    4 ++++
 include/bsd/vis.h            |    4 ++++
 include/bsd/wchar.h          |    4 ++++
 src/local-elf.h              |    4 ++++
 src/progname.c               |   20 ++++++++++++++------
 15 files changed, 79 insertions(+), 9 deletions(-)

New commits:
commit 1f8a3f7bccfc84b195218ad0086ebd57049c3490
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Mar 6 01:39:45 2018 +0100

    Fix function declaration protection for glibc already providing them
    
    On non-glibc based systems we cannot unconditionally use the
    __GLIBC_PREREQ macro as it gets expanded before evaluation. Instead,
    if it is undefined, define it to 0.
    
    We should also always declare these functions on non-glibc based
    systems. And on systems with a new enough glibc, which provides these
    functions, we should still provide the declarations if _GNU_SOURCE
    is *not* defined.
    
    Reported-by: Jörg Krause <joerg.krause at embedded.rocks>

diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 8d33d1f..a5b063c 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -71,7 +71,8 @@ int sradixsort(const unsigned char **base, int nmemb,
                const unsigned char *table, unsigned endbyte);
 
 void *reallocf(void *ptr, size_t size);
-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 26)
+#if !defined(__GLIBC__) || \
+    (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 26) || !defined(_GNU_SOURCE)))
 void *reallocarray(void *ptr, size_t nmemb, size_t size);
 #endif
 
diff --git a/include/bsd/string.h b/include/bsd/string.h
index 29097f6..f987fee 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -46,7 +46,8 @@ size_t strlcat(char *dst, const char *src, size_t siz);
 char *strnstr(const char *str, const char *find, size_t str_len);
 void strmode(mode_t mode, char *str);
 
-#if defined(_GNU_SOURCE) && defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25)
+#if !defined(__GLIBC__) || \
+    (defined(__GLIBC__) && (!__GLIBC_PREREQ(2, 25) || !defined(_GNU_SOURCE)))
 void explicit_bzero(void *buf, size_t len);
 #endif
 __END_DECLS
diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h
index b4c8f30..d1cc419 100644
--- a/include/bsd/sys/cdefs.h
+++ b/include/bsd/sys/cdefs.h
@@ -59,6 +59,14 @@
 #endif
 
 /*
+ * On non-glibc based systems, we cannot unconditionally use the
+ * __GLIBC_PREREQ macro as it gets expanded before evaluation.
+ */
+#ifndef __GLIBC_PREREQ
+#define __GLIBC_PREREQ(maj, min) 0
+#endif
+
+/*
  * Some kFreeBSD headers expect those macros to be set for sanity checks.
  */
 #ifndef _SYS_CDEFS_H_
commit b20272f5a966333b49fdf2bda797e2a9f0227404
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Mar 6 01:42:52 2018 +0100

    Remove <features.h> inclusion from <bsd/libutil.h>
    
    This is a non-portable header, and we should not assume it is present.
    Let the first system header pull it in if needed.

diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h
index ccca29a..e5f148a 100644
--- a/include/bsd/libutil.h
+++ b/include/bsd/libutil.h
@@ -39,7 +39,6 @@
 #ifndef LIBBSD_LIBUTIL_H
 #define LIBBSD_LIBUTIL_H
 
-#include <features.h>
 #ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
 #else
commit 11ec8f1e5dfa1c10e0c9fb94879b6f5b96ba52dd
Author: Guillem Jover <guillem at hadrons.org>
Date:   Tue Mar 6 01:41:35 2018 +0100

    Handle systems missing <sys/cdefs.h>
    
    This is a non-portable header, and we cannot expect it to be provided by
    the system libc (e.g. musl). We just need and rely on declaration that
    we have defined ourselves in our own <bsd/sys/cdefs.h>. So we switch to
    only ever assume that.
    
    Fixes: https://bugs.freedesktop.org/105281

diff --git a/include/bsd/libutil.h b/include/bsd/libutil.h
index 45b3b15..ccca29a 100644
--- a/include/bsd/libutil.h
+++ b/include/bsd/libutil.h
@@ -40,7 +40,11 @@
 #define LIBBSD_LIBUTIL_H
 
 #include <features.h>
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 #include <sys/types.h>
 #include <stdint.h>
 #include <stdio.h>
diff --git a/include/bsd/md5.h b/include/bsd/md5.h
index 5f3ae46..bf36a30 100644
--- a/include/bsd/md5.h
+++ b/include/bsd/md5.h
@@ -27,7 +27,11 @@ typedef struct MD5Context {
 	uint8_t buffer[MD5_BLOCK_LENGTH];	/* input buffer */
 } MD5_CTX;
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 #include <sys/types.h>
 
 __BEGIN_DECLS
diff --git a/include/bsd/nlist.h b/include/bsd/nlist.h
index cb297e8..8767117 100644
--- a/include/bsd/nlist.h
+++ b/include/bsd/nlist.h
@@ -27,7 +27,11 @@
 #ifndef LIBBSD_NLIST_H
 #define LIBBSD_NLIST_H
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 
 struct nlist {
 	union {
diff --git a/include/bsd/readpassphrase.h b/include/bsd/readpassphrase.h
index 14744b8..5eb8021 100644
--- a/include/bsd/readpassphrase.h
+++ b/include/bsd/readpassphrase.h
@@ -31,7 +31,11 @@
 #define RPP_SEVENBIT    0x10		/* Strip the high bit from input. */
 #define RPP_STDIN       0x20		/* Read from stdin, not /dev/tty */
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 #include <sys/types.h>
 
 __BEGIN_DECLS
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index ebc9638..8d33d1f 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -42,7 +42,11 @@
 #ifndef LIBBSD_STDLIB_H
 #define LIBBSD_STDLIB_H
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 #include <sys/stat.h>
 #include <stdint.h>
 
diff --git a/include/bsd/string.h b/include/bsd/string.h
index 6798bf6..29097f6 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -33,7 +33,11 @@
 #ifndef LIBBSD_STRING_H
 #define LIBBSD_STRING_H
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 #include <sys/types.h>
 
 __BEGIN_DECLS
diff --git a/include/bsd/stringlist.h b/include/bsd/stringlist.h
index ff30cac..dd71496 100644
--- a/include/bsd/stringlist.h
+++ b/include/bsd/stringlist.h
@@ -31,7 +31,12 @@
 
 #ifndef LIBBSD_STRINGLIST_H
 #define LIBBSD_STRINGLIST_H
+
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 #include <sys/types.h>
 
 /*
diff --git a/include/bsd/sys/queue.h b/include/bsd/sys/queue.h
index 4a94ea7..ac00026 100644
--- a/include/bsd/sys/queue.h
+++ b/include/bsd/sys/queue.h
@@ -33,7 +33,11 @@
 #ifndef LIBBSD_SYS_QUEUE_H
 #define LIBBSD_SYS_QUEUE_H
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 
 /*
  * This file defines four types of data structures: singly-linked lists,
diff --git a/include/bsd/sys/tree.h b/include/bsd/sys/tree.h
index 628bec0..325b382 100644
--- a/include/bsd/sys/tree.h
+++ b/include/bsd/sys/tree.h
@@ -30,7 +30,11 @@
 #ifndef LIBBSD_SYS_TREE_H
 #define LIBBSD_SYS_TREE_H
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 
 /*
  * This file defines data structures for different types of trees:
diff --git a/include/bsd/timeconv.h b/include/bsd/timeconv.h
index e2a2c55..a426bd3 100644
--- a/include/bsd/timeconv.h
+++ b/include/bsd/timeconv.h
@@ -41,7 +41,11 @@
 #ifndef LIBBSD_TIMECONV_H
 #define LIBBSD_TIMECONV_H
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 #include <stdint.h>
 #include <time.h>
 
diff --git a/include/bsd/vis.h b/include/bsd/vis.h
index 970dfdd..ab5430c 100644
--- a/include/bsd/vis.h
+++ b/include/bsd/vis.h
@@ -72,7 +72,11 @@
  */
 #define	UNVIS_END	1	/* no more characters */
 
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 
 __BEGIN_DECLS
 char	*vis(char *, int, int, int);
diff --git a/include/bsd/wchar.h b/include/bsd/wchar.h
index 33a500e..7216503 100644
--- a/include/bsd/wchar.h
+++ b/include/bsd/wchar.h
@@ -40,7 +40,11 @@
 #define LIBBSD_WCHAR_H
 
 #include <stddef.h>
+#ifdef LIBBSD_OVERLAY
 #include <sys/cdefs.h>
+#else
+#include <bsd/sys/cdefs.h>
+#endif
 #include <sys/types.h>
 
 __BEGIN_DECLS
commit 5ba8c5bab05c8315439c351e91ce554d4f092915
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Mar 5 00:37:47 2018 +0100

    progname: Port to Windows
    
    Define the directory separator depending on the system targetted.
    
    Reported-by: Progyan Bhattacharya <progyanb at acm.org>

diff --git a/src/progname.c b/src/progname.c
index 10c3701..3edbf24 100644
--- a/src/progname.c
+++ b/src/progname.c
@@ -34,6 +34,12 @@
 #include <string.h>
 #include <stdlib.h>
 
+#if defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
+#define LIBBSD_IS_PATHNAME_SEPARATOR(c) ((c) == '/' || (c) == '\\')
+#else
+#define LIBBSD_IS_PATHNAME_SEPARATOR(c) ((c) == '/')
+#endif
+
 #ifdef HAVE___PROGNAME
 extern const char *__progname;
 #else
@@ -58,11 +64,13 @@ getprogname(void)
 void
 setprogname(const char *progname)
 {
-	const char *last_slash;
+	size_t i;
 
-	last_slash = strrchr(progname, '/');
-	if (last_slash == NULL)
-		__progname = progname;
-	else
-		__progname = last_slash + 1;
+	for (i = strlen(progname); i > 0; i--) {
+		if (LIBBSD_IS_PATHNAME_SEPARATOR(progname[i - 1])) {
+			__progname = progname + i;
+			return;
+		}
+	}
+	__progname = progname;
 }
commit 0093ca2b0e3fcbb71649682a84def684340f01c9
Author: Guillem Jover <guillem at hadrons.org>
Date:   Mon Mar 5 00:02:34 2018 +0100

    Handle SPARC V8+ on Sun Studio compiler

diff --git a/src/local-elf.h b/src/local-elf.h
index f7cbd83..c11bf6e 100644
--- a/src/local-elf.h
+++ b/src/local-elf.h
@@ -186,7 +186,7 @@
 #define ELF_TARG_MACH	EM_SPARCV9
 #define ELF_TARG_CLASS	ELFCLASS64
 #else
-#if defined(__sparc_v9__)
+#if defined(__sparc_v9__) || defined(__sparcv9)
 #define ELF_TARG_MACH	EM_SPARC32PLUS
 #else
 #define ELF_TARG_MACH	EM_SPARC
commit 0b65d43963fc1bea195e94e3af922a7893bf6fcd
Author: James Clarke <jrtc27 at jrtc27.com>
Date:   Sun Mar 4 23:44:52 2018 +0100

    Add support for ELF machine EM_SPARC32PLUS
    
    32-bit SPARC on V8+ uses a different ELF machine type.
    
    Fixes: https://bugs.gentoo.org/634550
    Signed-off-by: Guillem Jover <guillem at hadrons.org>

diff --git a/src/local-elf.h b/src/local-elf.h
index 1faf182..f7cbd83 100644
--- a/src/local-elf.h
+++ b/src/local-elf.h
@@ -186,7 +186,11 @@
 #define ELF_TARG_MACH	EM_SPARCV9
 #define ELF_TARG_CLASS	ELFCLASS64
 #else
+#if defined(__sparc_v9__)
+#define ELF_TARG_MACH	EM_SPARC32PLUS
+#else
 #define ELF_TARG_MACH	EM_SPARC
+#endif
 #define ELF_TARG_CLASS	ELFCLASS32
 #endif
 #define ELF_TARG_DATA	ELFDATA2MSB


More information about the libbsd mailing list