mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] string.h, _BSD_SOURCE, and *index()
@ 2012-04-13  1:45 Isaac Dunham
  2012-04-13  1:52 ` Andre Renaud
  2012-04-13  3:30 ` Rich Felker
  0 siblings, 2 replies; 5+ messages in thread
From: Isaac Dunham @ 2012-04-13  1:45 UTC (permalink / raw)
  To: musl

[-- 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);

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

end of thread, other threads:[~2012-04-13  4:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-13  1:45 [PATCH] string.h, _BSD_SOURCE, and *index() Isaac Dunham
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

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).