~javier-lopez/ubuntu/quantal/cdo/sru-1023329

« back to all changes in this revision

Viewing changes to libcdi/src/error.c

  • Committer: Bazaar Package Importer
  • Author(s): Alastair McKinstry
  • Date: 2010-09-22 15:58:09 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100922155809-u1d3vlmlqj02uxjt
Tags: 1.4.6.dfsg.1-1
New upstream release. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if defined (HAVE_CONFIG_H)
 
2
#  include "config.h"
 
3
#endif
 
4
 
 
5
#include <stdio.h>
 
6
#include <stdlib.h>
 
7
#include <stdarg.h>
 
8
#include <errno.h>
 
9
 
 
10
 
 
11
int _ExitOnError   = 1; /* If set to 1, exit on error       */
 
12
int _Verbose = 1;       /* If set to 1, errors are reported */
 
13
int _Debug   = 0;       /* If set to 1, debugging           */
 
14
 
 
15
 
 
16
void SysError(const char *caller, const char *fmt, ...)
 
17
{
 
18
  va_list args;
 
19
        
 
20
  va_start(args, fmt);
 
21
 
 
22
  printf("\n");
 
23
   fprintf(stderr, "Error (%s) : ", caller);
 
24
  vfprintf(stderr, fmt, args);
 
25
   fprintf(stderr, "\n");
 
26
 
 
27
  va_end(args);
 
28
 
 
29
  if ( errno )
 
30
    perror("System error message ");
 
31
        
 
32
  exit(EXIT_FAILURE);
 
33
}
 
34
 
 
35
void Error(const char *caller, const char *fmt, ...)
 
36
{
 
37
  va_list args;
 
38
        
 
39
  va_start(args, fmt);
 
40
 
 
41
  printf("\n");
 
42
   fprintf(stderr, "Error (%s) : ", caller);
 
43
  vfprintf(stderr, fmt, args);
 
44
   fprintf(stderr, "\n");
 
45
 
 
46
  va_end(args);
 
47
 
 
48
  if ( _ExitOnError ) exit(EXIT_FAILURE);
 
49
}
 
50
 
 
51
void Warning(const char *caller, const char *fmt, ...)
 
52
{
 
53
  va_list args;
 
54
        
 
55
  va_start(args, fmt);
 
56
 
 
57
  if ( _Verbose )
 
58
    {
 
59
       fprintf(stderr, "Warning (%s) : ", caller);
 
60
      vfprintf(stderr, fmt, args);
 
61
       fprintf(stderr, "\n");
 
62
    }
 
63
 
 
64
  va_end(args);
 
65
}
 
66
 
 
67
void Message(const char *caller, const char *fmt, ...)
 
68
{
 
69
  va_list args;
 
70
        
 
71
  va_start(args, fmt);
 
72
 
 
73
   fprintf(stdout, "%-18s : ", caller);
 
74
  vfprintf(stdout, fmt, args);
 
75
   fprintf(stdout, "\n");
 
76
 
 
77
  va_end(args);
 
78
}