]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/error/SysErrorDetail.h
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef _SQUID_SRC_ERROR_SYSERRORDETAIL_H
10 #define _SQUID_SRC_ERROR_SYSERRORDETAIL_H
12 #include "error/Detail.h"
13 #include "sbuf/SBuf.h"
14 #include "sbuf/Stream.h"
16 /// system call failure detail based on standard errno(3)/strerror(3) APIs
17 class SysErrorDetail
: public ErrorDetail
19 MEMPROXY_CLASS(SysErrorDetail
);
22 /// \returns a pointer to a SysErrorDetail instance (or nil for lost errnos)
23 static ErrorDetail::Pointer
NewIfAny(const int errorNo
)
25 // we could optimize by caching results for (frequently used?) errnos
26 return errorNo
? new SysErrorDetail(errorNo
) : nullptr;
29 static SBuf
Brief(int errorNo
) {
30 return SysErrorDetail(errorNo
).brief();
34 virtual SBuf
brief() const override
{
35 return ToSBuf("errno=", errorNo
);
38 virtual SBuf
verbose(const HttpRequestPointer
&) const override
{
39 return SBuf(strerror(errorNo
));
43 // hidden by NewIfAny() to avoid creating SysErrorDetail from zero errno
44 explicit SysErrorDetail(const int anErrorNo
): errorNo(anErrorNo
) {}
46 int errorNo
; ///< errno(3) set by the last failed system call or equivalent
49 #endif /* _SQUID_SRC_ERROR_SYSERRORDETAIL_H */