mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-30 00:00:15 +01:00
26 lines
701 B
C
26 lines
701 B
C
/* GPLv2 or OpenIB.org BSD (MIT) See COPYING file */
|
|
#ifndef UTIL_UTIL_H
|
|
#define UTIL_UTIL_H
|
|
|
|
#include <stdbool.h>
|
|
#include <sys/types.h>
|
|
|
|
/* Return true if the snprintf succeeded, false if there was truncation or
|
|
* error */
|
|
static inline bool __good_snprintf(size_t len, int rc)
|
|
{
|
|
return (rc < len && rc >= 0);
|
|
}
|
|
|
|
#define check_snprintf(buf, len, fmt, ...) \
|
|
__good_snprintf(len, snprintf(buf, len, fmt, ##__VA_ARGS__))
|
|
|
|
/* a CMP b. See also the BSD macro timercmp(). */
|
|
#define ts_cmp(a, b, CMP) \
|
|
(((a)->tv_sec == (b)->tv_sec) ? \
|
|
((a)->tv_nsec CMP (b)->tv_nsec) : \
|
|
((a)->tv_sec CMP (b)->tv_sec))
|
|
|
|
int set_fd_nonblock(int fd, bool nonblock);
|
|
|
|
#endif
|