peerguardian: Bump release
[openwrt/svn-archive/archive.git] / ipv6 / ndisc / patches / 110-strverscmp.patch
1 --- a/rdnssd/Makefile.am
2 +++ b/rdnssd/Makefile.am
3 @@ -27,7 +27,8 @@ conf_SCRIPTS = merge-hook
4 # rdnssd
5 rdnssd_SOURCES = rdnssd.c rdnssd.h \
6 icmp.c \
7 - netlink.c
8 + netlink.c \
9 + strverscmp.c
10 rdnssd_LDADD = $(LIBRT) \
11 @top_builddir@/compat/libcompat.a
12
13 --- a/rdnssd/Makefile.in
14 +++ b/rdnssd/Makefile.in
15 @@ -58,7 +58,7 @@ CONFIG_CLEAN_FILES =
16 am__installdirs = "$(DESTDIR)$(sbindir)" "$(DESTDIR)$(confdir)"
17 sbinPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
18 PROGRAMS = $(sbin_PROGRAMS)
19 -am_rdnssd_OBJECTS = rdnssd.$(OBJEXT) icmp.$(OBJEXT) netlink.$(OBJEXT)
20 +am_rdnssd_OBJECTS = rdnssd.$(OBJEXT) icmp.$(OBJEXT) netlink.$(OBJEXT) strverscmp.$(OBJEXT)
21 rdnssd_OBJECTS = $(am_rdnssd_OBJECTS)
22 am__DEPENDENCIES_1 =
23 rdnssd_DEPENDENCIES = $(am__DEPENDENCIES_1) \
24 @@ -213,7 +213,8 @@ conf_SCRIPTS = merge-hook
25 # rdnssd
26 rdnssd_SOURCES = rdnssd.c rdnssd.h \
27 icmp.c \
28 - netlink.c
29 + netlink.c \
30 + strverscmp.c
31
32 rdnssd_LDADD = $(LIBRT) \
33 @top_builddir@/compat/libcompat.a
34 @@ -336,6 +337,7 @@ distclean-compile:
35
36 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/icmp.Po@am__quote@
37 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netlink.Po@am__quote@
38 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strverscmp.Po@am__quote@
39 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rdnssd.Po@am__quote@
40
41 .c.o:
42 --- /dev/null
43 +++ b/rdnssd/strverscmp.c
44 @@ -0,0 +1,131 @@
45 +/* Compare strings while treating digits characters numerically.
46 + Copyright (C) 1997, 2000, 2002, 2004 Free Software Foundation, Inc.
47 + This file is part of the GNU C Library.
48 + Contributed by Jean-François Bignolles <bignolle@ecoledoc.ibp.fr>, 1997.
49 +
50 + This program is free software; you can redistribute it and/or modify
51 + it under the terms of the GNU General Public License as published by
52 + the Free Software Foundation; either version 2, or (at your option)
53 + any later version.
54 +
55 + This program is distributed in the hope that it will be useful,
56 + but WITHOUT ANY WARRANTY; without even the implied warranty of
57 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58 + GNU General Public License for more details.
59 +
60 + You should have received a copy of the GNU General Public License along
61 + with this program; if not, write to the Free Software Foundation,
62 + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
63 +
64 +#ifdef HAVE_CONFIG_H
65 +# include <config.h>
66 +#endif
67 +
68 +#include <string.h>
69 +#include <ctype.h>
70 +
71 +/* states: S_N: normal, S_I: comparing integral part, S_F: comparing
72 + fractional parts, S_Z: idem but with leading Zeroes only */
73 +#define S_N 0x0
74 +#define S_I 0x4
75 +#define S_F 0x8
76 +#define S_Z 0xC
77 +
78 +/* result_type: CMP: return diff; LEN: compare using len_diff/diff */
79 +#define CMP 2
80 +#define LEN 3
81 +
82 +
83 +/* ISDIGIT differs from isdigit, as follows:
84 + - Its arg may be any int or unsigned int; it need not be an unsigned char.
85 + - It's guaranteed to evaluate its argument exactly once.
86 + - It's typically faster.
87 + POSIX says that only '0' through '9' are digits. Prefer ISDIGIT to
88 + ISDIGIT_LOCALE unless it's important to use the locale's definition
89 + of `digit' even when the host does not conform to POSIX. */
90 +#define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)
91 +
92 +#undef __strverscmp
93 +#undef strverscmp
94 +
95 +#ifndef weak_alias
96 +# define __strverscmp strverscmp
97 +#endif
98 +
99 +/* Compare S1 and S2 as strings holding indices/version numbers,
100 + returning less than, equal to or greater than zero if S1 is less than,
101 + equal to or greater than S2 (for more info, see the texinfo doc).
102 +*/
103 +
104 +int
105 +__strverscmp (const char *s1, const char *s2)
106 +{
107 + const unsigned char *p1 = (const unsigned char *) s1;
108 + const unsigned char *p2 = (const unsigned char *) s2;
109 + unsigned char c1, c2;
110 + int state;
111 + int diff;
112 +
113 + /* Symbol(s) 0 [1-9] others (padding)
114 + Transition (10) 0 (01) d (00) x (11) - */
115 + static const unsigned int next_state[] =
116 + {
117 + /* state x d 0 - */
118 + /* S_N */ S_N, S_I, S_Z, S_N,
119 + /* S_I */ S_N, S_I, S_I, S_I,
120 + /* S_F */ S_N, S_F, S_F, S_F,
121 + /* S_Z */ S_N, S_F, S_Z, S_Z
122 + };
123 +
124 + static const int result_type[] =
125 + {
126 + /* state x/x x/d x/0 x/- d/x d/d d/0 d/-
127 + 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */
128 +
129 + /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
130 + CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
131 + /* S_I */ CMP, -1, -1, CMP, 1, LEN, LEN, CMP,
132 + 1, LEN, LEN, CMP, CMP, CMP, CMP, CMP,
133 + /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP,
134 + CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP,
135 + /* S_Z */ CMP, 1, 1, CMP, -1, CMP, CMP, CMP,
136 + -1, CMP, CMP, CMP
137 + };
138 +
139 + if (p1 == p2)
140 + return 0;
141 +
142 + c1 = *p1++;
143 + c2 = *p2++;
144 + /* Hint: '0' is a digit too. */
145 + state = S_N | ((c1 == '0') + (ISDIGIT (c1) != 0));
146 +
147 + while ((diff = c1 - c2) == 0 && c1 != '\0')
148 + {
149 + state = next_state[state];
150 + c1 = *p1++;
151 + c2 = *p2++;
152 + state |= (c1 == '0') + (ISDIGIT (c1) != 0);
153 + }
154 +
155 + state = result_type[state << 2 | ((c2 == '0') + (ISDIGIT (c2) != 0))];
156 +
157 + switch (state)
158 + {
159 + case CMP:
160 + return diff;
161 +
162 + case LEN:
163 + while (ISDIGIT (*p1++))
164 + if (!ISDIGIT (*p2++))
165 + return 1;
166 +
167 + return ISDIGIT (*p2) ? -1 : diff;
168 +
169 + default:
170 + return state;
171 + }
172 +}
173 +#ifdef weak_alias
174 +weak_alias (__strverscmp, strverscmp)
175 +#endif