diff mbox

[v3] Improve strsep

Message ID 4fb02cf3-1ea7-1e79-1088-bdc10fe4cb67@linaro.org
State New
Headers show

Commit Message

Adhemerval Zanella Netto Dec. 13, 2016, 6:10 p.m. UTC
With a correction and a suggestion below I think this ok.

On 13/12/2016 10:44, Wilco Dijkstra wrote:

> -

> -__STRING_INLINE char *__strsep_3c (char **__s, char __reject1, char __reject2,

> -				   char __reject3);

> -__STRING_INLINE char *

> -__strsep_3c (char **__s, char __reject1, char __reject2, char __reject3)

> -{

> -  char *__retval = *__s;

> -  if (__retval != NULL)

> -    {

> -      char *__cp = __retval;

> -      while (1)

> -	{

> -	  if (*__cp == '\0')

> -	    {

> -	      __cp = NULL;

> -	  break;

> -	    }

> -	  if (*__cp == __reject1 || *__cp == __reject2 || *__cp == __reject3)

> -	    {

> -	      *__cp++ = '\0';

> -	      break;

> -	    }

> -	  ++__cp;

> -	}

> -      *__s = __cp;

> -    }

> -  return __retval;

> -}

> -# ifdef __USE_MISC

> -#  define strsep(s, reject) __strsep (s, reject)


Without the indirection some link namespace tests fails with:

[initial] fpathconf -> [libc.a(fpathconf.o)] __fstatvfs64 -> [libc.a(fstatvfs.o)] __internal_statvfs -> [libc.a(internal_statvfs.o)] strsep

Previously strsep was redirected internally to __strsep_g and it
contains the requires libc_hidden_{def,proto}, however I think we
just can simplify internal strsep altogether by simply replace
__strset_g definition and usage with __strsep.  We still need
to strong_alias strsep to __strsep_g and export it unfortunately.

Based on your patch:
diff mbox

Patch

diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c
index 116ec49..dd2edde 100644
--- a/elf/dl-minimal.c
+++ b/elf/dl-minimal.c
@@ -377,4 +377,3 @@  __strsep (char **stringp, const char *delim)
   return begin;
 }
 weak_alias (__strsep, strsep)
-strong_alias (__strsep, __strsep_g)
diff --git a/include/string.h b/include/string.h
index e145bfd..dffafd5 100644
--- a/include/string.h
+++ b/include/string.h
@@ -91,8 +91,7 @@  libc_hidden_proto (strcoll)
 libc_hidden_proto (__strcoll_l)
 libc_hidden_proto (__strxfrm_l)
 libc_hidden_proto (__strtok_r)
-extern char *__strsep_g (char **__stringp, const char *__delim);
-libc_hidden_proto (__strsep_g)
+libc_hidden_proto (__strsep)
 libc_hidden_proto (strnlen)
 libc_hidden_proto (__strnlen)
 libc_hidden_proto (memmem)
@@ -125,7 +124,7 @@  libc_hidden_builtin_proto (ffs)
 extern __typeof (__stpcpy) __stpcpy attribute_hidden;
 extern __typeof (__strdup) __strdup attribute_hidden;
 extern __typeof (__strerror_r) __strerror_r attribute_hidden;
-extern __typeof (__strsep_g) __strsep_g attribute_hidden;
+extern __typeof (__strsep) __strsep attribute_hidden;
 
 extern __typeof (memchr) memchr attribute_hidden;
 extern __typeof (memcmp) memcmp attribute_hidden;
diff --git a/string/strsep.c b/string/strsep.c
index 68581c8..6af0bdc 100644
--- a/string/strsep.c
+++ b/string/strsep.c
@@ -45,5 +45,5 @@  __strsep (char **stringp, const char *delim)
   return begin;
 }
 weak_alias (__strsep, strsep)
+libc_hidden_def (__strsep)
 strong_alias (__strsep, __strsep_g)
-libc_hidden_def (__strsep_g)
diff --git a/sysdeps/unix/sysv/linux/internal_statvfs.c b/sysdeps/unix/sysv/linux/internal_statvfs.c
index 012f93f..ce649cd 100644
--- a/sysdeps/unix/sysv/linux/internal_statvfs.c
+++ b/sysdeps/unix/sysv/linux/internal_statvfs.c
@@ -168,7 +168,7 @@  __statvfs_getflags (const char *name, int fstype, int fd)
              char *cp = mntbuf.mnt_opts;
              char *opt;
 
-             while ((opt = strsep (&cp, ",")) != NULL)
+             while ((opt = __strsep (&cp, ",")) != NULL)
                if (strcmp (opt, "ro") == 0)
                  result |= ST_RDONLY;
                else if (strcmp (opt, "nosuid") == 0)