Browse Source

Added isspace() and made strtoul() accept whitespace, as per POSIX.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
ca3db0bf11
1 changed files with 17 additions and 0 deletions
  1. 17
    0
      src/core/misc.c

+ 17
- 0
src/core/misc.c View File

@@ -152,10 +152,27 @@ int inet_aton ( const char *cp, struct in_addr *inp ) {
152 152
 	return 0;
153 153
 }
154 154
 
155
+int isspace ( int c ) {
156
+	switch ( c ) {
157
+	case ' ':
158
+	case '\f':
159
+	case '\n':
160
+	case '\r':
161
+	case '\t':
162
+	case '\v':
163
+		return 1;
164
+	default:
165
+		return 0;
166
+	}
167
+}
168
+
155 169
 unsigned long strtoul ( const char *p, char **endp, int base ) {
156 170
 	unsigned long ret = 0;
157 171
 	unsigned int charval;
158 172
 
173
+	while ( isspace ( *p ) )
174
+		p++;
175
+
159 176
 	if ( base == 0 ) {
160 177
 		base = 10;
161 178
 		if ( *p == '0' ) {

Loading…
Cancel
Save