util.h (1019B) download
1#pragma once
2
3#include <stdio.h>
4
5#define LEN(arr) (sizeof(arr) / sizeof(*arr))
6
7#define streq(a, b) (!strcmp((a), (b)))
8
9#define print_errno(msg, ...) (fprint(1, "%s: " msg, current_prog(), ##__VA_ARGS__, strerror(errno)))
10#define print_error(msg, ...) (fprint(1, "%s: " msg, current_prog(), ##__VA_ARGS__))
11
12// void errprint(const char* format, ...);
13
14// extern const char* prog; // has to be defined per program
15const char* current_prog(void);
16
17ssize_t dgetline(int fd, char* line, size_t line_buffer);
18ssize_t readstr(int fd, char* str);
19ssize_t writestr(int fd, const char* str);
20unsigned int stat_mode(const char* format, ...);
21int fork_dup_cd_exec(int dir, const char* path, int fd0, int fd1, int fd2);
22int reclaim_console(void);
23void sigblock_all(int unblock);
24long parse_long(const char* str, const char* name);
25char* progname(char* path);
26int fd_set_flag(int fd, int flags);
27void path_join(char* buffer, const char* component, ...);