Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
8396be0f
Commit
8396be0f
authored
Jul 16, 2012
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement parse_nat, an error-checking variant of atoi.
parent
e331aec3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
util.c
util.c
+21
-0
util.h
util.h
+1
-0
No files found.
util.c
View file @
8396be0f
...
...
@@ -27,6 +27,7 @@ THE SOFTWARE.
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/socket.h>
...
...
@@ -131,6 +132,26 @@ timeval_min_sec(struct timeval *d, time_t secs)
}
}
/* There's no good name for a positive int in C, call it nat. */
int
parse_nat
(
const
char
*
string
)
{
long
l
;
char
*
end
;
l
=
strtol
(
string
,
&
end
,
0
);
while
(
*
end
==
' '
||
*
end
==
'\t'
)
end
++
;
if
(
*
end
!=
'\0'
)
return
-
1
;
if
(
l
<
0
||
l
>
INT_MAX
)
return
-
1
;
return
(
int
)
l
;
}
int
parse_msec
(
const
char
*
string
)
{
...
...
util.h
View file @
8396be0f
...
...
@@ -77,6 +77,7 @@ int timeval_compare(const struct timeval *s1, const struct timeval *s2)
ATTRIBUTE
((
pure
));
void
timeval_min
(
struct
timeval
*
d
,
const
struct
timeval
*
s
);
void
timeval_min_sec
(
struct
timeval
*
d
,
time_t
secs
);
int
parse_nat
(
const
char
*
string
)
ATTRIBUTE
((
pure
));
int
parse_msec
(
const
char
*
string
)
ATTRIBUTE
((
pure
));
void
do_debugf
(
int
level
,
const
char
*
format
,
...)
ATTRIBUTE
((
format
(
printf
,
2
,
3
)))
COLD
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment