Atoi,itoa and other functions in the Linux kernel __oracle

Source: Internet
Author: User

For ordinary applications, you can use functions such as header files Stdlib.h and stdio.h,string.h, and then call the required itoa (), atoi (),

But for the Linux kernel, the functions in the C library are not available.

There is a corresponding implementation in this Linux kernel:

For atoi () use Simple_strtol (), Simple_strtoul () and other functions to replace;
For itoa (), use snprintf ().

Other related functions, to see/LIB/VSPRINTF.C.
Like what:

Simple_strtoul,simple_strtol,simple_strtoull,strict_strtoul,strict_strtol,strict_strtoull,strict_strtoll, vsnprintf,vscnprintf

In addition, for common character-related processing functions, they are in/lib/string.c:

STRNICMP,STRCASECMP,STRNCASECMP,STRCPY,STRNCPY,STRLCPY,STRCAT,STRNCAT,STRLCAT,STRCMP,STRNCMP,STRCHR,STRRCHR, Strnchr,strstrip,strlen,strnlen,strspn,strcspn,strpbrk,strsep,sysfs_streq

and memory-related action functions:

Memset,memcpy,memmove,memcmp,memscan,strstr,memchr

Source:

/*

const char *PTR The target string, the string to be converted

Char **end the position of the destination string, general padding null

cardinality of int base//convert String

Return value: An integer represented by a string

*/

unsigned long long int strtoull (const char *ptr, char **end, int base)
{
unsigned long long ret = 0;
if (Base > 36)
Goto out;
while (*PTR) {
int digit;
if (*ptr >= ' 0 ' && *ptr <= ' 9 ' && *ptr < ' 0 ' + base)
digit = *ptr-' 0 ';
else if (*ptr >= ' a ' && *ptr < ' a ' + base-10)
digit = *ptr-' A ' + 10;
else if (*ptr >= ' a ' && *ptr < ' a ' + base-10)
digit = *ptr-' a ' + 10;
Else
Break
RET *= Base;
ret + digit;
ptr++;
}
Out
if (end)
*end = (char *) ptr;
return ret;
}


Example:

int index = Simple_strtol ("12345", NULL, 10);

The converted integer is 12345

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.