Add error() to the BSD program support.

This commit is contained in:
Chris Johns
2015-06-16 13:16:37 +10:00
parent 59a9e6a5da
commit b5aca58594
2 changed files with 24 additions and 0 deletions

View File

@@ -56,6 +56,9 @@ rtems_bsd_program_call_main(const char *name, int (*main)(int, char **),
void void
rtems_bsd_program_exit(int exit_code) __dead2; rtems_bsd_program_exit(int exit_code) __dead2;
void
rtems_bsd_program_error(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
const char * const char *
rtems_bsd_program_get_name(void); rtems_bsd_program_get_name(void);
@@ -69,14 +72,22 @@ void
rtems_bsd_program_unlock(void); rtems_bsd_program_unlock(void);
#ifndef RTEMS_BSD_PROGRAM_NO_EXIT_WRAP #ifndef RTEMS_BSD_PROGRAM_NO_EXIT_WRAP
#undef exit
#define exit(code) rtems_bsd_program_exit(code) #define exit(code) rtems_bsd_program_exit(code)
#endif #endif
#ifndef RTEMS_BSD_PROGRAM_NO_ERROR_WRAP
#undef error
#define error(fmt, ...) rtems_bsd_program_error(fmt, ## __VA_ARGS__)
#endif
#ifndef RTEMS_BSD_PROGRAM_NO_GETPROGNAME_WRAP #ifndef RTEMS_BSD_PROGRAM_NO_GETPROGNAME_WRAP
#undef getprogname
#define getprogname() rtems_bsd_program_get_name() #define getprogname() rtems_bsd_program_get_name()
#endif #endif
#ifndef RTEMS_BSD_PROGRAM_NO_PRINTF_WRAP #ifndef RTEMS_BSD_PROGRAM_NO_PRINTF_WRAP
#undef printf
#define printf(...) fprintf(stdout, __VA_ARGS__) #define printf(...) fprintf(stdout, __VA_ARGS__)
#endif #endif

View File

@@ -52,6 +52,8 @@
#include <setjmp.h> #include <setjmp.h>
#include <stdlib.h> #include <stdlib.h>
#include <machine/rtems-bsd-program.h>
struct rtems_bsd_program_control { struct rtems_bsd_program_control {
void *context; void *context;
int exit_code; int exit_code;
@@ -116,6 +118,17 @@ rtems_bsd_program_exit(int exit_code)
panic("unexpected BSD program exit"); panic("unexpected BSD program exit");
} }
void
rtems_bsd_program_error(const char *fmt, ...)
{
va_list list;
va_start(list, fmt);
vfprintf(stderr, fmt, list);
fprintf(stderr, "\n");
va_end(list);
rtems_bsd_program_exit(1);
}
const char * const char *
rtems_bsd_program_get_name(void) rtems_bsd_program_get_name(void)
{ {