Add string duplication function (strdup)

This commit is contained in:
2025-11-08 11:02:01 +03:00
parent d559d3f66b
commit 44057e96f3
4 changed files with 36 additions and 0 deletions

View File

@@ -377,6 +377,13 @@ The optional parameter I<base> specifies the base of the number.
If successful, it returns the converted number or 0.
=head2 BH_StringDup
char *BH_StringDup(const char *string);
Creates duplicate of the I<string> (simular to strdup).
=head1 SEE ALSO
L<BH>

View File

@@ -368,6 +368,13 @@ I<string> (с ограничением по длинне I<size>).
В случае успеха, возвращает преобразованное число или 0.
=head2 BH_StringDup
char *BH_StringDup(const char *string);
Создает копию строки I<string> (схоже с strdup).
=head1 СМ. ТАКЖЕ
L<BH>

View File

@@ -113,4 +113,7 @@ uint64_t BH_StringToInt64u(const char *string,
int base);
char *BH_StringDup(const char *string);
#endif /* BH_STRING_H */

19
src/String/String.c Normal file
View File

@@ -0,0 +1,19 @@
#include <BH/String.h>
#include <string.h>
#include <stdlib.h>
char *BH_StringDup(const char *string)
{
size_t length;
char *result;
if (!string)
return NULL;
length = strlen(string) + 1;
result = malloc(length);
if (result)
memcpy(result, string, length);
return result;
}