/* | |
* Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. | |
* | |
* SPDX-License-Identifier: MIT | |
*/ | |
#include "aml_atoi.h" | |
#include "aml_isspace.h" | |
#include "aml_isdigit.h" | |
int atoi(const char *nptr) | |
{ | |
int result = 0; | |
int neg = 0; | |
char c = '\0'; | |
while ((c = *nptr++) && isspace(c)) | |
; | |
if (c == '-') { | |
neg = 1; | |
c = *nptr++; | |
} | |
while (isdigit(c)) { | |
result = result * 10 + (c - '0'); | |
c = *nptr++; | |
} | |
return neg ? -result : result; | |
} |