Reprint: http://blog.csdn.net/tommy_wxie/article/details/7480087
Some of the string conversion functions available in the Linux kernel:
Lib/vsprintf.c
UnsignedLong LongSimple_strtoull (Const Char*CP,Char**ENDP, unsignedint Base) unsignedLongSimple_strtoul (Const Char*CP,Char**ENDP, unsignedint Base) LongSimple_strtol (Const Char*CP,Char**ENDP, unsignedint Base) Long LongSimple_strtoll (Const Char*CP,Char**ENDP, unsignedint Base) intStrict_strtoul (Const Char*CP, unsignedint Base, unsignedLong*Res)intStrict_strtol (Const Char*CP, unsignedint Base,Long*Res)intStrict_strtoull (Const Char*CP, unsignedint Base, unsignedLong Long*Res)intStrict_strtoll (Const Char*CP, unsignedint Base,Long Long*Res)intsprintfChar*buf,Const Char*FMT, ...) intsnprintfChar*BUF, size_t size,Const Char*FMT, ...) intsscanfConst Char*buf,Const Char*FMT, ...)
unsigned long long simple_strtoull (const char *CP, char **ENDP, unsigned int base)
Function: Converts a string into unsigend long Long data.
Return: Returns the converted data.
Parameters: CP points to the beginning of the string, ENDP points at the end of the parsed string, base is the base to use (number of digits), base 0 means that the base is determined by the CP, the function is automatically recognized by the cardinality: ' 0x ' means 16, ' 0 ' means 8, and the other is 10. The valid characters for the function to be converted to numbers are: [0,f]. For example: CP = "0x12str", base = 0, then return unsigned long long to 18,*ENDP = "str". Parameters below.
Staticssize_t Led_brightness_store (structDevice *Dev,structDevice_attribute *attr,Const Char*buf, size_t size) { structLed_classdev *led_cdev =dev_get_drvdata (Dev); ssize_t ret= -EINVAL; Char*After ; unsignedLongState = Simple_strtoul (buf, &after,Ten); size_t Count= after-buf; if(Isspace (*After )) Count++; if(Count = =size) {ret=count; if(state = =led_off) Led_trigger_remove (Led_cdev); Led_set_brightness (Led_cdev, state); } returnret; }
unsigned long Simple_strtoul (const char *CP, char **ENDP, unsigned int base)
Function: Converts a string into unsigend long data.
Return: Returns the converted data.
int Strict_strtoul (const char *CP, unsigned int base, unsigned long *res)
Function: Converts a string into a unsigend long type.
Return: The conversion succeeded in returning 0, otherwise a negative is returned. Res points to the converted unsigned Long data.
Description: The function is strict with the string that the CP points to, and the string that the CP points to must be a true unsigned long string. The string must begin with "0x", "0", [0,f], all valid characters in the middle [0,f], otherwise the return is negative. It handles the last "\ n" character of the string. Same below
Long Long simple_strtoll (const char *CP, char **ENDP, unsigned int base)
Function: Converts a string into a sigend long long type.
Return: Returns the converted data.
int strict_strtol (const char *CP, unsigned int base, long *res)
Function: Converts a string into a sigend long type.
Return: The conversion succeeded in returning 0, otherwise a negative is returned. Res points to the converted signed Long data.
int strict_strtoull (const char *CP, unsigned int base, unsigned long long *res)
Function: Converts a string into a unsigend long long type.
Return: The conversion succeeded in returning 0, otherwise a negative is returned. Res points to the converted unsigned long Long data.
int strict_strtoll (const char *CP, unsigned int base, long long *res)
Function: Converts a string into a sigend long long type.
Return: The conversion succeeded in returning 0, otherwise a negative is returned. Res points to the converted signed long Long data.
int sprintf (char *buf, const char *FMT, ...)
Function: Format the output string, similar to printf, just use string buf as the output object.
Returns: Returns the number of characters written to the BUF string.
int snprintf (char *buf, size_t size, const char *FMT, ...)
Function: Format the output string, similar to printf, just use string buf as the output object. where size is buf (including the ' \ S ' character).
Returns: Returns the number of characters written to the BUF string.
int sscanf (const char *BUF, const char *FMT, ...)
Function: Format input string, similar to scanf, just use string buf as input object.
Returns: Returns the number of characters that read the BUF string.
lib/kasprintf
Char Const char *fmt, ...)
Char *kasprintf (gfp_t GFP, const char *FMT, ...)
Function: Formats the output string into a section of memory allocated by GFP.
Return: Returns a pointer to the string that is pointing to the content.
String conversion function Simple_strtoul in Linux