aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2008-04-24 02:02:49 +0000
committerRuss Allbery <rra@stanford.edu>2008-04-24 02:02:49 +0000
commit92ff7f21ad0b167f8d742a9d7b5f93704a57619c (patch)
tree7adae5f227b6463e07d5cd0f1dab82b7f1c6be47 /util
parent34c58f9471b3df4fa8b719b3c3534940ba5cfe1b (diff)
Major coding style cleanup. Updated all shared code from my other
projects. The configure option requesting AFS kaserver support (and thus building kasetkey) is now --with-kaserver instead of --with-afs. If KRB5_CONFIG was explicitly set in the environment, don't use a different krb5-config based on --with-krb4 or --with-krb5. If krb5-config isn't executable, don't use it. This allows one to force library probing by setting KRB5_CONFIG to point to a nonexistent file. Sanity-check the results of krb5-config before proceeding and error out in configure if they don't work. Stop setting Stanford-specific compile-time defaults for the wallet server and port.
Diffstat (limited to 'util')
-rw-r--r--util/concat.c75
-rw-r--r--util/messages-krb5.c2
-rw-r--r--util/messages.c224
-rw-r--r--util/xmalloc.c168
4 files changed, 258 insertions, 211 deletions
diff --git a/util/concat.c b/util/concat.c
index 65ca04c..1d08e08 100644
--- a/util/concat.c
+++ b/util/concat.c
@@ -1,39 +1,42 @@
-/* $Id$
-**
-** Concatenate strings with dynamic memory allocation.
-**
-** Written by Russ Allbery <rra@stanford.edu>
-** This work is hereby placed in the public domain by its author.
-**
-** Usage:
-**
-** string = concat(string1, string2, ..., (char *) 0);
-** path = concatpath(base, name);
-**
-** Dynamically allocates (using xmalloc) sufficient memory to hold all of
-** the strings given and then concatenates them together into that
-** allocated memory, returning a pointer to it. Caller is responsible for
-** freeing. Assumes xmalloc is available. The last argument must be a
-** null pointer (to a char *, if you actually find a platform where it
-** matters).
-**
-** concatpath is similar, except that it only takes two arguments. If the
-** second argument begins with / or ./, a copy of it is returned;
-** otherwise, the first argument, a slash, and the second argument are
-** concatenated together and returned. This is useful for building file
-** names where names that aren't fully qualified are qualified with some
-** particular directory.
-*/
+/* $Id$
+ *
+ * Concatenate strings with dynamic memory allocation.
+ *
+ * Usage:
+ *
+ * string = concat(string1, string2, ..., (char *) 0);
+ * path = concatpath(base, name);
+ *
+ * Dynamically allocates (using xmalloc) sufficient memory to hold all of the
+ * strings given and then concatenates them together into that allocated
+ * memory, returning a pointer to it. Caller is responsible for freeing.
+ * Assumes xmalloc is available. The last argument must be a null pointer (to
+ * a char *, if you actually find a platform where it matters).
+ *
+ * concatpath is similar, except that it only takes two arguments. If the
+ * second argument begins with / or ./, a copy of it is returned; otherwise,
+ * the first argument, a slash, and the second argument are concatenated
+ * together and returned. This is useful for building file names where names
+ * that aren't fully qualified are qualified with some particular directory.
+ *
+ * Written by Russ Allbery <rra@stanford.edu>
+ * This work is hereby placed in the public domain by its author.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <util/util.h>
/* Abbreviation for cleaner code. */
-#define VA_NEXT(var, type) ((var) = (type) va_arg(args, type))
+#define VA_NEXT(var, type) ((var) = (type) va_arg(args, type))
-/* ANSI C requires at least one named parameter. */
+
+/*
+ * Concatenate all of the arguments into a newly allocated string. ANSI C
+ * requires at least one named parameter, but it's not treated any different
+ * than the rest.
+ */
char *
concat(const char *first, ...)
{
@@ -49,10 +52,12 @@ concat(const char *first, ...)
va_end(args);
length++;
- /* Create the string. Doing the copy ourselves avoids useless string
- traversals of result, if using strcat, or string, if using strlen to
- increment a pointer into result, at the cost of losing the native
- optimization of strcat if any. */
+ /*
+ * Create the string. Doing the copy ourselves avoids useless string
+ * traversals of result, if using strcat, or string, if using strlen to
+ * increment a pointer into result, at the cost of losing the native
+ * optimization of strcat if any.
+ */
result = xmalloc(length);
p = result;
va_start(args, first);
@@ -66,6 +71,10 @@ concat(const char *first, ...)
}
+/*
+ * Concatenate name with base, unless name begins with / or ./. Return the
+ * new string in newly allocated memory.
+ */
char *
concatpath(const char *base, const char *name)
{
diff --git a/util/messages-krb5.c b/util/messages-krb5.c
index 314f96a..caf29b9 100644
--- a/util/messages-krb5.c
+++ b/util/messages-krb5.c
@@ -14,7 +14,7 @@
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <krb5.h>
#if !defined(HAVE_KRB5_GET_ERROR_MESSAGE) && !defined(HAVE_KRB5_GET_ERR_TEXT)
diff --git a/util/messages.c b/util/messages.c
index 4a975c3..7714c2b 100644
--- a/util/messages.c
+++ b/util/messages.c
@@ -1,82 +1,95 @@
-/* $Id$
-**
-** Message and error reporting (possibly fatal).
-**
-** Usage:
-**
-** extern int cleanup(void);
-** extern void log(int, const char *, va_list, int);
-**
-** message_fatal_cleanup = cleanup;
-** message_program_name = argv[0];
-**
-** warn("Something horrible happened at %lu", time);
-** syswarn("Couldn't unlink temporary file %s", tmpfile);
-**
-** die("Something fatal happened at %lu", time);
-** sysdie("open of %s failed", filename);
-**
-** debug("Some debugging message about %s", string);
-** notice("Informational notices");
-**
-** message_handlers_warn(1, log);
-** warn("This now goes through our log function");
-**
-** These functions implement message reporting through user-configurable
-** handler functions. debug() only does something if DEBUG is defined, and
-** notice() and warn() just output messages as configured. die() similarly
-** outputs a message but then exits, normally with a status of 1.
-**
-** The sys* versions do the same, but append a colon, a space, and the
-** results of strerror(errno) to the end of the message. All functions
-** accept printf-style formatting strings and arguments.
-**
-** If message_fatal_cleanup is non-NULL, it is called before exit by die and
-** sysdie and its return value is used as the argument to exit. It is a
-** pointer to a function taking no arguments and returning an int, and can be
-** used to call cleanup functions or to exit in some alternate fashion (such
-** as by calling _exit).
-**
-** If message_program_name is non-NULL, the string it points to, followed by
-** a colon and a space, is prepended to all error messages logged through the
-** message_log_stdout and message_log_stderr message handlers (the former is
-** the default for notice, and the latter is the default for warn and die).
-**
-** Honoring error_program_name and printing to stderr is just the default
-** handler; with message_handlers_* the handlers for any message function can
-** be changed. By default, notice prints to stdout, warn and die print to
-** stderr, and the others don't do anything at all. These functions take a
-** count of handlers and then that many function pointers, each one to a
-** function that takes a message length (the number of characters snprintf
-** generates given the format and arguments), a format, an argument list as a
-** va_list, and the applicable errno value (if any).
-**
-** Copyright (c) 2004, 2005, 2006
-** by Internet Systems Consortium, Inc. ("ISC")
-** Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-** 2002, 2003 by The Internet Software Consortium and Rich Salz
-**
-** This code is derived from software contributed to the Internet Software
-** Consortium by Rich Salz.
-**
-** Permission to use, copy, modify, and distribute this software for any
-** purpose with or without fee is hereby granted, provided that the above
-** copyright notice and this permission notice appear in all copies.
-**
-** THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-** REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
-** SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+/* $Id$
+ *
+ * Message and error reporting (possibly fatal).
+ *
+ * Usage:
+ *
+ * extern int cleanup(void);
+ * extern void log(int, const char *, va_list, int);
+ *
+ * message_fatal_cleanup = cleanup;
+ * message_program_name = argv[0];
+ *
+ * warn("Something horrible happened at %lu", time);
+ * syswarn("Couldn't unlink temporary file %s", tmpfile);
+ *
+ * die("Something fatal happened at %lu", time);
+ * sysdie("open of %s failed", filename);
+ *
+ * debug("Some debugging message about %s", string);
+ * notice("Informational notices");
+ *
+ * message_handlers_warn(1, log);
+ * warn("This now goes through our log function");
+ *
+ * These functions implement message reporting through user-configurable
+ * handler functions. debug() only does something if DEBUG is defined, and
+ * notice() and warn() just output messages as configured. die() similarly
+ * outputs a message but then exits, normally with a status of 1.
+ *
+ * The sys* versions do the same, but append a colon, a space, and the results
+ * of strerror(errno) to the end of the message. All functions accept
+ * printf-style formatting strings and arguments.
+ *
+ * If message_fatal_cleanup is non-NULL, it is called before exit by die and
+ * sysdie and its return value is used as the argument to exit. It is a
+ * pointer to a function taking no arguments and returning an int, and can be
+ * used to call cleanup functions or to exit in some alternate fashion (such
+ * as by calling _exit).
+ *
+ * If message_program_name is non-NULL, the string it points to, followed by a
+ * colon and a space, is prepended to all error messages logged through the
+ * message_log_stdout and message_log_stderr message handlers (the former is
+ * the default for notice, and the latter is the default for warn and die).
+ *
+ * Honoring error_program_name and printing to stderr is just the default
+ * handler; with message_handlers_* the handlers for any message function can
+ * be changed. By default, notice prints to stdout, warn and die print to
+ * stderr, and the others don't do anything at all. These functions take a
+ * count of handlers and then that many function pointers, each one to a
+ * function that takes a message length (the number of characters snprintf
+ * generates given the format and arguments), a format, an argument list as a
+ * va_list, and the applicable errno value (if any).
+ *
+ * Copyright 2008 Board of Trustees, Leland Stanford Jr. University
+ * Copyright 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ * 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <errno.h>
-#include <syslog.h>
+#ifdef HAVE_SYSLOG_H
+# include <syslog.h>
+#endif
+
+#ifdef _WIN32
+# include <windows.h>
+# define LOG_DEBUG EVENTLOG_SUCCESS
+# define LOG_INFO EVENTLOG_INFORMATION_TYPE
+# define LOG_NOTICE EVENTLOG_INFORMATION_TYPE
+# define LOG_WARNING EVENTLOG_WARNING_TYPE
+# define LOG_ERR EVENTLOG_ERROR_TYPE
+# define LOG_CRIT EVENTLOG_ERROR_TYPE
+#endif
#include <util/util.h>
@@ -102,9 +115,9 @@ const char *message_program_name = NULL;
/*
-** Set the handlers for a particular message function. Takes a pointer to
-** the handler list, the count of handlers, and the argument list.
-*/
+ * Set the handlers for a particular message function. Takes a pointer to the
+ * handler list, the count of handlers, and the argument list.
+ */
static void
message_handlers(message_handler_func **list, int count, va_list args)
{
@@ -120,10 +133,10 @@ message_handlers(message_handler_func **list, int count, va_list args)
/*
-** There's no good way of writing these handlers without a bunch of code
-** duplication since we can't assume variadic macros, but I can at least make
-** it easier to write and keep them consistent.
-*/
+ * There's no good way of writing these handlers without a bunch of code
+ * duplication since we can't assume variadic macros, but I can at least make
+ * it easier to write and keep them consistent.
+ */
#define HANDLER_FUNCTION(type) \
void \
message_handlers_ ## type(int count, ...) \
@@ -141,8 +154,8 @@ HANDLER_FUNCTION(die)
/*
-** Print a message to stdout, supporting message_program_name.
-*/
+ * Print a message to stdout, supporting message_program_name.
+ */
void
message_log_stdout(int len UNUSED, const char *fmt, va_list args, int err)
{
@@ -152,13 +165,14 @@ message_log_stdout(int len UNUSED, const char *fmt, va_list args, int err)
if (err)
fprintf(stdout, ": %s", strerror(err));
fprintf(stdout, "\n");
+ fflush(stdout);
}
/*
-** Print a message to stderr, supporting message_program_name. Also flush
-** stdout so that errors and regular output occur in the right order.
-*/
+ * Print a message to stderr, supporting message_program_name. Also flush
+ * stdout so that errors and regular output occur in the right order.
+ */
void
message_log_stderr(int len UNUSED, const char *fmt, va_list args, int err)
{
@@ -173,11 +187,13 @@ message_log_stderr(int len UNUSED, const char *fmt, va_list args, int err)
/*
-** Log a message to syslog. This is a helper function used to implement all
-** of the syslog message log handlers. It takes the same arguments as a
-** regular message handler function but with an additional priority
-** argument.
-*/
+ * Log a message to syslog. This is a helper function used to implement all
+ * of the syslog message log handlers. It takes the same arguments as a
+ * regular message handler function but with an additional priority argument.
+ *
+ * This needs further attention on Windows. For example, it currently doesn't
+ * log the errno information.
+ */
static void
message_log_syslog(int pri, int len, const char *fmt, va_list args, int err)
{
@@ -190,18 +206,30 @@ message_log_syslog(int pri, int len, const char *fmt, va_list args, int err)
exit(message_fatal_cleanup ? (*message_fatal_cleanup)() : 1);
}
vsnprintf(buffer, len + 1, fmt, args);
+#ifdef _WIN32
+ {
+ HANDLE eventlog;
+
+ eventlog = RegisterEventSource(NULL, message_program_name);
+ if (eventlog != NULL) {
+ ReportEvent(eventlog, pri, 0, 0, NULL, 1, 0, &buffer, NULL);
+ CloseEventLog(eventlog);
+ }
+ }
+#else /* !_WIN32 */
if (err == 0)
syslog(pri, "%s", buffer);
else
syslog(pri, "%s: %s", buffer, strerror(err));
+#endif /* !_WIN32 */
free(buffer);
}
/*
-** Do the same sort of wrapper to generate all of the separate syslog logging
-** functions.
-*/
+ * Do the same sort of wrapper to generate all of the separate syslog logging
+ * functions.
+ */
#define SYSLOG_FUNCTION(name, type) \
void \
message_log_syslog_ ## name(int l, const char *f, va_list a, int e) \
@@ -217,10 +245,10 @@ SYSLOG_FUNCTION(crit, CRIT)
/*
-** All of the message handlers. There's a lot of code duplication here too,
-** but each one is still *slightly* different and va_start has to be called
-** multiple times, so it's hard to get rid of the duplication.
-*/
+ * All of the message handlers. There's a lot of code duplication here too,
+ * but each one is still *slightly* different and va_start has to be called
+ * multiple times, so it's hard to get rid of the duplication.
+ */
void
debug(const char *format, ...)
diff --git a/util/xmalloc.c b/util/xmalloc.c
index 635af75..927372d 100644
--- a/util/xmalloc.c
+++ b/util/xmalloc.c
@@ -1,90 +1,93 @@
/* $Id$
-**
-** malloc routines with failure handling.
-**
-** Usage:
-**
-** extern xmalloc_handler_t memory_error;
-** extern const char *string;
-** char *buffer;
-** va_list args;
-**
-** xmalloc_error_handler = memory_error;
-** buffer = xmalloc(1024);
-** xrealloc(buffer, 2048);
-** free(buffer);
-** buffer = xcalloc(1024);
-** free(buffer);
-** buffer = xstrdup(string);
-** free(buffer);
-** buffer = xstrndup(string, 25);
-** free(buffer);
-** xasprintf(&buffer, "%s", "some string");
-** free(buffer);
-** xvasprintf(&buffer, "%s", args);
-**
-** xmalloc, xcalloc, xrealloc, and xstrdup behave exactly like their C
-** library counterparts without the leading x except that they will never
-** return NULL. Instead, on error, they call xmalloc_error_handler,
-** passing it the name of the function whose memory allocation failed, the
-** amount of the allocation, and the file and line number where the
-** allocation function was invoked (from __FILE__ and __LINE__). This
-** function may do whatever it wishes, such as some action to free up
-** memory or a call to sleep to hope that system resources return. If the
-** handler returns, the interrupted memory allocation function will try its
-** allocation again (calling the handler again if it still fails).
-**
-** xstrndup behaves like xstrdup but only copies the given number of
-** characters. It allocates an additional byte over its second argument and
-** always nul-terminates the string.
-**
-** xasprintf and xvasprintf behave just like their GNU glibc library
-** implementations except that they do the same checking as described above.
-** xasprintf will only be able to provide accurate file and line information
-** on systems that support variadic macros.
-**
-** The default error handler, if none is set by the caller, prints an error
-** message to stderr and exits with exit status 1. An error handler must
-** take a const char * (function name), size_t (bytes allocated), const
-** char * (file), and int (line).
-**
-** xmalloc will return a pointer to a valid memory region on an xmalloc of 0
-** bytes, ensuring this by allocating space for one character instead of 0
-** bytes.
-**
-** The functions defined here are actually x_malloc, x_realloc, etc. The
-** header file defines macros named xmalloc, etc. that pass the file name
-** and line number to these functions.
-**
-** Copyright (c) 2004, 2005, 2006
-** by Internet Systems Consortium, Inc. ("ISC")
-** Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-** 2002, 2003 by The Internet Software Consortium and Rich Salz
-**
-** This code is derived from software contributed to the Internet Software
-** Consortium by Rich Salz.
-**
-** Permission to use, copy, modify, and distribute this software for any
-** purpose with or without fee is hereby granted, provided that the above
-** copyright notice and this permission notice appear in all copies.
-**
-** THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
-** REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-** MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY
-** SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-** WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-** ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-** OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-*/
+ *
+ * malloc routines with failure handling.
+ *
+ * Usage:
+ *
+ * extern xmalloc_handler_t memory_error;
+ * extern const char *string;
+ * char *buffer;
+ * va_list args;
+ *
+ * xmalloc_error_handler = memory_error;
+ * buffer = xmalloc(1024);
+ * xrealloc(buffer, 2048);
+ * free(buffer);
+ * buffer = xcalloc(1024);
+ * free(buffer);
+ * buffer = xstrdup(string);
+ * free(buffer);
+ * buffer = xstrndup(string, 25);
+ * free(buffer);
+ * xasprintf(&buffer, "%s", "some string");
+ * free(buffer);
+ * xvasprintf(&buffer, "%s", args);
+ *
+ * xmalloc, xcalloc, xrealloc, and xstrdup behave exactly like their C library
+ * counterparts without the leading x except that they will never return NULL.
+ * Instead, on error, they call xmalloc_error_handler, passing it the name of
+ * the function whose memory allocation failed, the amount of the allocation,
+ * and the file and line number where the allocation function was invoked
+ * (from __FILE__ and __LINE__). This function may do whatever it wishes,
+ * such as some action to free up memory or a call to sleep to hope that
+ * system resources return. If the handler returns, the interrupted memory
+ * allocation function will try its allocation again (calling the handler
+ * again if it still fails).
+ *
+ * xstrndup behaves like xstrdup but only copies the given number of
+ * characters. It allocates an additional byte over its second argument and
+ * always nul-terminates the string.
+ *
+ * xasprintf and xvasprintf behave just like their GNU glibc library
+ * implementations except that they do the same checking as described above.
+ * xasprintf will only be able to provide accurate file and line information
+ * on systems that support variadic macros.
+ *
+ * The default error handler, if none is set by the caller, prints an error
+ * message to stderr and exits with exit status 1. An error handler must take
+ * a const char * (function name), size_t (bytes allocated), const char *
+ * (file), and int (line).
+ *
+ * xmalloc will return a pointer to a valid memory region on an xmalloc of 0
+ * bytes, ensuring this by allocating space for one character instead of 0
+ * bytes.
+ *
+ * The functions defined here are actually x_malloc, x_realloc, etc. The
+ * header file defines macros named xmalloc, etc. that pass the file name and
+ * line number to these functions.
+ *
+ * Copyright 2004, 2005, 2006
+ * by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+ * 2003 by The Internet Software Consortium and Rich Salz
+ *
+ * This code is derived from software contributed to the Internet Software
+ * Consortium by Rich Salz.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
#include <config.h>
-#include <system.h>
+#include <portable/system.h>
#include <errno.h>
#include <util/util.h>
-/* The default error handler. */
+
+/*
+ * The default error handler.
+ */
void
xmalloc_fail(const char *function, size_t size, const char *file, int line)
{
@@ -95,6 +98,7 @@ xmalloc_fail(const char *function, size_t size, const char *file, int line)
/* Assign to this variable to choose a handler other than the default. */
xmalloc_handler_type xmalloc_error_handler = xmalloc_fail;
+
void *
x_malloc(size_t size, const char *file, int line)
{
@@ -110,6 +114,7 @@ x_malloc(size_t size, const char *file, int line)
return p;
}
+
void *
x_calloc(size_t n, size_t size, const char *file, int line)
{
@@ -125,6 +130,7 @@ x_calloc(size_t n, size_t size, const char *file, int line)
return p;
}
+
void *
x_realloc(void *p, size_t size, const char *file, int line)
{
@@ -138,6 +144,7 @@ x_realloc(void *p, size_t size, const char *file, int line)
return newp;
}
+
char *
x_strdup(const char *s, const char *file, int line)
{
@@ -154,6 +161,7 @@ x_strdup(const char *s, const char *file, int line)
return p;
}
+
char *
x_strndup(const char *s, size_t size, const char *file, int line)
{
@@ -169,6 +177,7 @@ x_strndup(const char *s, size_t size, const char *file, int line)
return p;
}
+
int
x_vasprintf(char **strp, const char *fmt, va_list args, const char *file,
int line)
@@ -191,6 +200,7 @@ x_vasprintf(char **strp, const char *fmt, va_list args, const char *file,
return status;
}
+
#if HAVE_C99_VAMACROS || HAVE_GNU_VAMACROS
int
x_asprintf(char **strp, const char *file, int line, const char *fmt, ...)