diff options
author | Eric Biggers <ebiggers@google.com> | 2019-05-20 17:03:46 -0700 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2019-05-20 17:03:46 -0700 |
commit | 7c8901f260056998fe3606835fee957e66c0fa80 (patch) | |
tree | e2c0b06ef086bc5f46e5c35a01a8c3c529c85de9 | |
parent | c67b06a3c4b1e0597af41d271a6c61a6f9cc289e (diff) | |
download | fsverity-utils-7c8901f260056998fe3606835fee957e66c0fa80.tar.gz |
Remove now-unused utility functions
Signed-off-by: Eric Biggers <ebiggers@google.com>
-rw-r--r-- | util.c | 147 | ||||
-rw-r--r-- | util.h | 34 |
2 files changed, 0 insertions, 181 deletions
@@ -45,26 +45,6 @@ char *xstrdup(const char *s) return xmemdup(s, strlen(s) + 1); } -char *xasprintf(const char *format, ...) -{ - va_list va1, va2; - int size; - char *s; - - va_start(va1, format); - - va_copy(va2, va1); - size = vsnprintf(NULL, 0, format, va2); - va_end(va2); - - ASSERT(size >= 0); - s = xmalloc(size + 1); - vsprintf(s, format, va1); - - va_end(va1); - return s; -} - /* ========== Error messages and assertions ========== */ void do_error_msg(const char *format, va_list va, int err) @@ -121,26 +101,7 @@ bool open_file(struct filedes *file, const char *filename, int flags, int mode) "reading and writing"); return false; } - file->autodelete = false; file->name = xstrdup(filename); - file->pos = 0; - return true; -} - -bool open_tempfile(struct filedes *file) -{ - const char *tmpdir = getenv("TMPDIR") ?: P_tmpdir; - char *name = xasprintf("%s/fsverity-XXXXXX", tmpdir); - - file->fd = mkstemp(name); - if (file->fd < 0) { - error_msg_errno("can't create temporary file"); - free(name); - return false; - } - file->autodelete = true; - file->name = name; - file->pos = 0; return true; } @@ -156,19 +117,6 @@ bool get_file_size(struct filedes *file, u64 *size_ret) return true; } -bool filedes_seek(struct filedes *file, u64 pos, int whence) -{ - off_t res; - - res = lseek(file->fd, pos, whence); - if (res < 0) { - error_msg_errno("seek error on '%s'", file->name); - return false; - } - file->pos = res; - return true; -} - bool full_read(struct filedes *file, void *buf, size_t count) { while (count) { @@ -184,27 +132,6 @@ bool full_read(struct filedes *file, void *buf, size_t count) } buf += n; count -= n; - file->pos += n; - } - return true; -} - -bool full_pread(struct filedes *file, void *buf, size_t count, u64 offset) -{ - while (count) { - int n = pread(file->fd, buf, min(count, INT_MAX), offset); - - if (n < 0) { - error_msg_errno("reading from '%s'", file->name); - return false; - } - if (n == 0) { - error_msg("unexpected end-of-file on '%s'", file->name); - return false; - } - buf += n; - count -= n; - offset += n; } return true; } @@ -220,58 +147,6 @@ bool full_write(struct filedes *file, const void *buf, size_t count) } buf += n; count -= n; - file->pos += n; - } - return true; -} - -bool full_pwrite(struct filedes *file, const void *buf, size_t count, - u64 offset) -{ - while (count) { - int n = pwrite(file->fd, buf, min(count, INT_MAX), offset); - - if (n < 0) { - error_msg_errno("writing to '%s'", file->name); - return false; - } - buf += n; - count -= n; - offset += n; - } - return true; -} - -/* Copy 'count' bytes of data from 'src' to 'dst' */ -bool copy_file_data(struct filedes *src, struct filedes *dst, u64 count) -{ - char buf[4096]; - - while (count) { - size_t n = min(count, sizeof(buf)); - - if (!full_read(src, buf, n)) - return false; - if (!full_write(dst, buf, n)) - return false; - count -= n; - } - return true; -} - -/* Write 'count' bytes of zeroes to the file */ -bool write_zeroes(struct filedes *file, u64 count) -{ - char buf[4096]; - - memset(buf, 0, min(count, sizeof(buf))); - - while (count) { - size_t n = min(count, sizeof(buf)); - - if (!full_write(file, buf, n)) - return false; - count -= n; } return true; } @@ -285,8 +160,6 @@ bool filedes_close(struct filedes *file) res = close(file->fd); if (res != 0) error_msg_errno("closing '%s'", file->name); - if (file->autodelete) - (void)unlink(file->name); file->fd = -1; free(file->name); file->name = NULL; @@ -340,23 +213,3 @@ void bin2hex(const u8 *bin, size_t bin_len, char *hex) } *hex = '\0'; } - -void string_list_append(struct string_list *list, char *string) -{ - ASSERT(list->length <= list->capacity); - if (list->length == list->capacity) { - list->capacity = (list->capacity * 2) + 4; - list->strings = realloc(list->strings, - sizeof(list->strings[0]) * - list->capacity); - if (!list->strings) - fatal_error("out of memory"); - } - list->strings[list->length++] = string; -} - -void string_list_destroy(struct string_list *list) -{ - free(list->strings); - memset(list, 0, sizeof(*list)); -} @@ -83,12 +83,6 @@ static inline int ilog2(unsigned long n) # define le32_to_cpu(v) ((__force u32)(__le32)(v)) # define cpu_to_le64(v) ((__force __le64)(u64)(v)) # define le64_to_cpu(v) ((__force u64)(__le64)(v)) -# define cpu_to_be16(v) ((__force __be16)__builtin_bswap16(v)) -# define be16_to_cpu(v) (__builtin_bswap16((__force u16)(v))) -# define cpu_to_be32(v) ((__force __be32)__builtin_bswap32(v)) -# define be32_to_cpu(v) (__builtin_bswap32((__force u32)(v))) -# define cpu_to_be64(v) ((__force __be64)__builtin_bswap64(v)) -# define be64_to_cpu(v) (__builtin_bswap64((__force u64)(v))) #else # define cpu_to_le16(v) ((__force __le16)__builtin_bswap16(v)) # define le16_to_cpu(v) (__builtin_bswap16((__force u16)(v))) @@ -96,12 +90,6 @@ static inline int ilog2(unsigned long n) # define le32_to_cpu(v) (__builtin_bswap32((__force u32)(v))) # define cpu_to_le64(v) ((__force __le64)__builtin_bswap64(v)) # define le64_to_cpu(v) (__builtin_bswap64((__force u64)(v))) -# define cpu_to_be16(v) ((__force __be16)(u16)(v)) -# define be16_to_cpu(v) ((__force u16)(__be16)(v)) -# define cpu_to_be32(v) ((__force __be32)(u32)(v)) -# define be32_to_cpu(v) ((__force u32)(__be32)(v)) -# define cpu_to_be64(v) ((__force __be64)(u64)(v)) -# define be64_to_cpu(v) ((__force u64)(__be64)(v)) #endif /* ========== Memory allocation ========== */ @@ -110,7 +98,6 @@ void *xmalloc(size_t size); void *xzalloc(size_t size); void *xmemdup(const void *mem, size_t size); char *xstrdup(const char *s); -__printf(1, 2) char *xasprintf(const char *format, ...); /* ========== Error messages and assertions ========== */ @@ -127,22 +114,13 @@ __cold __noreturn void assertion_failed(const char *expr, struct filedes { int fd; - bool autodelete; /* unlink when closed? */ char *name; /* filename, for logging or error messages */ - u64 pos; /* lseek() position */ }; bool open_file(struct filedes *file, const char *filename, int flags, int mode); -bool open_tempfile(struct filedes *file); bool get_file_size(struct filedes *file, u64 *size_ret); -bool filedes_seek(struct filedes *file, u64 pos, int whence); bool full_read(struct filedes *file, void *buf, size_t count); -bool full_pread(struct filedes *file, void *buf, size_t count, u64 offset); bool full_write(struct filedes *file, const void *buf, size_t count); -bool full_pwrite(struct filedes *file, const void *buf, size_t count, - u64 offset); -bool copy_file_data(struct filedes *src, struct filedes *dst, u64 length); -bool write_zeroes(struct filedes *file, u64 length); bool filedes_close(struct filedes *file); /* ========== String utilities ========== */ @@ -150,16 +128,4 @@ bool filedes_close(struct filedes *file); bool hex2bin(const char *hex, u8 *bin, size_t bin_len); void bin2hex(const u8 *bin, size_t bin_len, char *hex); -struct string_list { - char **strings; - size_t length; - size_t capacity; -}; - -#define STRING_LIST_INITIALIZER { .strings = NULL, .length = 0, .capacity = 0 } -#define STRING_LIST(_list) struct string_list _list = STRING_LIST_INITIALIZER - -void string_list_append(struct string_list *list, char *string); -void string_list_destroy(struct string_list *list); - #endif /* UTIL_H */ |