mirror of
https://github.com/drasko/codezero.git
synced 2026-02-18 04:43:18 +01:00
Added a simplified ascii_to_int() implementation.
Removed dependency on hard-coded pager id. Pager id is now passed as an environment string `pagerid' to tasks. Alternatively, this could take space in the utcb of each task.
This commit is contained in:
26
conts/libc/include/atoi.h
Normal file
26
conts/libc/include/atoi.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef __ATOI_H__
|
||||
#define __ATOI_H__
|
||||
|
||||
static inline int power(int exp, int mul)
|
||||
{
|
||||
int total = 1;
|
||||
|
||||
while (exp > 0) {
|
||||
total *= mul;
|
||||
exp--;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
static inline int atoi(char *str)
|
||||
{
|
||||
int size = strlen(str);
|
||||
int iter = size - 1;
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
num += ((int)str[iter - i] - 48) * power(i, 10);
|
||||
return num;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user