1explain_system(3)          Library Functions Manual          explain_system(3)
2
3
4

NAME

6       explain_system - explain system(3) errors
7

SYNOPSIS

9       #include <libexplain/system.h>
10       const char *explain_system(const char *command);
11       const char *explain_errno_system(int errnum, const char *command);
12       void explain_message_system(char *message, int message_size, const char
13       *command);
14       void explain_message_errno_system(char *message, int message_size,  int
15       errnum, const char *command);
16

DESCRIPTION

18       These  functions may be used to obtain explanations for errors returned
19       by the system(3) system call.
20
21   explain_system
22       const char *explain_system(const char *command);
23
24       The explain_system function is used to  obtain  an  explanation  of  an
25       error  returned  by  the  system(3) system call.  The least the message
26       will contain is the value of strerror(errno), but usually  it  will  do
27       much better, and indicate the underlying cause in more detail.
28
29       The  errno global variable will be used to obtain the error value to be
30       decoded.
31
32       This function is intended to be used in a fashion similar to  the  fol‐
33       lowing example:
34              if (system(command) < 0)
35              {
36                  fprintf(stderr, "%s\n", explain_system(command));
37                  exit(EXIT_FAILURE);
38              }
39
40       command The original command, exactly as passed to the system(3) system
41               call.
42
43       Returns:
44               The message explaining  the  error.   This  message  buffer  is
45               shared by all libexplain functions which do not supply a buffer
46               in their argument list.  This will be overwritten by  the  next
47               call  to  any  libexplain  function  which  shares this buffer,
48               including other threads.
49
50       Note: This function is not thread safe, because it shares a return buf‐
51       fer across all threads, and many other functions in this library.
52
53   explain_errno_system
54       const char *explain_errno_system(int errnum, const char *command);
55
56       The  explain_errno_system  function is used to obtain an explanation of
57       an error returned by the system(3) system call.  The least the  message
58       will  contain  is the value of strerror(errnum), but usually it will do
59       much better, and indicate the underlying cause in more detail.
60
61       This function is intended to be used in a fashion similar to  the  fol‐
62       lowing example:
63              if (system(command) < 0)
64              {
65                  int err = errno;
66                  fprintf(stderr, "%s\n", explain_errno_system(err, command));
67                  exit(EXIT_FAILURE);
68              }
69
70       errnum  The  error value to be decoded, usually obtained from the errno
71               global variable just before this function is called.   This  is
72               necessary  if you need to call any code between the system call
73               to be explained and this function, because many libc  functions
74               will alter the value of errno.
75
76       command The original command, exactly as passed to the system(3) system
77               call.
78
79       Returns:
80               The message explaining  the  error.   This  message  buffer  is
81               shared by all libexplain functions which do not supply a buffer
82               in their argument list.  This will be overwritten by  the  next
83               call  to  any  libexplain  function  which  shares this buffer,
84               including other threads.
85
86       Note: This function is not thread safe, because it shares a return buf‐
87       fer across all threads, and many other functions in this library.
88
89   explain_message_system
90       void explain_message_system(char *message, int message_size, const char
91       *command);
92
93       The explain_message_system function may be used to  obtain an  explana‐
94       tion  of an error returned by the system(3) system call.  The least the
95       message will contain is the value of strerror(errno),  but  usually  it
96       will do much better, and indicate the underlying cause in more detail.
97
98       The  errno global variable will be used to obtain the error value to be
99       decoded.
100
101       This function is intended to be used in a fashion similar to  the  fol‐
102       lowing example:
103              if (system(command) < 0)
104              {
105                  char message[3000];
106                  explain_message_system(message, sizeof(message), command);
107                  fprintf(stderr, "%s\n", message);
108                  exit(EXIT_FAILURE);
109              }
110
111       message The  location  in  which  to  store the returned message.  If a
112               suitable message return buffer is supplied,  this  function  is
113               thread safe.
114
115       message_size
116               The  size  in  bytes  of  the  location  in  which to store the
117               returned message.
118
119       command The original command, exactly as passed to the system(3) system
120               call.
121
122   explain_message_errno_system
123       void  explain_message_errno_system(char *message, int message_size, int
124       errnum, const char *command);
125
126       The explain_message_errno_system function may  be  used  to  obtain  an
127       explanation  of  an  error  returned by the system(3) system call.  The
128       least the message will contain is the value  of  strerror(errnum),  but
129       usually  it  will  do much better, and indicate the underlying cause in
130       more detail.
131
132       This function is intended to be used in a fashion similar to  the  fol‐
133       lowing example:
134              if (system(command) < 0)
135              {
136                  int err = errno;
137                  char message[3000];
138                  explain_message_errno_system(message, sizeof(message), err, command);
139                  fprintf(stderr, "%s\n", message);
140                  exit(EXIT_FAILURE);
141              }
142
143       message The  location  in  which  to  store the returned message.  If a
144               suitable message return buffer is supplied,  this  function  is
145               thread safe.
146
147       message_size
148               The  size  in  bytes  of  the  location  in  which to store the
149               returned message.
150
151       errnum  The error value to be decoded, usually obtained from the  errno
152               global  variable  just before this function is called.  This is
153               necessary if you need to call any code between the system  call
154               to  be explained and this function, because many libc functions
155               will alter the value of errno.
156
157       command The original command, exactly as passed to the system(3) system
158               call.
159

SEE ALSO

161       system(3)
162               execute a shell command
163
164       explain_system_or_die(3)
165               execute a shell command and report errors
166
168       libexplain version 1.4
169       Copyright (C) 2008 Peter Miller
170
171
172
173                                                             explain_system(3)
Impressum