summaryrefslogtreecommitdiff
path: root/libiberty
diff options
context:
space:
mode:
authorShiz <hi@shiz.me>2015-06-20 14:51:16 +0200
committerShiz <hi@shiz.me>2015-06-20 15:23:00 +0200
commit1b7ea5c3a323b3306838fa39d1705007b77cbe0e (patch)
tree77661c8ce25941dbca99fc741de8ad5e71a5834d /libiberty
parent43c916b6dc5441c273bbefd789f8944f2d8c8070 (diff)
downloadcbb-gcc-4.6.4-1b7ea5c3a323b3306838fa39d1705007b77cbe0e.tar.bz2
cbb-gcc-4.6.4-1b7ea5c3a323b3306838fa39d1705007b77cbe0e.tar.xz
remove non-portable include and add back strverscmp.
See COPYING.MIDIPIX (9cd0746c) for copyright information. Signed-off-by: Shiz <hi@shiz.me>
Diffstat (limited to 'libiberty')
-rw-r--r--libiberty/strverscmp.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/libiberty/strverscmp.c b/libiberty/strverscmp.c
index 59ec5d2bc..0a005db2a 100644
--- a/libiberty/strverscmp.c
+++ b/libiberty/strverscmp.c
@@ -1,2 +1,44 @@
-/* empty translation unit for build system compatibility */
-typedef int dummy;
+/* strverscmp from musl. Copyright © 2005-2015 Rich Felker, et al.
+ Released under the MIT license.
+ See http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT?id=eceaf1d29f32656e5befb5e37b1f7db632f2e1dc for details. */
+#define _GNU_SOURCE
+#include <ctype.h>
+#include <string.h>
+
+int strverscmp(const char *l, const char *r)
+{
+ int haszero=1;
+ while (*l==*r) {
+ if (!*l) return 0;
+
+ if (*l=='0') {
+ if (haszero==1) {
+ haszero=0;
+ }
+ } else if (isdigit(*l)) {
+ if (haszero==1) {
+ haszero=2;
+ }
+ } else {
+ haszero=1;
+ }
+ l++; r++;
+ }
+ if (haszero==1 && (*l=='0' || *r=='0')) {
+ haszero=0;
+ }
+ if ((isdigit(*l) && isdigit(*r) ) && haszero) {
+ size_t lenl=0, lenr=0;
+ while (isdigit(l[lenl]) ) lenl++;
+ while (isdigit(r[lenr]) ) lenr++;
+ if (lenl==lenr) {
+ return (*l - *r);
+ } else if (lenl>lenr) {
+ return 1;
+ } else {
+ return -1;
+ }
+ } else {
+ return (*l - *r);
+ }
+}