Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
79e86db6
Commit
79e86db6
authored
Nov 23, 2012
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib: have local atoi, saves 1680 bytes
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
2086ab2b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletion
+52
-1
atoi.c
lib/atoi.c
+51
-0
lib.mk
lib/lib.mk
+1
-1
No files found.
lib/atoi.c
0 → 100644
View file @
79e86db6
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2012 CERN (www.cern.ch)
* Author: Alessandro Rubini <rubini@gnudd.com>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdlib.h>
/*
* This is a minimal atoi, that doesn't call strtol. Since we are only
* calling atoi, it saves XXXX bytes of library code
*/
int
atoi
(
const
char
*
s
)
{
int
sign
=
1
,
res
=
0
;
/* as (mis)designed in atoi, we make no error check */
if
(
*
s
==
'-'
)
{
sign
=
-
1
;
s
++
;
}
while
(
*
s
>=
'0'
&&
*
s
<=
'9'
)
res
=
res
*
10
+
*
s
++
-
'0'
;
return
res
*
sign
;
}
#ifdef TEST_ATOI
/*
* You can try this:
*
make atoi CFLAGS="-DTEST_ATOI -Wall" && \
./atoi foo 0 45 -45 9876543210 -9345.2 97.5 666devils
*
*/
#include <stdio.h>
/* just to be sure I call mine and not a #define somewhere in the headers */
int
__local_atoi
(
const
char
*
s
)
__attribute__
((
alias
(
"atoi"
)));
int
main
(
int
argc
,
char
**
argv
)
{
int
i
;
for
(
i
=
1
;
i
<
argc
;
i
++
)
printf
(
"%i
\n
"
,
__local_atoi
(
argv
[
i
]));
return
0
;
}
#endif
/* TEST_ATOI */
lib/lib.mk
View file @
79e86db6
obj-$(CONFIG_MPRINTF) += lib/mprintf.o
obj-y += lib/util.o
obj-y += lib/util.o
lib/atoi.o
obj-$(CONFIG_ETHERBONE) += lib/arp.o lib/icmp.o lib/ipv4.o lib/bootp.o
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