diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-12-30 14:49:46 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-01-19 14:41:55 -0500 |
commit | 683552c4c9a3dfee4ce603157bb2cf18d64fbcfc (patch) | |
tree | 475130eeb136007eea7c59cb7190dc05287e2c56 /tests/mksock.c | |
parent | 944cd72f40a84d318453c320a84d443273956859 (diff) | |
download | bfs-683552c4c9a3dfee4ce603157bb2cf18d64fbcfc.tar.xz |
bfstd: New wrappers for dirname()/basename()
Diffstat (limited to 'tests/mksock.c')
-rw-r--r-- | tests/mksock.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/tests/mksock.c b/tests/mksock.c index d1776b3..5068bc8 100644 --- a/tests/mksock.c +++ b/tests/mksock.c @@ -19,8 +19,8 @@ * program does the job. */ +#include "../src/bfstd.h" #include <errno.h> -#include <libgen.h> #include <stdio.h> #include <string.h> #include <stdlib.h> @@ -41,18 +41,13 @@ static void errmsg(const char *cmd, const char *path) { * file name is not. */ static int chdir_parent(const char *path) { - char *copy = strdup(path); - if (!copy) { + char *dir = xdirname(path); + if (!dir) { return -1; } - const char *dir = dirname(copy); int ret = chdir(dir); - - int error = errno; - free(copy); - errno = error; - + free(dir); return ret; } @@ -66,22 +61,21 @@ static int init_sun(struct sockaddr_un *sock, const char *path) { return -1; } - char *copy = strdup(path); - if (!copy) { + char *base = xbasename(path); + if (!base) { return -1; } - const char *base = basename(copy); len = strlen(base); if (len >= sizeof(sock->sun_path)) { - free(copy); + free(base); errno = ENAMETOOLONG; return -1; } sock->sun_family = AF_UNIX; memcpy(sock->sun_path, base, len + 1); - free(copy); + free(base); return 0; } |