Some string conversion functions provided in the Linux kernel:
LIB/vsprintf. c
[HTML]
View plaincopyprint?
- 1. Unsigned 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 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 * res)
- 8. Int strict_strtoll (const char * CP, unsigned int base, long * res)
- 9. Int sprintf (char * Buf, const char * FMT ,...)
- 10. Int snprintf (char * Buf, size_t size, const char * FMT ,...)
- 11. Int sscanf (const char * Buf, const char * FMT ,...)
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, ...) 10. int snprintf(char *buf, size_t size, const char *fmt, ...) 11. int sscanf(const char *buf, const char *fmt, ...)
Unsigned long simple_strtoull (const char * CP, char ** endp, unsigned int Base)
Function: converts a string into unsigend long data.
Return: The converted data is returned.
Parameter: CP points to the start of the string, endp points to the end of the string to be analyzed, base is the base number to use (base number), and base is 0 indicates that the base is automatically determined through CP, the base number automatically recognized by the function: '0x 'indicates hexadecimal, '0' indicates octal, and other values are considered as hexadecimal. The valid characters for converting a function to a number are: [0, F]. For example, if CP = "0x12str" and base = 0, the return value of unsigned long is 18, * endp = "STR ". Parameters are the same.
[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;
- }
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: The converted data is returned.
Int strict_strtoul (const char * CP, unsigned int base, unsigned long * res)
Function: converts a string to the unsigend long type.
Return: If the conversion is successful, 0 is returned. Otherwise, negative is returned. Res points to the converted unsigned long data.
Note: This function strictly requires the string to which CP points. The string to which CP points must be a real string in the form of unsigned long. The string must start with "0x", "0", and [0, F]. All valid characters in the middle are [0, F]. Otherwise, the return value is negative. It processes the \ n character at the end of the string. Same below
Long long simple_strtoll (const char * CP, char ** endp, unsigned int Base)
Function: converts a string to the sigend long type.
Return: The converted data is returned.
Int strict_strtol (const char * CP, unsigned int base, long * res)
Function: converts a string to the sigend long type.
Return: If the conversion is successful, 0 is returned. Otherwise, negative is returned. Res points to the converted signed long data.
Int strict_strtoull (const char * CP, unsigned int base, unsigned long * res)
Function: converts a string to the unsigend long type.
Return: If the conversion is successful, 0 is returned. Otherwise, negative is returned. Res points to the converted unsigned long data.
Int strict_strtoll (const char * CP, unsigned int base, long * res)
Function: converts a string to the sigend long type.
Return: If the conversion is successful, 0 is returned. Otherwise, negative is returned. Res points to the converted signed long data.
Int sprintf (char * Buf, const char * FMT ,...)
Function: format the output string. It is similar to printf, but uses the string Buf as the output object.
Return: 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. It is similar to printf, but uses the string Buf as the output object. The size is the Buf size (including '\ 0' characters ).
Return: returns the number of characters written to the Buf string.
Int sscanf (const char * Buf, const char * FMT ,...)
Function: format the input string, similar to scanf, but uses the string Buf as the input object.
Return: returns the number of characters read from the Buf string.
LIB/kasprintf
[CPP]
View plaincopyprint?
- Char * kasprintf (gfp_t green,
Const char * FMT ,...)
[CPP]
View plaincopyprint?
- Char * kasprintf (gfp_t green,
Const char * FMT ,...)
Char * kasprintf (gfp_t green, const char * FMT ,...)
Char * kasprintf (gfp_t green, const char * FMT ,...)
Function: format the output string to a segment of memory allocated with the green code.
Return: returns a string pointer to the content.
Source: http://blog.csdn.net/tommy_wxie/article/details/7480087