Some of the string conversion functions available in the Linux kernel:
Lib/vsprintf.c
[HTML]View PlainCopyprint?
- 1. Unsigned long long simple_strtoull (const char *CP, char **ENDP, unsigned int base)
- 2. unsigned long Simple_strtoul (const char *CP, char **ENDP, unsigned int base)
- 3. Long Simple_strtol (const char *CP, char **ENDP, unsigned int base)
- 4. Long Long simple_strtoll (const char *CP, char **ENDP, unsigned int base)
- 5. int Strict_strtoul (const char *CP, unsigned int base, unsigned long *res)
- 6. int strict_strtol (const char *CP, unsigned int base, long *res)
- 7. int strict_strtoull (const char *CP, unsigned int base, unsigned long long *res)
- 8. int strict_strtoll (const char *CP, unsigned int base, long long *res)
- 9. int sprintf (char *buf, const char *FMT, ...)
- int snprintf (char *buf, size_t size, const char *FMT, ...)
- One. int sscanf (const 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.
[CPP]View PlainCopyprint?
- Static ssize_t Led_brightness_store (struct device *dev,
- struct Device_attribute *attr, const char *buf, size_t size)
- {
- struct Led_classdev *led_cdev = dev_get_drvdata (dev);
- ssize_t ret =-einval;
- Char *after;
- unsigned long state = Simple_strtoul (buf, &after, 10);
- 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);
- }
- return ret;
- }
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
[CPP]View Plaincopyprint?
- Char *kasprintf (gfp_t GFP, const char *fmt, ...)
<textarea style= "Display:none;" readonly= "readonly" name= "code" class= "CPP" >char *kasprintf (gfp_t GFP, const Char *fmt, ...) </textarea>
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