ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/error.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/error.c (file contents):
Revision 1.7 by tdb, Wed Apr 7 21:08:40 2004 UTC vs.
Revision 1.12 by tdb, Fri Jul 16 15:07:14 2004 UTC

# Line 26 | Line 26
26   #endif
27  
28   #include <stdlib.h>
29 + #include <string.h>
30 + #include <errno.h>
31  
32   #include "statgrab.h"
33 + #include "tools.h"
34  
35   static sg_error error = SG_ERROR_NONE;
36 + #define ERROR_ARG_MAX 256
37 + static char error_arg[ERROR_ARG_MAX];
38 + static char error_strerror[ERROR_ARG_MAX];
39  
40   void sg_set_error(sg_error code, const char *arg) {
41          error = code;
42 <        /* FIXME do something with arg */
42 >        if (arg != NULL) {
43 >                sg_strlcpy(error_arg, arg, sizeof error_arg);
44 >        }
45 >        else {
46 >                /* FIXME is this the best idea? */
47 >                error_arg[0] = '\0';
48 >        }
49   }
50  
51 + void sg_set_error_with_errno(sg_error code, const char *arg, int use_errno) {
52 +        if(use_errno) {
53 +                sg_strlcpy(error_strerror, strerror(errno), sizeof error_strerror);
54 +        }
55 +        else {
56 +                /* FIXME is this the best idea? */
57 +                error_strerror[0] = '\0';
58 +        }
59 +        sg_set_error(code, arg);
60 + }
61 +
62   sg_error sg_get_error() {
63          return error;
64   }
65  
66 + const char *sg_get_error_arg() {
67 +        return error_arg;
68 + }
69 +
70 + const char *sg_get_error_strerror() {
71 +        return error_strerror;
72 + }
73 +
74   const char *sg_str_error(sg_error code) {
75          switch (code) {
76          case SG_ERROR_NONE:
# Line 102 | Line 133 | const char *sg_str_error(sg_error code) {
133                  return "unsupported function";
134          case SG_ERROR_XSW_VER_MISMATCH:
135                  return "XSW version mismatch";
105        default:
106                return "unknown error";
136          }
137 +        return "unknown error";
138   }
139  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines