diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bar.c | 2 | ||||
-rw-r--r-- | src/bfstd.c (renamed from src/util.c) | 556 | ||||
-rw-r--r-- | src/bfstd.h (renamed from src/util.h) | 218 | ||||
-rw-r--r-- | src/bftw.c | 2 | ||||
-rw-r--r-- | src/color.c | 2 | ||||
-rw-r--r-- | src/diag.c | 2 | ||||
-rw-r--r-- | src/diag.h | 2 | ||||
-rw-r--r-- | src/dir.c | 2 | ||||
-rw-r--r-- | src/eval.c | 6 | ||||
-rw-r--r-- | src/exec.c | 2 | ||||
-rw-r--r-- | src/fsade.c | 3 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/mtab.c | 2 | ||||
-rw-r--r-- | src/opt.c | 1 | ||||
-rw-r--r-- | src/parse.c | 2 | ||||
-rw-r--r-- | src/printf.c | 2 | ||||
-rw-r--r-- | src/stat.c | 6 | ||||
-rw-r--r-- | src/xregex.c | 3 | ||||
-rw-r--r-- | src/xspawn.c | 2 |
19 files changed, 418 insertions, 401 deletions
@@ -15,8 +15,8 @@ ****************************************************************************/ #include "bar.h" +#include "bfstd.h" #include "dstring.h" -#include "util.h" #include <errno.h> #include <fcntl.h> #include <limits.h> @@ -14,7 +14,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * ****************************************************************************/ -#include "util.h" +#include "bfstd.h" #include "config.h" #include "dstring.h" #include "xregex.h" @@ -42,75 +42,197 @@ # include <util.h> #endif -char *xreadlinkat(int fd, const char *path, size_t size) { - ssize_t len; - char *name = NULL; +bool is_nonexistence_error(int error) { + return error == ENOENT || errno == ENOTDIR; +} - if (size == 0) { - size = 64; +const char *xbasename(const char *path) { + const char *i; + + // Skip trailing slashes + for (i = path + strlen(path); i > path && i[-1] == '/'; --i); + + // Find the beginning of the name + for (; i > path && i[-1] != '/'; --i); + + // Skip leading slashes + for (; i[0] == '/' && i[1]; ++i); + + return i; +} + +void close_quietly(int fd) { + int error = errno; + xclose(fd); + errno = error; +} + +int xclose(int fd) { + int ret = close(fd); + if (ret != 0) { + assert(errno != EBADF); + } + return ret; +} + +FILE *xfopen(const char *path, int flags) { + char mode[4]; + + switch (flags & O_ACCMODE) { + case O_RDONLY: + strcpy(mode, "rb"); + break; + case O_WRONLY: + strcpy(mode, "wb"); + break; + case O_RDWR: + strcpy(mode, "r+b"); + break; + default: + assert(!"Invalid access mode"); + errno = EINVAL; + return NULL; + } + + if (flags & O_APPEND) { + mode[0] = 'a'; + } + + int fd; + if (flags & O_CREAT) { + fd = open(path, flags, 0666); } else { - ++size; // NUL terminator + fd = open(path, flags); } - while (true) { - char *new_name = realloc(name, size); - if (!new_name) { - goto error; + if (fd < 0) { + return NULL; + } + + FILE *ret = fdopen(fd, mode); + if (!ret) { + close_quietly(fd); + return NULL; + } + + return ret; +} + +char *xgetdelim(FILE *file, char delim) { + char *chunk = NULL; + size_t n = 0; + ssize_t len = getdelim(&chunk, &n, delim, file); + if (len >= 0) { + if (chunk[len] == delim) { + chunk[len] = '\0'; } - name = new_name; + return chunk; + } else { + free(chunk); + if (!ferror(file)) { + errno = 0; + } + return NULL; + } +} - len = readlinkat(fd, path, name, size); - if (len < 0) { - goto error; - } else if ((size_t)len >= size) { - size *= 2; - } else { +size_t xread(int fd, void *buf, size_t nbytes) { + size_t count = 0; + + while (count < nbytes) { + ssize_t ret = read(fd, (char *)buf + count, nbytes - count); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else { + break; + } + } else if (ret == 0) { + // EOF + errno = 0; break; + } else { + count += ret; } } - name[len] = '\0'; - return name; + return count; +} -error: - free(name); - return NULL; +size_t xwrite(int fd, const void *buf, size_t nbytes) { + size_t count = 0; + + while (count < nbytes) { + ssize_t ret = write(fd, (const char *)buf + count, nbytes - count); + if (ret < 0) { + if (errno == EINTR) { + continue; + } else { + break; + } + } else if (ret == 0) { + // EOF? + errno = 0; + break; + } else { + count += ret; + } + } + + return count; } -int dup_cloexec(int fd) { -#ifdef F_DUPFD_CLOEXEC - return fcntl(fd, F_DUPFD_CLOEXEC, 0); -#else - int ret = dup(fd); - if (ret < 0) { +/** Compile and execute a regular expression for xrpmatch(). */ +static int xrpregex(nl_item item, const char *response) { + const char *pattern = nl_langinfo(item); + if (!pattern) { return -1; } - if (fcntl(ret, F_SETFD, FD_CLOEXEC) == -1) { - close_quietly(ret); - return -1; + struct bfs_regex *regex; + int ret = bfs_regcomp(®ex, pattern, BFS_REGEX_POSIX_EXTENDED, 0); + if (ret == 0) { + ret = bfs_regexec(regex, response, 0); } + bfs_regfree(regex); return ret; -#endif } -int pipe_cloexec(int pipefd[2]) { -#if __linux__ || (BSD && !__APPLE__) - return pipe2(pipefd, O_CLOEXEC); -#else - if (pipe(pipefd) != 0) { +/** Check if a response is affirmative or negative. */ +static int xrpmatch(const char *response) { + int ret = xrpregex(NOEXPR, response); + if (ret > 0) { + return 0; + } else if (ret < 0) { return -1; } - if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) == -1 || fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) == -1) { - close_quietly(pipefd[1]); - close_quietly(pipefd[0]); + ret = xrpregex(YESEXPR, response); + if (ret > 0) { + return 1; + } else if (ret < 0) { return -1; } - return 0; -#endif + // Failsafe: always handle y/n + char c = response[0]; + if (c == 'n' || c == 'N') { + return 0; + } else if (c == 'y' || c == 'Y') { + return 1; + } else { + return -1; + } +} + +int ynprompt(void) { + fflush(stderr); + + char *line = xgetdelim(stdin, '\n'); + int ret = line ? xrpmatch(line) : -1; + free(line); + return ret; } /** Get the single character describing the given file type. */ @@ -195,19 +317,88 @@ void xstrmode(mode_t mode, char str[11]) { } } -const char *xbasename(const char *path) { - const char *i; +dev_t xmakedev(int ma, int mi) { +#ifdef makedev + return makedev(ma, mi); +#else + return (ma << 8) | mi; +#endif +} - // Skip trailing slashes - for (i = path + strlen(path); i > path && i[-1] == '/'; --i); +int xmajor(dev_t dev) { +#ifdef major + return major(dev); +#else + return dev >> 8; +#endif +} - // Find the beginning of the name - for (; i > path && i[-1] != '/'; --i); +int xminor(dev_t dev) { +#ifdef minor + return minor(dev); +#else + return dev & 0xFF; +#endif +} - // Skip leading slashes - for (; i[0] == '/' && i[1]; ++i); +int dup_cloexec(int fd) { +#ifdef F_DUPFD_CLOEXEC + return fcntl(fd, F_DUPFD_CLOEXEC, 0); +#else + int ret = dup(fd); + if (ret < 0) { + return -1; + } - return i; + if (fcntl(ret, F_SETFD, FD_CLOEXEC) == -1) { + close_quietly(ret); + return -1; + } + + return ret; +#endif +} + +int pipe_cloexec(int pipefd[2]) { +#if __linux__ || (BSD && !__APPLE__) + return pipe2(pipefd, O_CLOEXEC); +#else + if (pipe(pipefd) != 0) { + return -1; + } + + if (fcntl(pipefd[0], F_SETFD, FD_CLOEXEC) == -1 || fcntl(pipefd[1], F_SETFD, FD_CLOEXEC) == -1) { + close_quietly(pipefd[1]); + close_quietly(pipefd[0]); + return -1; + } + + return 0; +#endif +} + +char *xconfstr(int name) { +#if __ANDROID__ + errno = ENOTSUP; + return NULL; +#else + size_t len = confstr(name, NULL, 0); + if (len == 0) { + return NULL; + } + + char *str = malloc(len); + if (!str) { + return NULL; + } + + if (confstr(name, str, len) != len) { + free(str); + return NULL; + } + + return str; +#endif // !__ANDROID__ } int xfaccessat(int fd, const char *path, int amode) { @@ -224,6 +415,41 @@ int xfaccessat(int fd, const char *path, int amode) { return ret; } +char *xreadlinkat(int fd, const char *path, size_t size) { + ssize_t len; + char *name = NULL; + + if (size == 0) { + size = 64; + } else { + ++size; // NUL terminator + } + + while (true) { + char *new_name = realloc(name, size); + if (!new_name) { + goto error; + } + name = new_name; + + len = readlinkat(fd, path, name, size); + if (len < 0) { + goto error; + } else if ((size_t)len >= size) { + size *= 2; + } else { + break; + } + } + + name[len] = '\0'; + return name; + +error: + free(name); + return NULL; +} + int xstrtofflags(const char **str, unsigned long long *set, unsigned long long *clear) { #if BSD && !__GNU__ char *str_arg = (char *)*str; @@ -284,229 +510,3 @@ size_t xstrwidth(const char *str) { return ret; } - -bool is_nonexistence_error(int error) { - return error == ENOENT || errno == ENOTDIR; -} - -/** Compile and execute a regular expression for xrpmatch(). */ -static int xrpregex(nl_item item, const char *response) { - const char *pattern = nl_langinfo(item); - if (!pattern) { - return -1; - } - - struct bfs_regex *regex; - int ret = bfs_regcomp(®ex, pattern, BFS_REGEX_POSIX_EXTENDED, 0); - if (ret == 0) { - ret = bfs_regexec(regex, response, 0); - } - - bfs_regfree(regex); - return ret; -} - -/** Check if a response is affirmative or negative. */ -static int xrpmatch(const char *response) { - int ret = xrpregex(NOEXPR, response); - if (ret > 0) { - return 0; - } else if (ret < 0) { - return -1; - } - - ret = xrpregex(YESEXPR, response); - if (ret > 0) { - return 1; - } else if (ret < 0) { - return -1; - } - - // Failsafe: always handle y/n - char c = response[0]; - if (c == 'n' || c == 'N') { - return 0; - } else if (c == 'y' || c == 'Y') { - return 1; - } else { - return -1; - } -} - -int ynprompt(void) { - fflush(stderr); - - char *line = xgetdelim(stdin, '\n'); - int ret = line ? xrpmatch(line) : -1; - free(line); - return ret; -} - -dev_t bfs_makedev(int ma, int mi) { -#ifdef makedev - return makedev(ma, mi); -#else - return (ma << 8) | mi; -#endif -} - -int bfs_major(dev_t dev) { -#ifdef major - return major(dev); -#else - return dev >> 8; -#endif -} - -int bfs_minor(dev_t dev) { -#ifdef minor - return minor(dev); -#else - return dev & 0xFF; -#endif -} - -size_t xread(int fd, void *buf, size_t nbytes) { - size_t count = 0; - - while (count < nbytes) { - ssize_t ret = read(fd, (char *)buf + count, nbytes - count); - if (ret < 0) { - if (errno == EINTR) { - continue; - } else { - break; - } - } else if (ret == 0) { - // EOF - errno = 0; - break; - } else { - count += ret; - } - } - - return count; -} - -size_t xwrite(int fd, const void *buf, size_t nbytes) { - size_t count = 0; - - while (count < nbytes) { - ssize_t ret = write(fd, (const char *)buf + count, nbytes - count); - if (ret < 0) { - if (errno == EINTR) { - continue; - } else { - break; - } - } else if (ret == 0) { - // EOF? - errno = 0; - break; - } else { - count += ret; - } - } - - return count; -} - -char *xconfstr(int name) { -#if __ANDROID__ - errno = ENOTSUP; - return NULL; -#else - size_t len = confstr(name, NULL, 0); - if (len == 0) { - return NULL; - } - - char *str = malloc(len); - if (!str) { - return NULL; - } - - if (confstr(name, str, len) != len) { - free(str); - return NULL; - } - - return str; -#endif // !__ANDROID__ -} - -char *xgetdelim(FILE *file, char delim) { - char *chunk = NULL; - size_t n = 0; - ssize_t len = getdelim(&chunk, &n, delim, file); - if (len >= 0) { - if (chunk[len] == delim) { - chunk[len] = '\0'; - } - return chunk; - } else { - free(chunk); - if (!ferror(file)) { - errno = 0; - } - return NULL; - } -} - -FILE *xfopen(const char *path, int flags) { - char mode[4]; - - switch (flags & O_ACCMODE) { - case O_RDONLY: - strcpy(mode, "rb"); - break; - case O_WRONLY: - strcpy(mode, "wb"); - break; - case O_RDWR: - strcpy(mode, "r+b"); - break; - default: - assert(!"Invalid access mode"); - errno = EINVAL; - return NULL; - } - - if (flags & O_APPEND) { - mode[0] = 'a'; - } - - int fd; - if (flags & O_CREAT) { - fd = open(path, flags, 0666); - } else { - fd = open(path, flags); - } - - if (fd < 0) { - return NULL; - } - - FILE *ret = fdopen(fd, mode); - if (!ret) { - close_quietly(fd); - return NULL; - } - - return ret; -} - -int xclose(int fd) { - int ret = close(fd); - if (ret != 0) { - assert(errno != EBADF); - } - return ret; -} - -void close_quietly(int fd) { - int error = errno; - xclose(fd); - errno = error; -} @@ -15,113 +15,107 @@ ****************************************************************************/ /** - * Assorted utilities that don't belong anywhere else. + * Standard library wrappers and polyfills. */ -#ifndef BFS_UTIL_H -#define BFS_UTIL_H +#ifndef BFS_BFSTD_H +#define BFS_BFSTD_H -#include <fcntl.h> -#include <fnmatch.h> #include <stdbool.h> -#include <stddef.h> -#include <stdio.h> -#include <sys/types.h> -// Some portability concerns +// #include <errno.h> -#if !defined(FNM_CASEFOLD) && defined(FNM_IGNORECASE) -# define FNM_CASEFOLD FNM_IGNORECASE -#endif +/** + * Return whether an error code is due to a path not existing. + */ +bool is_nonexistence_error(int error); + +#include <fcntl.h> #ifndef O_DIRECTORY # define O_DIRECTORY 0 #endif +#include <fnmatch.h> + +#if !defined(FNM_CASEFOLD) && defined(FNM_IGNORECASE) +# define FNM_CASEFOLD FNM_IGNORECASE +#endif + +// #include <libgen.h> + /** - * readlinkat() wrapper that dynamically allocates the result. + * basename() variant that doesn't modify the input. * - * @param fd - * The base directory descriptor. * @param path - * The path to the link, relative to fd. - * @param size - * An estimate for the size of the link name (pass 0 if unknown). - * @return The target of the link, allocated with malloc(), or NULL on failure. + * The path in question. + * @return A pointer into path at the base name offset. */ -char *xreadlinkat(int fd, const char *path, size_t size); +const char *xbasename(const char *path); -/** - * Like dup(), but set the FD_CLOEXEC flag. - * - * @param fd - * The file descriptor to duplicate. - * @return A duplicated file descriptor, or -1 on failure. - */ -int dup_cloexec(int fd); +#include <stdio.h> /** - * Like pipe(), but set the FD_CLOEXEC flag. + * close() variant that preserves errno. * - * @param pipefd - * The array to hold the two file descriptors. - * @return 0 on success, -1 on failure. + * @param fd + * The file descriptor to close. */ -int pipe_cloexec(int pipefd[2]); +void close_quietly(int fd); /** - * Format a mode like ls -l (e.g. -rw-r--r--). + * close() wrapper that asserts the file descriptor is valid. * - * @param mode - * The mode to format. - * @param str - * The string to hold the formatted mode. + * @param fd + * The file descriptor to close. + * @return + * 0 on success, or -1 on error. */ -void xstrmode(mode_t mode, char str[11]); +int xclose(int fd); /** - * basename() variant that doesn't modify the input. + * fopen() variant that takes open() style flags. * * @param path - * The path in question. - * @return A pointer into path at the base name offset. + * The path to open. + * @param flags + * Flags to pass to open(). */ -const char *xbasename(const char *path); +FILE *xfopen(const char *path, int flags); /** - * Wrapper for faccessat() that handles some portability issues. + * Convenience wrapper for getdelim(). + * + * @param file + * The file to read. + * @param delim + * The delimiter character to split on. + * @return + * The read chunk (without the delimiter), allocated with malloc(). + * NULL is returned on error (errno != 0) or end of file (errno == 0). */ -int xfaccessat(int fd, const char *path, int amode); +char *xgetdelim(FILE *file, char delim); /** - * Portability wrapper for strtofflags(). + * A safe version of read() that handles interrupted system calls and partial + * reads. * - * @param str - * The string to parse. The pointee will be advanced to the first - * invalid position on error. - * @param set - * The flags that are set in the string. - * @param clear - * The flags that are cleared in the string. * @return - * 0 on success, -1 on failure. + * The number of bytes read. A value != nbytes indicates an error + * (errno != 0) or end of file (errno == 0). */ -int xstrtofflags(const char **str, unsigned long long *set, unsigned long long *clear); +size_t xread(int fd, void *buf, size_t nbytes); /** - * wcswidth() variant that works on narrow strings. + * A safe version of write() that handles interrupted system calls and partial + * writes. * - * @param str - * The string to measure. * @return - * The likely width of that string in a terminal. + The number of bytes written. A value != nbytes indicates an error. */ -size_t xstrwidth(const char *str); +size_t xwrite(int fd, const void *buf, size_t nbytes); -/** - * Return whether an error code is due to a path not existing. - */ -bool is_nonexistence_error(int error); +// #include <stdlib.h> /** * Process a yes/no prompt. @@ -130,39 +124,56 @@ bool is_nonexistence_error(int error); */ int ynprompt(void); +// #include <string.h> + +/** + * Format a mode like ls -l (e.g. -rw-r--r--). + * + * @param mode + * The mode to format. + * @param str + * The string to hold the formatted mode. + */ +void xstrmode(mode_t mode, char str[11]); + +#include <sys/types.h> + /** * Portable version of makedev(). */ -dev_t bfs_makedev(int ma, int mi); +dev_t xmakedev(int ma, int mi); /** * Portable version of major(). */ -int bfs_major(dev_t dev); +int xmajor(dev_t dev); /** * Portable version of minor(). */ -int bfs_minor(dev_t dev); +int xminor(dev_t dev); + +#include <unistd.h> /** - * A safe version of read() that handles interrupted system calls and partial - * reads. + * Like dup(), but set the FD_CLOEXEC flag. * + * @param fd + * The file descriptor to duplicate. * @return - * The number of bytes read. A value != nbytes indicates an error - * (errno != 0) or end of file (errno == 0). + * A duplicated file descriptor, or -1 on failure. */ -size_t xread(int fd, void *buf, size_t nbytes); +int dup_cloexec(int fd); /** - * A safe version of write() that handles interrupted system calls and partial - * writes. + * Like pipe(), but set the FD_CLOEXEC flag. * + * @param pipefd + * The array to hold the two file descriptors. * @return - The number of bytes written. A value != nbytes indicates an error. + * 0 on success, -1 on failure. */ -size_t xwrite(int fd, const void *buf, size_t nbytes); +int pipe_cloexec(int pipefd[2]); /** * Wrapper for confstr() that allocates with malloc(). @@ -175,44 +186,49 @@ size_t xwrite(int fd, const void *buf, size_t nbytes); char *xconfstr(int name); /** - * Convenience wrapper for getdelim(). - * - * @param file - * The file to read. - * @param delim - * The delimiter character to split on. - * @return - * The read chunk (without the delimiter), allocated with malloc(). - * NULL is returned on error (errno != 0) or end of file (errno == 0). + * Wrapper for faccessat() that handles some portability issues. */ -char *xgetdelim(FILE *file, char delim); +int xfaccessat(int fd, const char *path, int amode); /** - * fopen() variant that takes open() style flags. + * readlinkat() wrapper that dynamically allocates the result. * + * @param fd + * The base directory descriptor. * @param path - * The path to open. - * @param flags - * Flags to pass to open(). + * The path to the link, relative to fd. + * @param size + * An estimate for the size of the link name (pass 0 if unknown). + * @return + * The target of the link, allocated with malloc(), or NULL on failure. */ -FILE *xfopen(const char *path, int flags); +char *xreadlinkat(int fd, const char *path, size_t size); /** - * close() wrapper that asserts the file descriptor is valid. + * Portability wrapper for strtofflags(). * - * @param fd - * The file descriptor to close. + * @param str + * The string to parse. The pointee will be advanced to the first + * invalid position on error. + * @param set + * The flags that are set in the string. + * @param clear + * The flags that are cleared in the string. * @return - * 0 on success, or -1 on error. + * 0 on success, -1 on failure. */ -int xclose(int fd); +int xstrtofflags(const char **str, unsigned long long *set, unsigned long long *clear); + +// #include <wchar.h> /** - * close() variant that preserves errno. + * wcswidth() variant that works on narrow strings. * - * @param fd - * The file descriptor to close. + * @param str + * The string to measure. + * @return + * The likely width of that string in a terminal. */ -void close_quietly(int fd); +size_t xstrwidth(const char *str); -#endif // BFS_UTIL_H +#endif // BFS_BFSTD_H @@ -31,13 +31,13 @@ */ #include "bftw.h" +#include "bfstd.h" #include "dir.h" #include "darray.h" #include "dstring.h" #include "mtab.h" #include "stat.h" #include "trie.h" -#include "util.h" #include <assert.h> #include <errno.h> #include <fcntl.h> diff --git a/src/color.c b/src/color.c index 6240b9c..98fe9f2 100644 --- a/src/color.c +++ b/src/color.c @@ -15,6 +15,7 @@ ****************************************************************************/ #include "color.h" +#include "bfstd.h" #include "bftw.h" #include "dir.h" #include "dstring.h" @@ -22,7 +23,6 @@ #include "fsade.h" #include "stat.h" #include "trie.h" -#include "util.h" #include <assert.h> #include <errno.h> #include <fcntl.h> @@ -15,10 +15,10 @@ ****************************************************************************/ #include "diag.h" +#include "bfstd.h" #include "ctx.h" #include "color.h" #include "expr.h" -#include "util.h" #include <assert.h> #include <errno.h> #include <stdarg.h> @@ -22,7 +22,7 @@ #define BFS_DIAG_H #include "ctx.h" -#include "util.h" +#include "config.h" #include <stdarg.h> #include <stdbool.h> @@ -15,8 +15,8 @@ ****************************************************************************/ #include "dir.h" +#include "bfstd.h" #include "config.h" -#include "util.h" #include <dirent.h> #include <errno.h> #include <fcntl.h> @@ -20,6 +20,7 @@ #include "eval.h" #include "bar.h" +#include "bfstd.h" #include "bftw.h" #include "color.h" #include "config.h" @@ -36,7 +37,6 @@ #include "pwcache.h" #include "stat.h" #include "trie.h" -#include "util.h" #include "xregex.h" #include "xtime.h" #include <assert.h> @@ -686,8 +686,8 @@ bool eval_fls(const struct bfs_expr *expr, struct bfs_eval *state) { } if (ftwbuf->type == BFS_BLK || ftwbuf->type == BFS_CHR) { - int ma = bfs_major(statbuf->rdev); - int mi = bfs_minor(statbuf->rdev); + int ma = xmajor(statbuf->rdev); + int mi = xminor(statbuf->rdev); if (fprintf(file, " %3d, %3d", ma, mi) < 0) { goto error; } @@ -15,12 +15,12 @@ ****************************************************************************/ #include "exec.h" +#include "bfstd.h" #include "bftw.h" #include "ctx.h" #include "color.h" #include "diag.h" #include "dstring.h" -#include "util.h" #include "xspawn.h" #include <assert.h> #include <errno.h> diff --git a/src/fsade.c b/src/fsade.c index 7a7201e..a609b97 100644 --- a/src/fsade.c +++ b/src/fsade.c @@ -15,10 +15,11 @@ ****************************************************************************/ #include "fsade.h" +#include "config.h" +#include "bfstd.h" #include "bftw.h" #include "dir.h" #include "dstring.h" -#include "util.h" #include <errno.h> #include <fcntl.h> #include <stddef.h> @@ -34,6 +34,7 @@ * * - Utilities: * - bar.[ch] (a terminal status bar) + * - bfstd.[ch] (standard library wrappers/polyfills) * - color.[ch] (for pretty terminal colors) * - config.h (configuration and feature/platform detection) * - darray.[ch] (a dynamic array library) @@ -49,13 +50,12 @@ * - xregex.[ch] (regular expression support) * - xspawn.[ch] (spawns processes) * - xtime.[ch] (date/time handling utilities) - * - util.[ch] (everything else) */ +#include "bfstd.h" #include "ctx.h" #include "eval.h" #include "parse.h" -#include "util.h" #include <errno.h> #include <fcntl.h> #include <locale.h> @@ -15,11 +15,11 @@ ****************************************************************************/ #include "mtab.h" +#include "bfstd.h" #include "config.h" #include "darray.h" #include "stat.h" #include "trie.h" -#include "util.h" #include <errno.h> #include <fcntl.h> #include <stdbool.h> @@ -46,7 +46,6 @@ #include "eval.h" #include "expr.h" #include "pwcache.h" -#include "util.h" #include <assert.h> #include <limits.h> #include <stdarg.h> diff --git a/src/parse.c b/src/parse.c index 2fe3473..1be7cb7 100644 --- a/src/parse.c +++ b/src/parse.c @@ -22,6 +22,7 @@ */ #include "parse.h" +#include "bfstd.h" #include "bftw.h" #include "color.h" #include "config.h" @@ -38,7 +39,6 @@ #include "pwcache.h" #include "stat.h" #include "typo.h" -#include "util.h" #include "xregex.h" #include "xspawn.h" #include "xtime.h" diff --git a/src/printf.c b/src/printf.c index 8fdde41..97c203f 100644 --- a/src/printf.c +++ b/src/printf.c @@ -15,6 +15,7 @@ ****************************************************************************/ #include "printf.h" +#include "bfstd.h" #include "bftw.h" #include "color.h" #include "ctx.h" @@ -26,7 +27,6 @@ #include "mtab.h" #include "pwcache.h" #include "stat.h" -#include "util.h" #include "xtime.h" #include <assert.h> #include <errno.h> @@ -15,8 +15,8 @@ ****************************************************************************/ #include "stat.h" +#include "bfstd.h" #include "config.h" -#include "util.h" #include <assert.h> #include <errno.h> #include <fcntl.h> @@ -186,7 +186,7 @@ static int bfs_statx_impl(int at_fd, const char *at_path, int at_flags, struct b buf->mask = 0; - buf->dev = bfs_makedev(xbuf.stx_dev_major, xbuf.stx_dev_minor); + buf->dev = xmakedev(xbuf.stx_dev_major, xbuf.stx_dev_minor); buf->mask |= BFS_STAT_DEV; if (xbuf.stx_mask & STATX_INO) { @@ -227,7 +227,7 @@ static int bfs_statx_impl(int at_fd, const char *at_path, int at_flags, struct b buf->mask |= BFS_STAT_BLOCKS; } - buf->rdev = bfs_makedev(xbuf.stx_rdev_major, xbuf.stx_rdev_minor); + buf->rdev = xmakedev(xbuf.stx_rdev_major, xbuf.stx_rdev_minor); buf->mask |= BFS_STAT_RDEV; buf->attrs = xbuf.stx_attributes; diff --git a/src/xregex.c b/src/xregex.c index 4fa098d..e8d6b23 100644 --- a/src/xregex.c +++ b/src/xregex.c @@ -15,7 +15,8 @@ ****************************************************************************/ #include "xregex.h" -#include "util.h" +#include "bfstd.h" +#include "config.h" #include <assert.h> #include <errno.h> #include <stdlib.h> diff --git a/src/xspawn.c b/src/xspawn.c index f9d52b0..5d2c320 100644 --- a/src/xspawn.c +++ b/src/xspawn.c @@ -15,8 +15,8 @@ ****************************************************************************/ #include "xspawn.h" +#include "bfstd.h" #include "config.h" -#include "util.h" #include <errno.h> #include <fcntl.h> #include <stdlib.h> |