debuggers.hg

annotate tools/xenstore/utils.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents f343d3c16dcc
children
rev   line source
cl349@5395 1 #define _GNU_SOURCE
cl349@5395 2 #include <stdio.h>
cl349@5395 3 #include <stdarg.h>
cl349@5395 4 #include <stdlib.h>
cl349@5395 5 #include <string.h>
cl349@5395 6 #include <errno.h>
cl349@5395 7 #include <unistd.h>
cl349@5395 8 #include <fcntl.h>
cl349@5395 9 #include <sys/types.h>
cl349@5395 10 #include <signal.h>
cl349@5395 11 #include "utils.h"
cl349@5395 12
kfraser@15711 13 static void default_xprintf(const char *fmt, ...)
cl349@5395 14 {
cl349@5789 15 va_list args;
kfraser@15709 16
cl349@5789 17 va_start(args, fmt);
kfraser@15709 18 vfprintf(stderr, fmt, args);
cl349@5789 19 va_end(args);
kfraser@15709 20 fflush(stderr);
cl349@5395 21 }
cl349@5395 22
kfraser@15711 23 void (*xprintf)(const char *fmt, ...) = default_xprintf;
kfraser@15711 24
cl349@5395 25 void barf(const char *fmt, ...)
cl349@5395 26 {
cl349@5395 27 char *str;
keir@15287 28 int bytes;
cl349@5395 29 va_list arglist;
cl349@5395 30
cl349@5395 31 xprintf("FATAL: ");
cl349@5395 32
cl349@5395 33 va_start(arglist, fmt);
keir@15287 34 bytes = vasprintf(&str, fmt, arglist);
cl349@5395 35 va_end(arglist);
cl349@5395 36
keir@15287 37 if (bytes >= 0) {
keir@15287 38 xprintf("%s\n", str);
keir@15287 39 free(str);
keir@15287 40 }
cl349@5395 41 exit(1);
cl349@5395 42 }
cl349@5395 43
cl349@5395 44 void barf_perror(const char *fmt, ...)
cl349@5395 45 {
cl349@5395 46 char *str;
keir@15287 47 int bytes, err = errno;
cl349@5395 48 va_list arglist;
cl349@5395 49
cl349@5395 50 xprintf("FATAL: ");
cl349@5395 51
cl349@5395 52 va_start(arglist, fmt);
keir@15287 53 bytes = vasprintf(&str, fmt, arglist);
cl349@5395 54 va_end(arglist);
cl349@5395 55
keir@15287 56 if (bytes >= 0) {
keir@15287 57 xprintf("%s: %s\n", str, strerror(err));
keir@15287 58 free(str);
keir@15287 59 }
cl349@5395 60 exit(1);
cl349@5395 61 }