summaryrefslogtreecommitdiffstats
path: root/include/c.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/c.h')
-rw-r--r--include/c.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/include/c.h b/include/c.h
index 2b70e8d..61b95ab 100644
--- a/include/c.h
+++ b/include/c.h
@@ -213,6 +213,14 @@
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
+#define read_unaligned_member(p, m) __extension__ ({ \
+ size_t offset = offsetof(__typeof__(* p), m); \
+ __typeof__(p->m + 0) v; \
+ memcpy(&v, ((unsigned char *)p) + offset, sizeof(v)); \
+ v; })
+
+#define member_ptr(p, m) (((unsigned char *)p) + offsetof(__typeof__(*p), m))
+
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
# ifdef HAVE___PROGNAME
extern char *__progname;
@@ -294,6 +302,9 @@ void __err_oom(const char *file, unsigned int line)
}
#define err_oom() __err_oom(__FILE__, __LINE__)
+#define err_nosys(exitcode, ...) \
+ err(errno == ENOSYS ? EXIT_NOTSUPP : exitcode, __VA_ARGS__)
+
/* Don't use inline function to avoid '#include "nls.h"' in c.h
*/
@@ -449,6 +460,7 @@ static inline void __attribute__((__noreturn__)) ul_sig_err(int excode, const ch
#define USAGE_COMMANDS _("\nCommands:\n")
#define USAGE_ARGUMENTS _("\nArguments:\n")
#define USAGE_COLUMNS _("\nAvailable output columns:\n")
+#define USAGE_DEFAULT_COLUMNS _("\nDefault columns:\n")
#define USAGE_SEPARATOR "\n"
#define USAGE_OPTSTR_HELP _("display this help")
@@ -498,6 +510,12 @@ static inline void print_features(const char **features, const char *prefix)
exit(eval); \
})
+static inline int fputsln(const char *s, FILE *stream) {
+ if (fputs(s, stream) == EOF)
+ return EOF;
+ return fputc('\n', stdout);
+}
+
/*
* seek stuff
*/
@@ -564,4 +582,17 @@ static inline void print_features(const char **features, const char *prefix)
#define SINT_MAX(t) (((t)1 << (sizeof(t) * 8 - 2)) - (t)1 + ((t)1 << (sizeof(t) * 8 - 2)))
+#ifndef HAVE_REALLOCARRAY
+static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
+{
+ size_t s = nmemb * size;
+
+ if (nmemb != 0 && s / nmemb != size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(ptr, s);
+}
+#endif
+
#endif /* UTIL_LINUX_C_H */