From: Isaac Dunham <idunham@lavabit.com>
To: musl@lists.openwall.com
Subject: [PATCH] string.h, _BSD_SOURCE, and *index()
Date: Thu, 12 Apr 2012 18:45:22 -0700 [thread overview]
Message-ID: <20120412184522.6c7b72a3@newbook> (raw)
[-- Attachment #1: Type: text/plain, Size: 884 bytes --]
I was working on _BSD_SOURCE for string.h.
Warning: several of the functions are mislabeled as _GNU_SOURCE in the
manpages.
Everything in strings.h should be available if _GNU_SOURCE ||
BSD_SOURCE is defined and string.h is included.
Actually, that's slightly an oversimplification-there are two
functions (*_l) that should be _GNU_SOURCE only.
(r)index was X/Open legacy, and has been dropped. The Open Group
recommended using
#define index(a,b) strchr((a),(b))
#define rindex(a,b) strrchr((a),(b))
Which will let us remove two more files if we do it (rindex.c & index.c)
However, would removing those break the ABI?
There are two patches attached: the first (string.diff) will define
everything from strings.h if defined _BSD_SOURCE || _GNU_SOURCE
The second patch (rindex.diff) applies the second change, but does not
remove (r)index.c, to prevent ABI breakage.
Isaac Dunham
[-- Attachment #2: string.diff --]
[-- Type: text/x-patch, Size: 2056 bytes --]
diff --git a/include/string.h b/include/string.h
index 4aa930e..cd09513 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,10 +67,21 @@ 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);
@@ -78,8 +89,8 @@ size_t strlcpy (char *, const char *, size_t);
#ifdef _GNU_SOURCE
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 *);
[-- Attachment #3: index.diff --]
[-- Type: text/x-patch, Size: 928 bytes --]
diff --git a/include/string.h b/include/string.h
index cd09513..ab9ba2d 100644
--- a/include/string.h
+++ b/include/string.h
@@ -77,8 +77,8 @@ 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);
+#define index(a,b) strchr((a),(b))
+#define rindex(a,b) strrchr((a),(b))
int ffs (int);
#endif
diff --git a/include/strings.h b/include/strings.h
index 345c651..f8fd255 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -17,8 +17,8 @@ void bzero (void *, size_t);
int ffs (int);
-char *index (const char *, int);
-char *rindex (const char *, int);
+#define index(a,b) strchr((a),(b))
+#define rindex(a,b) strrchr((a),(b))
int strcasecmp (const char *, const char *);
int strncasecmp (const char *, const char *, size_t);
next reply other threads:[~2012-04-13 1:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-13 1:45 Isaac Dunham [this message]
2012-04-13 1:52 ` Andre Renaud
2012-04-13 3:31 ` Rich Felker
2012-04-13 3:30 ` Rich Felker
2012-04-13 4:31 ` Isaac Dunham
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120412184522.6c7b72a3@newbook \
--to=idunham@lavabit.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).