String Conversion Function simple_strtoul in Linux

Source: Internet
Author: User

Some string conversion functions provided in the Linux kernel:

LIB/vsprintf. c

[HTML]
View plaincopyprint?
  1. 1. Unsigned long simple_strtoull (const char * CP, char ** endp, unsigned int Base)
  2. 2. Unsigned long simple_strtoul (const char * CP, char ** endp, unsigned int Base)
  3. 3. Long simple_strtol (const char * CP, char ** endp, unsigned int Base)
  4. 4. Long simple_strtoll (const char * CP, char ** endp, unsigned int Base)
  5. 5. Int strict_strtoul (const char * CP, unsigned int base, unsigned long * res)
  6. 6. Int strict_strtol (const char * CP, unsigned int base, long * res)
  7. 7. Int strict_strtoull (const char * CP, unsigned int base, unsigned long * res)
  8. 8. Int strict_strtoll (const char * CP, unsigned int base, long * res)
  9. 9. Int sprintf (char * Buf, const char * FMT ,...)
  10. 10. Int snprintf (char * Buf, size_t size, const char * FMT ,...)
  11. 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?
  1. Static ssize_t led_brightness_store (struct device * Dev,
  2. Struct device_attribute * ATTR,
    Const char * Buf,
    Size_t size)
  3. {
  4. Struct led_classdev * led_cdev = dev_get_drvdata (Dev );
  5. Ssize_t ret =-einval;
  6. Char * after;
  7. Unsigned long state = simple_strtoul (BUF, & after, 10 );
  8. Size_t COUNT = after-Buf;
  9. If (isspace (* after ))
  10. Count ++;
  11. If (COUNT = size ){
  12. Ret = count;
  13. If (State = led_off)
  14. Led_trigger_remove (led_cdev );
  15. Led_set_brightness (led_cdev, State );
  16. }
  17. Return ret;
  18. }
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?
  1. Char * kasprintf (gfp_t green,
    Const char * FMT ,...)
[CPP]
View plaincopyprint?
  1. 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

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.