forked from regehr/str2long_contest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgedare.c
More file actions
35 lines (33 loc) · 669 Bytes
/
gedare.c
File metadata and controls
35 lines (33 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "str2long.h"
long str2long_gedare (const char *input)
{
long rv;
char t;
if (input) {
if (*input == 0) {
error = 1;
} else {
rv = 0;
if (*input == '-') {
while (*++input) {
t = *input - '0';
if ( rv < LONG_MIN/10L || rv*10L < LONG_MIN + t ) {
error = 1;
break;
}
rv = rv * 10L - t;
}
} else {
do {
t = *input - '0';
if ( rv > LONG_MAX/10L || rv*10L > LONG_MAX - t ) {
error = 1;
break;
}
rv = rv * 10L + t;
} while (*++input);
}
}
}
return rv;
}