summaryrefslogtreecommitdiffstats
path: root/include/c.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:34 +0000
commit1272be04be0cb803eec87f602edb2e3e6f111aea (patch)
treebce17f6478cdd9f3c4ec3d751135dc42786d6a56 /include/c.h
parentReleasing progress-linux version 2.39.3-11~progress7.99u1. (diff)
downloadutil-linux-1272be04be0cb803eec87f602edb2e3e6f111aea.tar.xz
util-linux-1272be04be0cb803eec87f602edb2e3e6f111aea.zip
Merging upstream version 2.40.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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 */