summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2019-06-26 12:46:32 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2019-06-26 12:48:52 -0700
commite0d220aa13abc03cd04dec7f9d1812a2177ec743 (patch)
tree6c87fd59dda3495272acbf59b22d2a122b6c8b7c
parentbacccb4e51dfdcf9c4481c6e27afc3d0c244d0d0 (diff)
downloadgnulib-e0d220aa13abc03cd04dec7f9d1812a2177ec743.tar.gz
strverscmp: sync from glibc
* lib/strverscmp.c: Sync from glibc, except use UTF-8 encoding in comments, include libc-config.h, define __strverscmp to be strverscmp, and don’t assume types line uint8_t and int8_t that that C99 doesn’t guarantee. [!_LIBC]: Include libc-config.h; define __strverscmp. Include stdint.h. (__strverscmp): Assume C99. Use uint_least8_t and int_least8_t instead of unsigned char and signed char. * modules/strverscmp (Depends-on): Add libc-config, stdint.
-rw-r--r--ChangeLog13
-rw-r--r--lib/strverscmp.c35
-rw-r--r--modules/strverscmp2
3 files changed, 30 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 1e00145220..5ae108e25c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2019-06-26 Paul Eggert <eggert@cs.ucla.edu>
+
+ strverscmp: sync from glibc
+ * lib/strverscmp.c: Sync from glibc, except use UTF-8 encoding in
+ comments, include libc-config.h, define __strverscmp to be
+ strverscmp, and don’t assume types line uint8_t and int8_t that
+ that C99 doesn’t guarantee.
+ [!_LIBC]: Include libc-config.h; define __strverscmp.
+ Include stdint.h.
+ (__strverscmp): Assume C99. Use uint_least8_t
+ and int_least8_t instead of unsigned char and signed char.
+ * modules/strverscmp (Depends-on): Add libc-config, stdint.
+
2019-06-25 Bruno Haible <bruno@clisp.org>
tss tests: Add tests for destructors and races.
diff --git a/lib/strverscmp.c b/lib/strverscmp.c
index 7e87057124..83922eab49 100644
--- a/lib/strverscmp.c
+++ b/lib/strverscmp.c
@@ -17,10 +17,12 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#if !_LIBC
-# include <config.h>
+#ifndef _LIBC
+# include <libc-config.h>
+# define __strverscmp strverscmp
#endif
+#include <stdint.h>
#include <string.h>
#include <ctype.h>
@@ -35,9 +37,6 @@
#define CMP 2
#define LEN 3
-#ifndef weak_alias
-# define __strverscmp strverscmp
-#endif
/* Compare S1 and S2 as strings holding indices/version numbers,
returning less than, equal to or greater than zero if S1 is less than,
@@ -49,13 +48,10 @@ __strverscmp (const char *s1, const char *s2)
{
const unsigned char *p1 = (const unsigned char *) s1;
const unsigned char *p2 = (const unsigned char *) s2;
- unsigned char c1, c2;
- int state;
- int diff;
/* Symbol(s) 0 [1-9] others
Transition (10) 0 (01) d (00) x */
- static const unsigned char next_state[] =
+ static const uint_least8_t next_state[] =
{
/* state x d 0 */
/* S_N */ S_N, S_I, S_Z,
@@ -64,7 +60,7 @@ __strverscmp (const char *s1, const char *s2)
/* S_Z */ S_N, S_F, S_Z
};
- static const signed char result_type[] =
+ static const int_least8_t result_type[] =
{
/* state x/x x/d x/0 d/x d/d d/0 0/x 0/d 0/0 */
@@ -77,15 +73,16 @@ __strverscmp (const char *s1, const char *s2)
if (p1 == p2)
return 0;
- c1 = *p1++;
- c2 = *p2++;
+ unsigned char c1 = *p1++;
+ unsigned char c2 = *p2++;
/* Hint: '0' is a digit too. */
- state = S_N + ((c1 == '0') + (isdigit (c1) != 0));
+ int state = S_N + ((c1 == '0') + (isdigit (c1) != 0));
+ int diff;
while ((diff = c1 - c2) == 0)
{
if (c1 == '\0')
- return diff;
+ return diff;
state = next_state[state];
c1 = *p1++;
@@ -96,22 +93,20 @@ __strverscmp (const char *s1, const char *s2)
state = result_type[state * 3 + (((c2 == '0') + (isdigit (c2) != 0)))];
switch (state)
- {
+ {
case CMP:
return diff;
case LEN:
while (isdigit (*p1++))
- if (!isdigit (*p2++))
- return 1;
+ if (!isdigit (*p2++))
+ return 1;
return isdigit (*p2) ? -1 : diff;
default:
return state;
- }
+ }
}
-#ifdef weak_alias
libc_hidden_def (__strverscmp)
weak_alias (__strverscmp, strverscmp)
-#endif
diff --git a/modules/strverscmp b/modules/strverscmp
index be0291fece..c2eefd5200 100644
--- a/modules/strverscmp
+++ b/modules/strverscmp
@@ -7,6 +7,8 @@ m4/strverscmp.m4
Depends-on:
extensions
+libc-config [test $HAVE_STRVERSCMP = 0]
+stdint [test $HAVE_STRVERSCMP = 0]
string
configure.ac: