From 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 14 Aug 2025 22:58:58 -0500 Subject: removing all downloaded devdocs files --- devdocs/c/string%2Fbyte%2Fstrndup.html | 46 ---------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 devdocs/c/string%2Fbyte%2Fstrndup.html (limited to 'devdocs/c/string%2Fbyte%2Fstrndup.html') diff --git a/devdocs/c/string%2Fbyte%2Fstrndup.html b/devdocs/c/string%2Fbyte%2Fstrndup.html deleted file mode 100644 index 74cb2101..00000000 --- a/devdocs/c/string%2Fbyte%2Fstrndup.html +++ /dev/null @@ -1,46 +0,0 @@ -

strndup

Defined in header <string.h>
char *strndup( const char *src, size_t size );
-
(since C23)

Returns a pointer to a null-terminated byte string, which contains copies of at most size bytes from the string pointed to by src. The space for the new string is obtained as if malloc was called. If the null terminator is not encountered in the first size bytes, it is appended to the duplicated string.

-

The returned pointer must be passed to free to avoid a memory leak.

-

If an error occurs, a null pointer is returned and errno might be set.

-

Parameters

- - -
src - pointer to the null-terminated byte string to duplicate
size - max number of bytes to copy from src

Return value

A pointer to the newly allocated string, or a null pointer if an error occurred.

-

Notes

The function is identical to the POSIX strndup except that it is allowed, but not required to set errno on error.

-

Example

#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
- 
-int main(void)
-{
-    const size_t n = 3;
- 
-    const char *src = "Replica";
-    char *dup = strndup(src, n);
-    printf("strndup(\"%s\", %lu) == \"%s\"\n", src, n, dup);
-    free(dup);
- 
-    src = "Hi";
-    dup = strndup(src, n);
-    printf("strndup(\"%s\", %lu) == \"%s\"\n", src, n, dup);
-    free(dup);
- 
-    const char arr[] = {'A','B','C','D'}; // NB: no trailing '\0'
-    dup = strndup(arr, n);
-    printf("strndup({'A','B','C','D'}, %lu) == \"%s\"\n", n, dup);
-    free(dup);
-}

Output:

-
strndup("Replica", 3) == "Rep"
-strndup("Hi", 3) == "Hi"
-strndup({'A','B','C','D'}, 3) == "ABC"

See also

- - - -
-
(C23)
allocates a copy of a string
(function)
-
(C11)
copies one string to another
(function)
allocates memory
(function)
deallocates previously allocated memory
(function)
-

- © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
- https://en.cppreference.com/w/c/string/byte/strndup -

-
-- cgit v1.2.3