coreutils

General Software Utilities
git clone http://git.omkov.net/coreutils
Log | Tree | Refs | README | LICENCE | Download

coreutils/src/util/error.h (69 lines, 1.7 KiB) -rw-r--r-- blame download

01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
// util/error.h, version 1.1.2
// Error header file from libutil
// Copyright (C) 2020, Jakob Wakeling
// MIT Licence

#ifndef UTIL_ERROR_H_38W06M3W
#define UTIL_ERROR_H_38W06M3W

#ifdef __cplusplus
extern "C" {
#endif

#include <errno.h>
#include <stdbool.h>
#include <stdnoreturn.h>
#include <string.h>

/* Warn and then return status */
#define WARN_R(status, format, ...) do { \
	warn(format, __VA_ARGS__); return status; \
} while (0)

/* Warn and then reset errno */
#define WARN_E(format, ...) do { \
	warn(format, __VA_ARGS__); errno = 0; \
} while (0)

/* Warn, reset errno, and then return status */
#define WARN_RE(status, format, ...) do { \
	warn(format, __VA_ARGS__); errno = 0; return status; \
} while (0)

/* Alert and then return status */
#define ALERT_R(status, format, ...) do { \
	alert(format, __VA_ARGS__); return status; \
} while (0)

/* Alert and then reset errno */
#define ALERT_E(format, ...) do { \
	alert(format, __VA_ARGS__); errno = 0; \
} while (0)

/* Alert, reset errno, and then return status */
#define ALERT_RE(status, format, ...) do { \
	alert(format, __VA_ARGS__); errno = 0; return status; \
} while (0)

/* Shorthand for strerror(serrno). */
#define SERR (strerror(errno))

extern char *A0;
extern bool warned;

/* Print an error message and exit. */
extern noreturn void error(int status, const char *format, ...);
/* Print a warning message and set the warned flag. */
extern void warn(const char *format, ...);
/* Print a warning message but do not set the warned flag. */
extern void alert(const char *format, ...);

/* Shorthand for strerror(errno). DEPRECIATED, use the SERR macro. */
extern char *serr(void);

#ifdef __cplusplus
} // extern "C"
#endif

#endif // UTIL_ERROR_H_38W06M3W