Introduce sstrndup wrapper.
This commit is contained in:
@ -23,7 +23,7 @@ char *resolve_tilde(const char *path) {
|
||||
char *head, *tail, *result;
|
||||
|
||||
tail = strchr(path, '/');
|
||||
head = strndup(path, tail ? (size_t)(tail - path) : strlen(path));
|
||||
head = sstrndup(path, tail ? (size_t)(tail - path) : strlen(path));
|
||||
|
||||
int res = glob(head, GLOB_TILDE, NULL, &globbuf);
|
||||
free(head);
|
||||
|
@ -48,6 +48,13 @@ char *sstrdup(const char *str) {
|
||||
return result;
|
||||
}
|
||||
|
||||
char *sstrndup(const char *str, size_t size) {
|
||||
char *result = strndup(str, size);
|
||||
if (result == NULL)
|
||||
err(EXIT_FAILURE, "strndup()");
|
||||
return result;
|
||||
}
|
||||
|
||||
int sasprintf(char **strp, const char *fmt, ...) {
|
||||
va_list args;
|
||||
int result;
|
||||
|
Reference in New Issue
Block a user