1 #include <libc/src/unistd.h> 2 #include <libc/src/stdlib.h> 3 #include <libc/src/ctype.h> 4 #include <libsystem/syscall.h> 5 abs(int i)6int abs(int i) 7 { 8 return i < 0 ? -i : i; 9 } 10 labs(long i)11long labs(long i) 12 { 13 return i < 0 ? -i : i; 14 } 15 llabs(long long i)16long long llabs(long long i) 17 { 18 return i < 0 ? -i : i; 19 } 20 atoi(const char * str)21int atoi(const char *str) 22 { 23 int n = 0, neg = 0; 24 25 while (isspace(*str)) 26 { 27 str++; 28 } 29 30 switch (*str) 31 { 32 case '-': 33 neg = 1; 34 break; 35 case '+': 36 str++; 37 break; 38 } 39 40 /* Compute n as a negative number to avoid overflow on INT_MIN */ 41 while (isdigit(*str)) 42 { 43 n = 10 * n - (*str++ - '0'); 44 } 45 46 return neg ? n : -n; 47 } 48 49 /** 50 * @brief 退出进程 51 * 52 * @param status 53 */ exit(int status)54void exit(int status) 55 { 56 syscall_invoke(SYS_EXIT, status, 0, 0, 0, 0, 0, 0, 0); 57 }