Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Wednesday, July 27, 2022
 
 

string(3C)

Name

string - string operations

Synopsis

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

Description

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:

strcat(3C)

string copying and concatenation operations

strchr(3C)

string search operations

strcmp(3C)

string comparison

strcoll(3C)

string collation

strdup(3C)

string duplication

strerror(3C)

get error message string

strerrordesc_np(3C)

get error name and message strings

strlen(3C)

string length operations

strsignal(3C)

get string describing signal

strtok(3C)

separate strings into tokens

strxfrm(3C)

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

Notes

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.