diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-02-08 13:16:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-02-08 13:16:47 +0000 |
commit | 4f5226cb7a97f86421a94fcc75c59fe6d709ae02 (patch) | |
tree | 1a2cab09cbbc1040650fe21c0a9cef15d2ccb6ee /src/utils.h | |
parent | Initial commit. (diff) | |
download | ttyd-4f5226cb7a97f86421a94fcc75c59fe6d709ae02.tar.xz ttyd-4f5226cb7a97f86421a94fcc75c59fe6d709ae02.zip |
Adding upstream version 1.6.3.upstream/1.6.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/utils.h')
-rw-r--r-- | src/utils.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..2060ac9 --- /dev/null +++ b/src/utils.h @@ -0,0 +1,37 @@ +#ifndef TTYD_UTIL_H +#define TTYD_UTIL_H + +#define container_of(ptr, type, member) \ + ({ \ + const typeof(((type *)0)->member) *__mptr = (ptr); \ + (type *)((char *)__mptr - offsetof(type, member)); \ + }) + +// malloc with NULL check +void *xmalloc(size_t size); + +// realloc with NULL check +void *xrealloc(void *p, size_t size); + +// Convert a string to upper case +char *uppercase(char *str); + +// Check whether str ends with suffix +bool endswith(const char *str, const char *suffix); + +// Get human readable signal string +int get_sig_name(int sig, char *buf, size_t len); + +// Get signal code from string like SIGHUP +int get_sig(const char *sig_name); + +// Set the given file descriptor close-on-exec +bool fd_set_cloexec(const int fd); + +// Open uri with the default application of system +int open_uri(char *uri); + +// Encode text to base64, the caller should free the returned string +char *base64_encode(const unsigned char *buffer, size_t length); + +#endif // TTYD_UTIL_H |