Download | Plain Text | No Line Numbers
- /*
- * Name: global
- * Author: Manuel Mausz, 0728348
- * Description: Shared definitions and functions
- * Created: 24.04.2009
- */
-
- #include <stdarg.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <errno.h>
- #include "global.h"
-
- /* global variables */
- volatile sig_atomic_t error = 0; /* error flag */
- char *me = NULL; /* name of myself (argv[0]) */
-
- /* function declerations */
- void free_resources(void);
-
- /*
- * NAME: vprintferr
- * PURPOSE:
- * prints error message to stderr and sets global error flag to 1. if errno
- * is set the error message string corresponding to errno will be appended
- * output format: "argv[0]: fmt\n" respectively "argv[0]: fmt: errorstr\n"
- *
- * PARAMETERS:
- * char *fmt ... format string to be passed to printf
- * va_list ap ... variable argument list structure
- *
- * RETURN VALUE:
- * void
- *
- * GLOBAL VARS:
- * me, error
- */
- void vprintferr(const char *fmt, va_list ap)
- {
- if (errno)
- error = 1;
- }
-
- /*
- * NAME: printferr
- * PURPOSE:
- * wrapper for vprintferr to support variable argument list (like printf)
- * see vprintferr for more information
- *
- * PARAMETERS:
- * char *fmt ... format string to be passed to vprintferr (see printf)
- * ... ... arguments according to fmt (see printf)
- *
- * RETURN VALUE:
- * void
- */
- void printferr(const char *fmt, ...)
- {
- va_list ap;
-
- (void) vprintferr(fmt, ap);
- }
-
- /*
- * NAME: bailout
- * PURPOSE:
- * prints formated error message using vprintferr and exits with EXIT_FAILURE
- * printing can be omitted by setting fmt to NULL
- * see vprintferr for more information
- *
- * PARAMETERS:
- * char *fmt ... format string to be passed to vprintferr (see printf)
- * ... ... arguments according to fmt (see printf)
- *
- * RETURN VALUE:
- * void
- */
- void bailout(const char *fmt, ...)
- {
- va_list ap;
-
- if (fmt != NULL)
- {
- (void) vprintferr(fmt, ap);
- }
- (void) free_resources();
- }
-