Add string duplication function (strdup)
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -368,6 +368,13 @@ I<string> (с ограничением по длинне I<size>).
|
||||
В случае успеха, возвращает преобразованное число или 0.
|
||||
|
||||
|
||||
=head2 BH_StringDup
|
||||
|
||||
char *BH_StringDup(const char *string);
|
||||
|
||||
Создает копию строки I<string> (схоже с strdup).
|
||||
|
||||
|
||||
=head1 СМ. ТАКЖЕ
|
||||
|
||||
L<BH>
|
||||
|
||||
@@ -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
19
src/String/String.c
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user