string(3) — Subroutines
NAME
strcasecmp, strcat, strcmp, strcpy, strdup − Perform operations on strings
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <string.h>
char ∗strcasecmp(
const char ∗s1,
const char ∗s2) ;
char ∗strcat(
char ∗s1,
const char ∗s2);
int strcmp(
const char ∗s1,
const char ∗s2);
char ∗strcpy(
char ∗s1,
const char ∗s2);
char ∗strdup(
const char ∗s1);
PARAMETERS
s1In strcat(), specifies the destination string for appending; in strcmp() and strcasecmp(), specifies the first of two strings to compare; in strcpy(), specifies the destination string for the copying; and in strdup(), specifies the string to be duplicated.
s2In strcat(), specifies the string to be appended to s1; in strcmp() and strcasecmp(), specifies the second of two strings to compare; and in strcpy(), specifies the source string for the copying.
Note
If you pass a NULL pointer as one of the const char ∗ or char ∗ parameters of a string manipulation function, the function generates a segmentation violation. To avoid the segmentation violation and cause the function to return zero, change the NULL pointer treatment for the process before issuing the call to the string manipulation function, as follows:
1.Include the system header file sys/uswitch.h.
2.Call the uswitch function, as described in the uswitch(3) reference page.
The following program illustrates this procedure:
#include <stdio.h>
#include <sys/types.h>
#include <sys/uswitch.h>
main()
{
size_t retval;
int uswitch_val;
uswitch_val = uswitch(USC_GET,0);
uswitch(USC_SET, uswitch_val | USW_NULLP);
retval = strdup(NULL);
DESCRIPTION
The strcat() function appends a copy of the string pointed to by the s2 parameter, including the terminating null character, to the end of the string pointed to by the s1 parameter. The beginning character of the string pointed to by the s2 parameter overwrites the null character at the end of the string pointed to by the s1 parameter. When operating on overlapping strings, the behavior of this function is unreliable.
The strcmp() function compares the string pointed to by the s1 parameter to the string pointed to by the s2 parameter. The sign of a nonzero value returned by strcmp() is determined by the sign of the difference between the values of the first pair of bytes (both interpreted as unsigned char) that differ in the two compared objects.
The strcasecmp() function is case insensitive. The returned lexicographic difference reflects a conversion to lower case. Note that strcasecmp() works for 7-bit ASCII compares only and should not be used in internationalized applications.
The strcmp() function compares strings based on the machine collating order. It does not use the locale-dependent sorting order. Use the strcol() or wcscol() functions for locale-dependent sorting.
The strcpy() function copies the string pointed to by the s2 parameter, including the terminating null character, to the location pointed to by the s1 parameter. When operating on overlapping strings, the behavior of this function is unreliable.
The strdup() function returns a pointer to a new string that is an exact duplicate of the string pointed to by the s1 parameter. The malloc() function is used to allocate space for the new string. The strdup() function is provided for compatibility with existing systems.
NOTES
AES Support Level:
Full use (strcat(), strcmp(), strcpy()).
RETURN VALUES
On successful completion, the strcat(), strcpy(), and strdup() functions return a pointer to the resulting string. Otherwise, these functions return a null pointer.
On successful completion, the strcmp() and strcasecmp() functions return an integer whose value is greater than, equal to, or less than 0 (zero), according to whether the s1 string is greater than, equal to, or less than the s2 string.
RELATED INFORMATION
Functions: malloc(3), memccpy(3), setlocale(3), strchr(3), strcoll(3), strlen(3), strncasecmp(3), strncat(3), strncmp(3), strncpy(3), strpbrk(3), strspn(3), strtok(3), strstr(3), strxfrm(3), swab(3), uswitch(3), wcscat(3), wcscmp(3), wcscpy(3).