Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022



string - string operations


#include <string.h>
#include <strings.h>


These functions perform various operations on strings (arrays of characters), which are given as arguments that point to strings. Depending on the function, strings may be either terminated by a null character or have a maximum length of n bytes. They are designed for use with encodings representing each character as a single byte, and all character counts are measured in individual bytes, even if a string with multibyte characters is used. Except where noted in the individual function descriptions, they do not check for null pointers, and programs may crash if passing null or otherwise invalid pointers to these functions, or specifying sizes larger than the memory allocation in use for the string. Use of adi(7) may help in detecting buffer overflows or invalid pointer usage in code.

For details of the string functions, see the following man pages:


string copying and concatenation operations


string search operations


string comparison


string collation


string duplication


get error message string


get error name and message strings


string length operations


get string describing signal


separate strings into tokens


string transformation

For corresponding functions that operate on wide-character strings, see wcstring(3C).

Multibyte strings may be handled by using mbstowcs(3C) or mbsrtowcs(3C) to convert the string to a wide-character string first.

Functions specific to handling UTF-8 encoded multibyte strings are also available. See the u8_strcmp(3C), u8_textprep_str(3C), and u8_validate(3C) man pages for these functions.

See Also

mbstowcs(3C), mbsrtowcs(3C), memory(3C), setlocale(3C), stpcpy(3C), stpncpy(3C), strcasecmp(3C), strcasecmp_l(3C), strcasestr(3C), strcat(3C), strcat_s(3C), strchr(3C), strchrnul(3C), strcmp(3C), strcoll(3C), strcoll_l(3C), strcpy(3C), strcpy_s(3C), strcspn(3C), strdup(3C), strdupa(3C), strlcat(3C), strlcpy(3C), strlen(3C), strncasecmp(3C), strncasecmp_l(3C), strncat(3C), strncat_s(3C), strncmp(3C), strncpy(3C), strncpy_s(3C), strndup(3C), strndupa(3C), strnlen(3C), strnlen_s(3C), strnstr(3C), strpbrk(3C), strrchr(3C), strsep(3C), strspn(3C), strstr(3C), strtok(3C), strtok_r(3C), strtok_s(3C), strxfrm(3C), strxfrm_l(3C), u8_strcmp(3C), u8_textprep_str(3C), u8_validate(3C), wcstring(3C), strcadd(3GEN), strccpy(3GEN), streadd(3GEN), strecpy(3GEN), strfind(3GEN), strrspn(3GEN), strtrns(3GEN)

Appendix E, Security Considerations When Using C Functions, in Developer’s Guide to Oracle Solaris 11.4 Security

Handling Characters and Character Strings in Internationalizing and Localizing Applications in Oracle Solaris


All of these functions, except as noted in their individual man pages, assume the default “C” locale. For some locales, strxfrm(3C) should be applied to the strings before they are passed to the functions.