[rtems-libbsd commit] Add error() to the BSD program support.

Sebastian Huber sebastian.huber at embedded-brains.de
Wed Jun 17 11:13:40 UTC 2015



On 16/06/15 05:21, Chris Johns wrote:
> Module:    rtems-libbsd
> Branch:    master
> Commit:    b5aca585949aa94d8d254ab4c4e5b4b2f7b1f1d9
> Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=b5aca585949aa94d8d254ab4c4e5b4b2f7b1f1d9
>
> Author:    Chris Johns <chrisj at rtems.org>
> Date:      Tue Jun 16 13:16:37 2015 +1000
>
> Add error() to the BSD program support.
>
> ---
>
>   rtemsbsd/include/machine/rtems-bsd-program.h | 11 +++++++++++
>   rtemsbsd/rtems/rtems-bsd-program.c           | 13 +++++++++++++
>   2 files changed, 24 insertions(+)
>
> diff --git a/rtemsbsd/include/machine/rtems-bsd-program.h b/rtemsbsd/include/machine/rtems-bsd-program.h
> index b2e542e..7c2837e 100644
> --- a/rtemsbsd/include/machine/rtems-bsd-program.h
> +++ b/rtemsbsd/include/machine/rtems-bsd-program.h
> @@ -56,6 +56,9 @@ rtems_bsd_program_call_main(const char *name, int (*main)(int, char **),
>   void
>   rtems_bsd_program_exit(int exit_code) __dead2;
>   
> +void
> +rtems_bsd_program_error(const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
> +
>   const char *
>   rtems_bsd_program_get_name(void);
>   
> @@ -69,14 +72,22 @@ void
>   rtems_bsd_program_unlock(void);
>   
>   #ifndef RTEMS_BSD_PROGRAM_NO_EXIT_WRAP
> +  #undef exit

What is the reason for this #undef?

>     #define exit(code) rtems_bsd_program_exit(code)
>   #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
> +  #undef getprogname
>     #define getprogname() rtems_bsd_program_get_name()
>   #endif
>   
>   #ifndef RTEMS_BSD_PROGRAM_NO_PRINTF_WRAP
> +  #undef printf
>     #define printf(...) fprintf(stdout, __VA_ARGS__)
>   #endif
>   
> diff --git a/rtemsbsd/rtems/rtems-bsd-program.c b/rtemsbsd/rtems/rtems-bsd-program.c
> index 8edd8f9..7b5920e 100644
> --- a/rtemsbsd/rtems/rtems-bsd-program.c
> +++ b/rtemsbsd/rtems/rtems-bsd-program.c
> @@ -52,6 +52,8 @@
>   #include <setjmp.h>
>   #include <stdlib.h>
>   
> +#include <machine/rtems-bsd-program.h>
> +
>   struct rtems_bsd_program_control {
>   	void *context;
>   	int exit_code;
> @@ -116,6 +118,17 @@ rtems_bsd_program_exit(int exit_code)
>   	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);
> +}
> +

It would be nice to keep the style of the files and this is STYLE(9) 
more or less.

>   const char *
>   rtems_bsd_program_get_name(void)
>   {
>
> _______________________________________________
> vc mailing list
> vc at rtems.org
> http://lists.rtems.org/mailman/listinfo/vc

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.



More information about the devel mailing list