mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-10 01:34:12 +00:00
string: Add atol
Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
parent
ebf1cf3aa3
commit
550e39913f
2 changed files with 23 additions and 0 deletions
22
src/string.c
22
src/string.c
|
@ -1,5 +1,7 @@
|
||||||
/* SPDX-License-Identifier: MIT */
|
/* SPDX-License-Identifier: MIT */
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
// Routines based on The Public Domain C Library
|
// Routines based on The Public Domain C Library
|
||||||
|
@ -185,3 +187,23 @@ char *strrchr(const char *s, int c)
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Very naive, no attempt to check for errors */
|
||||||
|
long atol(const char *s)
|
||||||
|
{
|
||||||
|
long val = 0;
|
||||||
|
bool neg = false;
|
||||||
|
|
||||||
|
if (*s == '-') {
|
||||||
|
neg = true;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*s >= '0' && *s <= '9')
|
||||||
|
val = (val * 10) + (*s++ - '0');
|
||||||
|
|
||||||
|
if (neg)
|
||||||
|
val = -val;
|
||||||
|
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ size_t strlen(const char *s);
|
||||||
size_t strnlen(const char *s, size_t n);
|
size_t strnlen(const char *s, size_t n);
|
||||||
char *strchr(const char *s, int c);
|
char *strchr(const char *s, int c);
|
||||||
char *strrchr(const char *s, int c);
|
char *strrchr(const char *s, int c);
|
||||||
|
long atol(const char *s);
|
||||||
|
|
||||||
static inline int tolower(int c)
|
static inline int tolower(int c)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue