mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
Add a strncpy_safe() utility function
Does strncpy, but guarantees that the string is null-terminated. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#define LIBRATBAG_UTIL_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <libudev.h>
|
||||
|
||||
@@ -78,6 +79,14 @@ int list_empty(const struct list *list);
|
||||
#define streq(s1, s2) (strcmp((s1), (s2)) == 0)
|
||||
#define strneq(s1, s2, n) (strncmp((s1), (s2), (n)) == 0)
|
||||
|
||||
static inline char*
|
||||
strncpy_safe(char *dest, const char *src, size_t n)
|
||||
{
|
||||
strncpy(dest, src, n);
|
||||
dest[n - 1] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
#define LIBRATBAG_EXPORT __attribute__ ((visibility("default")))
|
||||
|
||||
static inline void *
|
||||
|
||||
Reference in New Issue
Block a user