mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2024-11-03 04:17:18 -05:00
Work towards cleaner portability goo, and remove some ununsed code while there.
git-svn-id: https://svn.xiph.org/trunk/ezstream@15794 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
parent
1f91dd0941
commit
c0b09af703
@ -227,6 +227,7 @@ dnl #######################
|
||||
|
||||
AC_CHECK_FUNCS([ \
|
||||
arc4random \
|
||||
basename \
|
||||
gettimeofday \
|
||||
getopt \
|
||||
nl_langinfo \
|
||||
|
@ -19,8 +19,8 @@ AM_CPPFLAGS = @EZ_CPPFLAGS@
|
||||
AM_LDFLAGS = @EZ_LDFLAGS@
|
||||
|
||||
EXTRA_DIST = \
|
||||
compat.h \
|
||||
configfile.h \
|
||||
ezstream.h \
|
||||
metadata.h \
|
||||
playlist.h \
|
||||
strfctns.h \
|
||||
|
78
src/compat.c
78
src/compat.c
@ -1,4 +1,47 @@
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "ezstream.h"
|
||||
|
||||
#if defined(HAVE_LIBGEN_H) && !defined(__linux__)
|
||||
# include <libgen.h>
|
||||
#endif /* HAVE_LIBGEN_H && !__linux__ */
|
||||
|
||||
#ifndef PATH_MAX
|
||||
# define PATH_MAX 256
|
||||
#endif /* !PATH_MAX */
|
||||
|
||||
#ifndef PATH_SEPARATORS
|
||||
# define PATH_SEPARATORS "/"
|
||||
#endif /* !PATH_SEPARATORS */
|
||||
|
||||
char * local_basename(const char *);
|
||||
|
||||
static const char *path_separators = PATH_SEPARATORS;
|
||||
|
||||
static inline int
|
||||
is_separator(int);
|
||||
|
||||
static inline int
|
||||
is_separator(int c)
|
||||
{
|
||||
const char *cp;
|
||||
|
||||
for (cp = path_separators; '\0' != *cp; cp++) {
|
||||
if (*cp == c)
|
||||
return (1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Modified basename() implementation from OpenBSD, based on:
|
||||
* $OpenBSD: src/lib/libc/gen/basename.c,v 1.14 2005/08/08 08:05:33 espie Exp $
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1997, 2004 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
@ -14,27 +57,12 @@
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* Modified basename() implementation from OpenBSD, based on:
|
||||
* $OpenBSD: src/lib/libc/gen/basename.c,v 1.14 2005/08/08 08:05:33 espie Exp $
|
||||
*/
|
||||
char *
|
||||
local_basename(const char *path)
|
||||
{
|
||||
#ifdef HAVE_BASENAME
|
||||
return (basename(path));
|
||||
#else /* HAVE_BASENAME */
|
||||
static char bname[PATH_MAX];
|
||||
size_t len;
|
||||
const char *startp, *endp;
|
||||
@ -45,13 +73,16 @@ local_basename(const char *path)
|
||||
return (bname);
|
||||
}
|
||||
|
||||
/* Strip any trailing slashes */
|
||||
/* Strip any trailing path separators */
|
||||
endp = path + strlen(path) - 1;
|
||||
while (endp > path && *endp == PATH_SEPARATOR)
|
||||
while (endp > path && is_separator(*endp))
|
||||
endp--;
|
||||
|
||||
/* All slashes become "\" */
|
||||
if (endp == path && *endp == PATH_SEPARATOR) {
|
||||
/*
|
||||
* All path separators become a single one; pick the first in the
|
||||
* list as the default.
|
||||
*/
|
||||
if (endp == path && is_separator(*endp)) {
|
||||
bname[0] = PATH_SEPARATOR;
|
||||
bname[1] = '\0';
|
||||
return (bname);
|
||||
@ -59,7 +90,7 @@ local_basename(const char *path)
|
||||
|
||||
/* Find the start of the base */
|
||||
startp = endp;
|
||||
while (startp > path && *(startp - 1) != PATH_SEPARATOR)
|
||||
while (startp > path && !is_separator(*(startp - 1)))
|
||||
startp--;
|
||||
|
||||
len = endp - startp + 1;
|
||||
@ -71,4 +102,5 @@ local_basename(const char *path)
|
||||
bname[len] = '\0';
|
||||
|
||||
return (bname);
|
||||
#endif /* HAVE_BASENAME */
|
||||
}
|
||||
|
@ -22,12 +22,8 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "ezstream.h"
|
||||
|
||||
#include "compat.h"
|
||||
#include "configfile.h"
|
||||
#include "strfctns.h"
|
||||
#include "util.h"
|
||||
|
@ -22,37 +22,14 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_LIBGEN_H
|
||||
# include <libgen.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
#ifdef HAVE_PATHS_H
|
||||
# include <paths.h>
|
||||
#endif
|
||||
#include "ezstream.h"
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
# include <signal.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <shout/shout.h>
|
||||
|
||||
#include "compat.h"
|
||||
#include "configfile.h"
|
||||
#include "metadata.h"
|
||||
#include "playlist.h"
|
||||
@ -833,7 +810,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
|
||||
if (pezConfig->fileNameIsProgram) {
|
||||
char *tmp = xstrdup(pezConfig->fileName);
|
||||
printf(" [%s]",
|
||||
basename(tmp));
|
||||
local_basename(tmp));
|
||||
xfree(tmp);
|
||||
} else
|
||||
printf(" [%4lu/%-4lu]",
|
||||
|
@ -22,28 +22,44 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifndef PATH_SEPARATOR
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif /* HAVE_SYS_TYPES_H */
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#else /* HAVE_SYS_TIME_H */
|
||||
# include <time.h>
|
||||
#endif /* HAVE_SYS_TIME_H */
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif /* HAVE_SYS_STAT_H */
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#ifdef HAVE_PATHS_H
|
||||
# include <paths.h>
|
||||
#endif /* HAVE_PATHS_H */
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef _PATH_DEVNULL
|
||||
# ifdef WIN32
|
||||
# define PATH_SEPARATOR '\\'
|
||||
# else
|
||||
# define PATH_SEPARATOR '/'
|
||||
# define _PATH_DEVNULL "nul"
|
||||
# else /* WIN32 */
|
||||
# define _PATH_DEVNULL "/dev/null"
|
||||
# endif /* WIN32 */
|
||||
#endif /* !PATH_SEPARATOR */
|
||||
|
||||
#ifndef PATH_MAX
|
||||
# define PATH_MAX 256
|
||||
#endif /* !PATH_MAX */
|
||||
|
||||
/* Sometimes defined through <limits.h>. */
|
||||
#ifndef SIZE_T_MAX
|
||||
# define SIZE_T_MAX ((size_t)-1)
|
||||
#endif /* !SIZE_T_MAX */
|
||||
#endif /* !_PATH_DEVNULL */
|
||||
|
||||
#ifdef WIN32
|
||||
# include <windows.h>
|
||||
|
||||
# define _PATH_DEVNULL "nul"
|
||||
|
||||
# define pclose _pclose
|
||||
# define popen _popen
|
||||
# define snprintf _snprintf
|
||||
@ -60,20 +76,9 @@
|
||||
# define S_IXGRP 0
|
||||
# define S_IXOTH 0
|
||||
|
||||
# define basename local_basename
|
||||
# define sleep(a) Sleep((a) * 1000)
|
||||
#endif /* WIN32 */
|
||||
|
||||
/* Usually defined in <sys/stat.h>. */
|
||||
#ifndef S_IEXEC
|
||||
# define S_IEXEC S_IXUSR
|
||||
#endif /* !S_IEXEC */
|
||||
|
||||
/* For Solaris, possibly others (usually defined in <paths.h>.) */
|
||||
#ifndef _PATH_DEVNULL
|
||||
# define _PATH_DEVNULL "/dev/null"
|
||||
#endif /* !_PATH_DEVNULL */
|
||||
|
||||
#ifndef HAVE_STRUCT_TIMEVAL
|
||||
struct timeval {
|
||||
long tv_sec;
|
||||
@ -81,6 +86,10 @@ struct timeval {
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* For compat.c and getopt.c:
|
||||
*/
|
||||
|
||||
extern int opterr;
|
||||
extern int optind;
|
||||
extern int optopt;
|
||||
@ -89,7 +98,7 @@ extern char *optarg;
|
||||
|
||||
extern int
|
||||
local_getopt(int, char * const *, const char *);
|
||||
|
||||
char * local_basename(const char *);
|
||||
extern char *
|
||||
local_basename(const char *);
|
||||
|
||||
#endif /* __COMPAT_H__ */
|
10
src/getopt.c
10
src/getopt.c
@ -54,15 +54,7 @@
|
||||
# include "config.h"
|
||||
#endif /* HAVE_CONFIG_H */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif /* HAVE_UNISTD_H */
|
||||
|
||||
#include "compat.h"
|
||||
#include "ezstream.h"
|
||||
|
||||
int local_getopt(int, char * const *, const char *);
|
||||
|
||||
|
@ -19,20 +19,7 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_LIBGEN_H
|
||||
# include <libgen.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ezstream.h"
|
||||
|
||||
#ifdef HAVE_TAGLIB
|
||||
# include <taglib/tag_c.h>
|
||||
@ -42,12 +29,16 @@
|
||||
#endif /* HAVE_VORBISFILE */
|
||||
#include <shout/shout.h>
|
||||
|
||||
#include "compat.h"
|
||||
#include "metadata.h"
|
||||
#include "strfctns.h"
|
||||
#include "util.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
/* Usually defined in <sys/stat.h>. */
|
||||
#ifndef S_IEXEC
|
||||
# define S_IEXEC S_IXUSR
|
||||
#endif /* !S_IEXEC */
|
||||
|
||||
extern char *__progname;
|
||||
extern int vFlag;
|
||||
|
||||
@ -314,7 +305,7 @@ metadata_get_name(const char *file)
|
||||
abort();
|
||||
}
|
||||
|
||||
if ((p1 = basename(filename)) == NULL) {
|
||||
if ((p1 = local_basename(filename)) == NULL) {
|
||||
printf("%s: Internal error: basename() failed with '%s'\n",
|
||||
__progname, filename);
|
||||
exit(1);
|
||||
|
@ -19,23 +19,16 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "ezstream.h"
|
||||
|
||||
#include "compat.h"
|
||||
#include "playlist.h"
|
||||
#include "xalloc.h"
|
||||
|
||||
/* Usually defined in <sys/stat.h>. */
|
||||
#ifndef S_IEXEC
|
||||
# define S_IEXEC S_IXUSR
|
||||
#endif /* !S_IEXEC */
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
struct playlist {
|
||||
|
14
src/util.c
14
src/util.c
@ -27,32 +27,20 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
#else
|
||||
# include <time.h>
|
||||
#endif
|
||||
#include "ezstream.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
# include <langinfo.h>
|
||||
#endif
|
||||
#ifdef HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_ICONV
|
||||
# include <iconv.h>
|
||||
#endif
|
||||
#include <shout/shout.h>
|
||||
|
||||
#include "compat.h"
|
||||
#include "util.h"
|
||||
#include "configfile.h"
|
||||
#include "xalloc.h"
|
||||
|
78
src/xalloc.c
78
src/xalloc.c
@ -19,15 +19,7 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "ezstream.h"
|
||||
|
||||
#include "xalloc.h"
|
||||
|
||||
@ -43,27 +35,6 @@
|
||||
# undef XALLOC_SILENT
|
||||
#endif /* XALLOC_DEBUG && XALLOC_SILENT */
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
# include <pthread.h>
|
||||
static pthread_mutex_t xalloc_mutex;
|
||||
static pthread_mutex_t strerror_mutex;
|
||||
# define XALLOC_LOCK(mtx) do { \
|
||||
int error; \
|
||||
if ((error = pthread_mutex_lock(&mtx)) != 0) \
|
||||
_xalloc_error(error, "XALLOC: Internal error in %s:%u: pthread_mutex_lock()", \
|
||||
__FILE__, __LINE__); \
|
||||
} while (0)
|
||||
# define XALLOC_UNLOCK(mtx) do { \
|
||||
int error; \
|
||||
if ((error = pthread_mutex_unlock(&mtx)) != 0) \
|
||||
_xalloc_error(error, "XALLOC: Internal error in %s:%u: pthread_mutex_unlock()", \
|
||||
__FILE__, __LINE__); \
|
||||
} while (0)
|
||||
#else
|
||||
# define XALLOC_LOCK(mtx) ((void)0)
|
||||
# define XALLOC_UNLOCK(mtx) ((void)0)
|
||||
#endif /* THREAD_SAFE */
|
||||
|
||||
#ifdef XALLOC_DEBUG
|
||||
# include <sys/tree.h>
|
||||
|
||||
@ -170,13 +141,8 @@ _xalloc_error(int errnum, const char *fmt, ...)
|
||||
va_start(ap, fmt);
|
||||
#ifndef XALLOC_SILENT
|
||||
vfprintf(debug_output, fmt, ap);
|
||||
if (errnum > 0) {
|
||||
if (xalloc_initialized)
|
||||
XALLOC_LOCK(strerror_mutex);
|
||||
if (errnum > 0)
|
||||
fprintf(debug_output, ": %s\n", strerror(errnum));
|
||||
if (xalloc_initialized)
|
||||
XALLOC_UNLOCK(strerror_mutex);
|
||||
}
|
||||
fflush(debug_output);
|
||||
#endif /* !XALLOC_SILENT */
|
||||
va_end(ap);
|
||||
@ -292,10 +258,6 @@ _xalloc_vasprintf(char **str_p, const char *fmt, va_list ap, size_t *strsiz)
|
||||
void
|
||||
xalloc_initialize_debug(unsigned int level, FILE *output)
|
||||
{
|
||||
#ifdef THREAD_SAFE
|
||||
int err;
|
||||
#endif /* THREAD_SAFE */
|
||||
|
||||
if (xalloc_initialized)
|
||||
_xalloc_fatal("XALLOC: xalloc_initialize(): Xalloc library already initialized\n");
|
||||
|
||||
@ -315,13 +277,6 @@ xalloc_initialize_debug(unsigned int level, FILE *output)
|
||||
xalloc_peak = 0;
|
||||
xalloc_freed = 0;
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
if ((err = pthread_mutex_init(&strerror_mutex, NULL)) != 0)
|
||||
_xalloc_error(err, "XALLOC: xalloc_initialize(): Initializing xalloc_mutex");
|
||||
if ((err = pthread_mutex_init(&xalloc_mutex, NULL)) != 0)
|
||||
_xalloc_error(err, "XALLOC: xalloc_initialize(): Initializing strerror_mutex");
|
||||
#endif /* THREAD_SAFE */
|
||||
|
||||
xalloc_initialized = 1;
|
||||
}
|
||||
|
||||
@ -339,12 +294,10 @@ xalloc_set_functions(void *(*malloc_func)(size_t),
|
||||
realloc_func == NULL)
|
||||
_xalloc_fatal("XALLOC: xalloc_set_functions(): Bad argument(s)\n");
|
||||
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
real_malloc = malloc_func;
|
||||
real_calloc = calloc_func;
|
||||
real_realloc = realloc_func;
|
||||
real_free = free_func;
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
}
|
||||
|
||||
void
|
||||
@ -358,8 +311,6 @@ xalloc_shutdown(void)
|
||||
struct memory *mem, *mem_next;
|
||||
size_t leaked_bytes = 0;
|
||||
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
|
||||
for (mem = RB_MIN(memory_tree, &memory_tree_head);
|
||||
mem != NULL;
|
||||
mem = mem_next) {
|
||||
@ -395,20 +346,9 @@ xalloc_shutdown(void)
|
||||
(unsigned long)xalloc_peak,
|
||||
(unsigned long)xalloc_freed,
|
||||
(unsigned long)xalloc_total);
|
||||
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
}
|
||||
#endif /* XALLOC_DEBUG */
|
||||
|
||||
#ifdef THREAD_SAFE
|
||||
if (pthread_mutex_destroy(&xalloc_mutex) != 0)
|
||||
_xalloc_fatal("XALLOC: Internal error: xalloc_shutdown(): xalloc_mutex %p cannot be destroyed\n",
|
||||
xalloc_mutex);
|
||||
if (pthread_mutex_destroy(&strerror_mutex) != 0)
|
||||
_xalloc_fatal("XALLOC: Internal error: xalloc_shutdown(): strerror_mutex %p cannot be destroyed\n",
|
||||
strerror_mutex);
|
||||
#endif /* THREAD_SAFE */
|
||||
|
||||
xalloc_initialized = 0;
|
||||
}
|
||||
|
||||
@ -442,7 +382,6 @@ xmalloc_c(size_t size, const char *file, unsigned int line)
|
||||
else
|
||||
mem->allocated_by = unknown_file;
|
||||
mem->allocated_in_line = line;
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
mem->id = ++xalloc_next_id;
|
||||
if ((mem_exists = RB_INSERT(memory_tree, &memory_tree_head, mem)) != NULL) {
|
||||
/* Freed pointer is being reused: */
|
||||
@ -457,7 +396,6 @@ xmalloc_c(size_t size, const char *file, unsigned int line)
|
||||
xalloc_total += size;
|
||||
if (xalloc_allocated > xalloc_peak)
|
||||
xalloc_peak = xalloc_allocated;
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
}
|
||||
#endif /* XALLOC_DEBUG */
|
||||
|
||||
@ -499,7 +437,6 @@ xcalloc_c(size_t nmemb, size_t size, int may_fail,
|
||||
else
|
||||
mem->allocated_by = unknown_file;
|
||||
mem->allocated_in_line = line;
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
mem->id = ++xalloc_next_id;
|
||||
if ((mem_exists = RB_INSERT(memory_tree, &memory_tree_head, mem)) != NULL) {
|
||||
/* Freed pointer is being reused: */
|
||||
@ -514,7 +451,6 @@ xcalloc_c(size_t nmemb, size_t size, int may_fail,
|
||||
xalloc_total += nmemb * size;
|
||||
if (xalloc_allocated > xalloc_peak)
|
||||
xalloc_peak = xalloc_allocated;
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
}
|
||||
#endif /* XALLOC_DEBUG */
|
||||
|
||||
@ -549,9 +485,7 @@ xrealloc_c(void *ptr, size_t nmemb, size_t size,
|
||||
if ((mem = real_calloc(1, sizeof(struct memory))) == NULL)
|
||||
_xalloc_error(errno, "XALLOC: Internal error");
|
||||
mem->ptr = ret;
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
mem->id = ++xalloc_next_id;
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
if (file)
|
||||
mem->allocated_by = file;
|
||||
else
|
||||
@ -563,7 +497,6 @@ xrealloc_c(void *ptr, size_t nmemb, size_t size,
|
||||
#ifdef XALLOC_DEBUG
|
||||
struct memory find_mem;
|
||||
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
if (debug_level > 0) {
|
||||
find_mem.ptr = ptr;
|
||||
if ((mem = RB_FIND(memory_tree, &memory_tree_head, &find_mem)) == NULL)
|
||||
@ -572,7 +505,6 @@ xrealloc_c(void *ptr, size_t nmemb, size_t size,
|
||||
line, ptr);
|
||||
RB_REMOVE(memory_tree, &memory_tree_head, mem);
|
||||
}
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
#endif /* XALLOC_DEBUG */
|
||||
ret = real_realloc(ptr, nsiz);
|
||||
#ifdef XALLOC_DEBUG
|
||||
@ -597,7 +529,6 @@ xrealloc_c(void *ptr, size_t nmemb, size_t size,
|
||||
struct memory *mem_exists;
|
||||
ssize_t diff = (ssize_t)(nsiz - mem->size);
|
||||
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
xalloc_allocated += diff;
|
||||
if (diff < 0)
|
||||
xalloc_freed += -diff;
|
||||
@ -615,7 +546,6 @@ xrealloc_c(void *ptr, size_t nmemb, size_t size,
|
||||
_memory_free(&mem_exists);
|
||||
RB_INSERT(memory_tree, &memory_tree_head, mem);
|
||||
}
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
}
|
||||
#endif /* XALLOC_DEBUG */
|
||||
|
||||
@ -659,7 +589,6 @@ xfree_c(void **ptr_p, const char *file, unsigned int line)
|
||||
if (debug_level > 0) {
|
||||
struct memory *mem = NULL, find_mem;
|
||||
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
find_mem.ptr = *ptr_p;
|
||||
if ((mem = RB_FIND(memory_tree, &memory_tree_head, &find_mem)) == NULL)
|
||||
_xalloc_fatal("XALLOC: xfree(): %s:%u: Junk pointer %p not accounted for\n",
|
||||
@ -696,7 +625,6 @@ xfree_c(void **ptr_p, const char *file, unsigned int line)
|
||||
RB_REMOVE(memory_tree, &memory_tree_head, mem);
|
||||
_memory_free(&mem);
|
||||
}
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
}
|
||||
#endif /* XALLOC_DEBUG */
|
||||
|
||||
@ -744,7 +672,6 @@ xasprintf_c(const char *file, unsigned int line,
|
||||
else
|
||||
mem->allocated_by = unknown_file;
|
||||
mem->allocated_in_line = line;
|
||||
XALLOC_LOCK(xalloc_mutex);
|
||||
mem->id = ++xalloc_next_id;
|
||||
if ((mem_exists = RB_INSERT(memory_tree, &memory_tree_head, mem)) != NULL) {
|
||||
/* Freed pointer is being reused: */
|
||||
@ -759,7 +686,6 @@ xasprintf_c(const char *file, unsigned int line,
|
||||
xalloc_total += strsiz;
|
||||
if (xalloc_allocated > xalloc_peak)
|
||||
xalloc_peak = xalloc_allocated;
|
||||
XALLOC_UNLOCK(xalloc_mutex);
|
||||
}
|
||||
# endif /* XALLOC_DEBUG */
|
||||
|
||||
|
@ -37,8 +37,7 @@
|
||||
* over time!)
|
||||
*
|
||||
* Define XALLOC_SILENT to suppress all messages, which makes libxalloc
|
||||
* abort() and exit() silently. This has no effect when THREAD_DEBUG is
|
||||
* defined.
|
||||
* abort() and exit() silently.
|
||||
*
|
||||
* Define XALLOC_WITH_XASPRINTF to expose the xasprintf() interface. Doing
|
||||
* so will require libxalloc to be compiled with a compiler that supports C99
|
||||
@ -55,10 +54,6 @@
|
||||
/* The default output stream for messages: */
|
||||
#define XALLOC_DEFAULT_OUTPUT stderr
|
||||
|
||||
#if (defined(_REENTRANT) || defined(_POSIX_THREADS)) && !defined(THREAD_SAFE)
|
||||
# define THREAD_SAFE 1
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Library initialization and shutdown.
|
||||
|
@ -12,8 +12,11 @@
|
||||
#define popen _popen
|
||||
#define pclose _pclose
|
||||
#define snprintf _snprintf
|
||||
#define strncasecmp strnicmp
|
||||
#define stat _stat
|
||||
#define strncasecmp strnicmp
|
||||
#ifndef __GNUC__
|
||||
# define strtoll _strtoi64
|
||||
#endif /* !__GNUC__ */
|
||||
|
||||
#define sleep(a) Sleep((a) * 1000)
|
||||
|
||||
@ -25,8 +28,7 @@
|
||||
#define S_IWOTH 0
|
||||
#define S_IXGRP 0
|
||||
#define S_IXOTH 0
|
||||
#define PATH_SEPARATOR '\\'
|
||||
#define _PATH_DEVNULL "nul"
|
||||
#define PATH_SEPARATORS "\\/"
|
||||
|
||||
#ifndef ssize_t
|
||||
# define ssize_t long
|
||||
|
Loading…
Reference in New Issue
Block a user