XRootD
Loading...
Searching...
No Matches
XrdSysError.cc
Go to the documentation of this file.
1/******************************************************************************/
2/* */
3/* X r d S y s E r r o r . c c */
4/* */
5/*(c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
6/*Produced by Andrew Hanushevsky for Stanford University under contract */
7/* DE-AC02-76-SFO0515 with the Deprtment of Energy */
8/* */
9/* This file is part of the XRootD software suite. */
10/* */
11/* XRootD is free software: you can redistribute it and/or modify it under */
12/* the terms of the GNU Lesser General Public License as published by the */
13/* Free Software Foundation, either version 3 of the License, or (at your */
14/* option) any later version. */
15/* */
16/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
17/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
18/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
19/* License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
23/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
24/* */
25/* The copyright holder's institutional names and contributor's names may not */
26/* be used to endorse or promote products derived from this software without */
27/* specific prior written permission of the institution or contributor. */
28/******************************************************************************/
29
30#include <cctype>
31#ifndef WIN32
32#include <unistd.h>
33#include <cstdlib>
34#include <cstdio>
35#include <cstring>
36#include <strings.h>
37#include <sys/types.h>
38#include <sys/uio.h>
39#else
40#include <cstdlib>
41#include <cstdio>
42#include <cstring>
43#include <sys/types.h>
44#include "XrdSys/XrdWin32.hh"
45#endif
46
47#include "XrdSys/XrdSysE2T.hh"
48#include "XrdSys/XrdSysError.hh"
52
53/******************************************************************************/
54/* d e f i n e s */
55/******************************************************************************/
56
57#define Set_IOV_Item(x, y) {iov[iovpnt].iov_base = (caddr_t)x;\
58 iov[iovpnt++].iov_len = y;}
59
60#define Set_IOV_Buff(x) {iov[iovpnt].iov_base = (caddr_t)x;\
61 iov[iovpnt++].iov_len = strlen(x);}
62
63/******************************************************************************/
64/* G l o b a l s */
65/******************************************************************************/
66
67XrdSysError_Table *XrdSysError::etab = 0;
68XrdSysError_Table_Errno *XrdSysError::etab_errno = 0;
69
70/******************************************************************************/
71/* b a s e F D */
72/******************************************************************************/
73
74int XrdSysError::baseFD() {return Logger->originalFD();}
75
76/******************************************************************************/
77/* e c 2 t e x t */
78/******************************************************************************/
79
80const char *XrdSysError::ec2text(int ecode)
81{
82 int xcode;
83 const char *etxt = 0;
84 XrdSysError_Table *etp = etab;
85
86 xcode = (ecode < 0 ? -ecode : ecode);
87 while((etp != 0) && !(etxt = etp->Lookup(xcode))) etp = etp->next;
88 if (!etxt) etxt = XrdSysE2T(xcode);
89 return etxt;
90}
91
92/******************************************************************************/
93/* e c 2 e r r n o */
94/******************************************************************************/
95
97{
98 int xcode = 0;
99 XrdSysError_Table_Errno *etp = etab_errno;
100
101 int sign = (ecode < 0 ? -1 : 1);
102 int absE = ecode * sign;
103
104 while ((etp != 0) && !(xcode = etp->Lookup(absE)))
105 etp = etp->next;
106
107 // if errcode is mapped return
108 // otherwise return the original err code
109 return xcode ? xcode * sign : ecode;
110}
111
112/******************************************************************************/
113/* E m s g */
114/******************************************************************************/
115
116int XrdSysError::Emsg(const char *esfx, int ecode, const char *txt1,
117 const char *txt2)
118{
119 struct iovec iov[16];
120 int iovpnt = 0;
121 const char *etxt = ec2text(ecode);
122
123 Set_IOV_Item(0,0); // 0
124 if (epfx && epfxlen) Set_IOV_Item(epfx, epfxlen); // 1
125 if (esfx ) Set_IOV_Buff(esfx); // 2
126 Set_IOV_Item(": Unable to ", 12); // 3
127 Set_IOV_Buff(txt1); // 4
128 if (txt2 && txt2[0]){Set_IOV_Item(" ", 1); // 5
129 Set_IOV_Buff(txt2); } // 6
130 Set_IOV_Item("; ", 2); // 7
131 Set_IOV_Buff(etxt); // 8
132 Set_IOV_Item("\n", 1); // 9
133 Logger->Put(iovpnt, iov);
134
135 return ecode;
136}
137
138void XrdSysError::Emsg(const char *esfx, const char *txt1,
139 const char *txt2,
140 const char *txt3)
141{
142 struct iovec iov[16];
143 int iovpnt = 0;
144
145 Set_IOV_Item(0,0); // 0
146 if (epfx && epfxlen) Set_IOV_Item(epfx, epfxlen); // 1
147 if (esfx ) Set_IOV_Buff(esfx); // 2
148 Set_IOV_Item(": ", 2); // 3
149 Set_IOV_Buff(txt1); // 4
150 if (txt2 && txt2[0]){Set_IOV_Item(" ", 1); // 5
151 Set_IOV_Buff(txt2);} // 6
152 if (txt3 && txt3[0]){Set_IOV_Item(" ", 1); // 7
153 Set_IOV_Buff(txt3);} // 8
154 Set_IOV_Item("\n", 1); // 9
155 Logger->Put(iovpnt, iov);
156}
157
158/******************************************************************************/
159/* S a y */
160/******************************************************************************/
161
162void XrdSysError::Say(const char *txt1, const char *txt2, const char *txt3,
163 const char *txt4, const char *txt5, const char *txt6)
164{
165 struct iovec iov[9];
166 int iovpnt = 0;
167 if (txt1) Set_IOV_Buff(txt1) // 0
168 else Set_IOV_Item(0,0);
169 if (txt2 && txt2[0]) Set_IOV_Buff(txt2); // 1
170 if (txt3 && txt3[0]) Set_IOV_Buff(txt3); // 2
171 if (txt4 && txt4[0]) Set_IOV_Buff(txt4); // 3
172 if (txt5 && txt5[0]) Set_IOV_Buff(txt5); // 4
173 if (txt6 && txt6[0]) Set_IOV_Buff(txt6); // 5
174 Set_IOV_Item("\n", 1); // 6
175 Logger->Put(iovpnt, iov);
176}
177
178/******************************************************************************/
179/* T b e g */
180/******************************************************************************/
181
182void XrdSysError::TBeg(const char *txt1, const char *txt2, const char *txt3)
183{
184 std::cerr <<Logger->traceBeg();
185 if (txt1) std::cerr <<txt1 <<' ';
186 if (txt2) std::cerr <<epfx <<txt2 <<": ";
187 if (txt3) std::cerr <<txt3;
188}
189
190/******************************************************************************/
191/* T E n d */
192/******************************************************************************/
193
194void XrdSysError::TEnd() {std::cerr <<std::endl; Logger->traceEnd();}
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104
#define Set_IOV_Item(x, y)
#define Set_IOV_Buff(x)
char * Lookup(int mnum)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void TBeg(const char *txt1=0, const char *txt2=0, const char *txt3=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
static const char * ec2text(int ecode)
int ec2errno(int ecode)