mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 23:05:39 +00:00
string: Add strlcat helper
We will need it for btrfs subvolumes handling. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
f4e40ef7e2
commit
b4266c7e67
@@ -15,6 +15,9 @@ ifeq ($(call try-cc,$(PRLIMIT_TEST),,),y)
|
|||||||
endif
|
endif
|
||||||
ifeq ($(call try-cc,$(STRLCPY_TEST),,),y)
|
ifeq ($(call try-cc,$(STRLCPY_TEST),,),y)
|
||||||
$(Q) @echo '#define CONFIG_HAS_STRLCPY' >> $@
|
$(Q) @echo '#define CONFIG_HAS_STRLCPY' >> $@
|
||||||
|
endif
|
||||||
|
ifeq ($(call try-cc,$(STRLCAT_TEST),,),y)
|
||||||
|
$(Q) @echo '#define CONFIG_HAS_STRLCAT' >> $@
|
||||||
endif
|
endif
|
||||||
$(Q) @echo '#endif /* __CR_CONFIG_H__ */' >> $@
|
$(Q) @echo '#endif /* __CR_CONFIG_H__ */' >> $@
|
||||||
|
|
||||||
|
@@ -10,4 +10,8 @@
|
|||||||
extern size_t strlcpy(char *dest, const char *src, size_t size);
|
extern size_t strlcpy(char *dest, const char *src, size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_HAS_STRLCAT
|
||||||
|
extern size_t strlcat(char *dest, const char *src, size_t count);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __CR_STRING_H__ */
|
#endif /* __CR_STRING_H__ */
|
||||||
|
@@ -42,3 +42,16 @@ int main(void)
|
|||||||
return strlcpy(dst, src, sizeof(dst));
|
return strlcpy(dst, src, sizeof(dst));
|
||||||
}
|
}
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
define STRLCAT_TEST
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
char src[32] = "strlcat";
|
||||||
|
char dst[32];
|
||||||
|
|
||||||
|
return strlcat(dst, src, sizeof(dst));
|
||||||
|
}
|
||||||
|
endef
|
||||||
|
28
string.c
28
string.c
@@ -30,3 +30,31 @@ size_t strlcpy(char *dest, const char *src, size_t size)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef CONFIG_HAS_STRLCAT
|
||||||
|
/**
|
||||||
|
* strlcat - Append a length-limited, %NUL-terminated string to another
|
||||||
|
* @dest: The string to be appended to
|
||||||
|
* @src: The string to append to it
|
||||||
|
* @count: The size of the destination buffer.
|
||||||
|
*/
|
||||||
|
size_t strlcat(char *dest, const char *src, size_t count)
|
||||||
|
{
|
||||||
|
size_t dsize = strlen(dest);
|
||||||
|
size_t len = strlen(src);
|
||||||
|
size_t res = dsize + len;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It's assumed that @dsize strictly
|
||||||
|
* less than count. Otherwise it's
|
||||||
|
* a bug. But we left it to a caller.
|
||||||
|
*/
|
||||||
|
dest += dsize;
|
||||||
|
count -= dsize;
|
||||||
|
if (len >= count)
|
||||||
|
len = count-1;
|
||||||
|
memcpy(dest, src, len);
|
||||||
|
dest[len] = 0;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Reference in New Issue
Block a user