Exemple #1
0
/**
 * _nih_error_raise_printf:
 * @filename: filename where the error was raised,
 * @line: line number of @filename where the error was raised,
 * @function: function name the error was raised within,
 * @number: numeric identifier,
 * @format: format string for human-readable message.
 *
 * Raises an error with the given details in the current error context,
 * if an unhandled error already exists then an error message is emmitted
 * through the logging system; you should try to avoid this.
 *
 * The human-readable message for the error is parsed according to @format,
 * and allocated as a child of the error object so that it is freed.
 *
 * This function should never be called directly, instead use the
 * nih_error_raise_printf() macro to pass the correct arguments for @filename,
 * @line and @function.
 **/
void
_nih_error_raise_printf (const char *filename,
			 int         line,
			 const char *function,
			 int         number,
			 const char *format,
			 ...)
{
	NihError *error;
	va_list   args;

	nih_assert (filename != NULL);
	nih_assert (line > 0);
	nih_assert (function != NULL);
	nih_assert (number > 0);
	nih_assert (format != NULL);

	nih_error_init ();

	error = NIH_MUST (nih_new (NULL, NihError));

	error->number = number;

	va_start (args, format);
	error->message = NIH_MUST (nih_vsprintf (error, format, args));
	va_end (args);

	_nih_error_raise_error (filename, line, function, error);
}
Exemple #2
0
static char *
my_vsprintf (void *parent,
             const char *format,
             ...)
{
    char    *str;
    va_list  args;

    va_start (args, format);
    str = nih_vsprintf (parent, format, args);
    va_end (args);

    return str;
}
Exemple #3
0
/**
 * nih_dbus_error_raise_printf:
 * @name: D-Bus name for error,
 * @format: format string for human-readable message.
 *
 * Raises an error which includes a D-Bus name so that it may be sent as
 * a reply to a method call, the error type is fixed to NIH_DBUS_ERROR.
 *
 * The human-readable message for the error is parsed according to @format,
 * and allocated as a child of the error object so that it is freed.
 *
 * You may use this in D-Bus handlers and return a negative number to
 * automatically have this error returned as the method reply.  It is also
 * useful when mixing D-Bus and libnih function calls in your own methods
 * to return consistent error forms, in which case pass the name and message
 * members of the DBusError structure before freeing it.
 **/
void
nih_dbus_error_raise_printf (const char *name,
			     const char *format,
			     ...)
{
	NihDBusError *err;
	va_list       args;

	nih_assert (name != NULL);
	nih_assert (format != NULL);

	err = NIH_MUST (nih_new (NULL, NihDBusError));

	err->number = NIH_DBUS_ERROR;

	err->name = NIH_MUST (nih_strdup (err, name));

	va_start (args, format);
	err->message = NIH_MUST (nih_vsprintf (err, format, args));
	va_end (args);

	nih_error_raise_error ((NihError *)err);
}