Writing Device Drivers

String Manipulation

These interfaces are generic string manipulation utilities similar to, and in most cases identical to the routines of the same names defined in the standard C library used by application programmers.

int stoi(char **str);

stoi(9F) converts the ASCII decimal numeric string pointed to by *str to an integer and returns the integer. *str is updated to point to the last character examined.

void numtos(unsigned long num, char *s);

numtos(9F) converts the integer num to an ASCII decimal string and copies the string to the location pointed to by s. The driver must provide the storage for the string s and ensure that it can contain the result.

char *strchr(const char *str, int chr);

strchr(9F) returns a pointer to the first occurrence of the character chr in the string pointed to by str, or NULL, if chr is not found in the string.

int strcmp(const char *s1, const char *s2);

strcmp(9F) compares two null-terminated character strings. It returns zero if they are identical; otherwise, it returns a nonzero value.

int strncmp(const char *s1, const char *s2, size_t n);

strncmp(9F) compares the first n characters of the two strings. It returns zero if these characters are identical; otherwise, it returns a nonzero value.

char *strcpy(char *dst, const char *srs);

strcpy(9F) copies the character string pointed to by srs to the location pointed to by dst. The driver must provide storage for the string dst and ensure that it is long enough.

char *strncpy(char *dst, const char *srs, size_t n);

strncpy(9F) copies n characters from the string pointed to by srs to the string pointed to by dst. The driver must provide storage for the string dst and ensure that it is long enough.

size_t strlen(const char *sp);

strlen(9F) returns the length of the character string pointed to by sp, not including the null-termination character.