1
<refentry id="libuser-error">
3
<refentrytitle>error</refentrytitle>
4
<manvolnum>3</manvolnum>
5
<refmiscinfo>LIBUSER Library</refmiscinfo>
9
<refname>error</refname><refpurpose>Functions for allocating and manipulating <link linkend="lu-error"><type>lu_error</type></link> structures.</refpurpose>
12
<refsynopsisdiv><title>Synopsis</title>
18
#define <link linkend="LU-ERROR-CHECK:CAPS">LU_ERROR_CHECK</link> (err_p_p)
19
<link linkend="void">void</link> <link linkend="lu-error-new">lu_error_new</link> (<link linkend="lu-error-t">lu_error_t</link> **error,
20
<link linkend="lu-status-t">lu_status_t</link> code,
21
const <link linkend="char">char</link> *fmt,
23
<link linkend="void">void</link> <link linkend="lu-error-free">lu_error_free</link> (<link linkend="lu-error-t">lu_error_t</link> **error);
24
<link linkend="gboolean">gboolean</link> <link linkend="lu-error-is-success">lu_error_is_success</link> (<link linkend="lu-status-t">lu_status_t</link> status);
25
<link linkend="gboolean">gboolean</link> <link linkend="lu-error-is-warning">lu_error_is_warning</link> (<link linkend="lu-status-t">lu_status_t</link> status);
26
<link linkend="gboolean">gboolean</link> <link linkend="lu-error-is-error">lu_error_is_error</link> (<link linkend="lu-status-t">lu_status_t</link> status);
27
const <link linkend="char">char</link>* <link linkend="lu-strerror">lu_strerror</link> (<link linkend="lu-error-t">lu_error_t</link> *error);
40
<title>Description</title>
42
<filename>error.h</filename> includes declarations for allocating and
43
manipulating <link linkend="lu-error"><type>lu_error</type></link> structures. These structures hold error and status
44
information passed between libuser, its modules, and applications.
48
A struct <link linkend="lu-error"><type>lu_error</type></link> contains an error code and a human-readable, possibly
49
translated error string. The error string is using the encoding specified
50
by <literal>LC_CTYPE</literal> locale category.
55
<title>Details</title>
57
<title><anchor id="LU-ERROR-CHECK:CAPS"/>LU_ERROR_CHECK()</title>
58
<indexterm><primary>LU_ERROR_CHECK</primary></indexterm><programlisting>#define LU_ERROR_CHECK(err_p_p)</programlisting>
60
Checks that the given pointer to a pointer to a struct does not already point
61
to a valid <link linkend="lu-error"><type>lu_error</type></link> structure. This macro is used by many internal functions
62
to check that an error has not already occurred when they are invoked.
63
</para><variablelist role="params">
64
<varlistentry><term><parameter>err_p_p</parameter> :</term>
65
<listitem><simpara>A pointer to a struct <link linkend="lu-error"><type>lu_error</type></link> * which will be checked. If there
68
</simpara></listitem></varlistentry>
69
</variablelist></refsect2>
71
<title><anchor id="lu-error-new"/>lu_error_new ()</title>
72
<indexterm><primary>lu_error_new</primary></indexterm><programlisting><link linkend="void">void</link> lu_error_new (<link linkend="lu-error-t">lu_error_t</link> **error,
73
<link linkend="lu-status-t">lu_status_t</link> code,
74
const <link linkend="char">char</link> *fmt,
75
...);</programlisting>
77
Creates a new <link linkend="lu-error"><type>lu_error</type></link> structure.
78
</para><variablelist role="params">
79
<varlistentry><term><parameter>error</parameter> :</term>
80
<listitem><simpara>A pointer to a struct <link linkend="lu-error"><type>lu_error</type></link> * which will hold the newly-created
81
error structure. It must point to <link linkend="NULL:CAPS"><type>NULL</type></link> before calling this function.
82
</simpara></listitem></varlistentry>
83
<varlistentry><term><parameter>code</parameter> :</term>
84
<listitem><simpara>An error code
85
</simpara></listitem></varlistentry>
86
<varlistentry><term><parameter>fmt</parameter> :</term>
87
<listitem><simpara>Format string describing the error. If <link linkend="NULL:CAPS"><type>NULL</type></link>, a default string is used.
88
</simpara></listitem></varlistentry>
89
<varlistentry><term><parameter>...</parameter> :</term>
90
<listitem><simpara>Arguments for <parameter>fmt</parameter>, if necessary
93
</simpara></listitem></varlistentry>
94
</variablelist></refsect2>
96
<title><anchor id="lu-error-free"/>lu_error_free ()</title>
97
<indexterm><primary>lu_error_free</primary></indexterm><programlisting><link linkend="void">void</link> lu_error_free (<link linkend="lu-error-t">lu_error_t</link> **error);</programlisting>
99
Frees an <link linkend="lu-error"><type>lu_error</type></link> structure.
100
</para><variablelist role="params">
101
<varlistentry><term><parameter>error</parameter> :</term>
102
<listitem><simpara>A pointer to a pointer to the structure to be freed. The pointer is set
103
to NULL after the error is freed.
106
</simpara></listitem></varlistentry>
107
</variablelist></refsect2>
109
<title><anchor id="lu-error-is-success"/>lu_error_is_success ()</title>
110
<indexterm><primary>lu_error_is_success</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> lu_error_is_success (<link linkend="lu-status-t">lu_status_t</link> status);</programlisting>
112
Check if the error code held by an error structure is a success code.
113
</para><variablelist role="params">
114
<varlistentry><term><parameter>status</parameter> :</term>
116
</simpara></listitem></varlistentry>
117
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>a <link linkend="gboolean"><type>gboolean</type></link> indicating whether or not the error is a success code.
120
</simpara></listitem></varlistentry>
121
</variablelist></refsect2>
123
<title><anchor id="lu-error-is-warning"/>lu_error_is_warning ()</title>
124
<indexterm><primary>lu_error_is_warning</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> lu_error_is_warning (<link linkend="lu-status-t">lu_status_t</link> status);</programlisting>
126
Check if the error code held by an error structure is a warning code.
127
</para><variablelist role="params">
128
<varlistentry><term><parameter>status</parameter> :</term>
130
</simpara></listitem></varlistentry>
131
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>a <link linkend="gboolean"><type>gboolean</type></link> indicating whether or not the error is a warning code.
134
</simpara></listitem></varlistentry>
135
</variablelist></refsect2>
137
<title><anchor id="lu-error-is-error"/>lu_error_is_error ()</title>
138
<indexterm><primary>lu_error_is_error</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> lu_error_is_error (<link linkend="lu-status-t">lu_status_t</link> status);</programlisting>
140
Check if the error code held by an error structure is an error code.
141
</para><variablelist role="params">
142
<varlistentry><term><parameter>status</parameter> :</term>
144
</simpara></listitem></varlistentry>
145
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>a <link linkend="gboolean"><type>gboolean</type></link> indicating whether or not the error is an error code.
148
</simpara></listitem></varlistentry>
149
</variablelist></refsect2>
151
<title><anchor id="lu-strerror"/>lu_strerror ()</title>
152
<indexterm><primary>lu_strerror</primary></indexterm><programlisting>const <link linkend="char">char</link>* lu_strerror (<link linkend="lu-error-t">lu_error_t</link> *error);</programlisting>
154
Converts an <link linkend="lu-error"><type>lu_error</type></link> structure to a string describing the error.
155
If the <parameter>error->string</parameter> is <literal>NULL</literal>, returns a text representation of
156
<parameter>error->code</parameter>.
157
</para><variablelist role="params">
158
<varlistentry><term><parameter>error</parameter> :</term>
159
<listitem><simpara>An error
160
</simpara></listitem></varlistentry>
161
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>error string valid at least until <parameter>error</parameter> is freed.
164
</simpara></listitem></varlistentry>
165
</variablelist></refsect2>