From 5f152d9ef033029e81dd55abf44ced15cf00731c Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Mon, 12 Nov 2001 07:32:55 +0000 Subject: [PATCH] * mad.h: Enable glib support. * mad.[ch] (mad_get_current_dir): New function to use instead of g_get_current_dir. (mad_tempnam): Add file and line parameters. (mad_alloc0): Make file parameter const. (mad_realloc): Likewise. (mad_strdup): Likewise. (mad_strndup): Likewise. (mad_free): Likewise. (mad_finalize): Likewise. --- src/ChangeLog | 14 ++++++++++++++ src/mad.c | 31 ++++++++++++++++++++----------- src/mad.h | 20 +++++++++++--------- 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index facfcc1ce..c17fcd9fe 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2001-11-12 Andrew V. Samoilov + + * mad.h: Enable glib support. + + * mad.[ch] (mad_get_current_dir): New function to use instead + of g_get_current_dir. + (mad_tempnam): Add file and line parameters. + (mad_alloc0): Make file parameter const. + (mad_realloc): Likewise. + (mad_strdup): Likewise. + (mad_strndup): Likewise. + (mad_free): Likewise. + (mad_finalize): Likewise. + 2001-11-07 Andrew V. Samoilov * cmd.c (guess_message_value): Make val static const array. diff --git a/src/mad.c b/src/mad.c index db34d898b..64f41fe7f 100644 --- a/src/mad.c +++ b/src/mad.c @@ -36,6 +36,7 @@ #undef g_strdup #undef g_strndup #undef g_free +#undef g_get_current_dir #include #include @@ -180,7 +181,7 @@ void *mad_alloc (int size, const char *file, int line) } /* Reallocates a memory area. Used instead of realloc. */ -void *mad_realloc (void *ptr, int newsize, char *file, int line) +void *mad_realloc (void *ptr, int newsize, const char *file, int line) { int i; char *area; @@ -211,16 +212,15 @@ void *mad_realloc (void *ptr, int newsize, char *file, int line) *(mem_areas [i].start_sig) = MAD_SIGNATURE; *(mem_areas [i].end_sig) = MAD_SIGNATURE; - if (strlen (file) >= MAD_MAX_FILE) - file [MAD_MAX_FILE - 1] = 0; - strcpy (mem_areas [i].file, file); + strncpy (mem_areas [i].file, file, MAD_MAX_FILE - 1); + mem_areas [i].file [MAD_MAX_FILE - 1] = 0; mem_areas [i].line = line; return mem_areas [i].data; } /* Allocates a memory area. Used instead of malloc and calloc. */ -void *mad_alloc0 (int size, char *file, int line) +void *mad_alloc0 (int size, const char *file, int line) { char *t; @@ -230,7 +230,7 @@ void *mad_alloc0 (int size, char *file, int line) } /* Duplicates a character string. Used instead of strdup. */ -char *mad_strdup (const char *s, char *file, int line) +char *mad_strdup (const char *s, const char *file, int line) { if (s) { char *t; @@ -244,7 +244,7 @@ char *mad_strdup (const char *s, char *file, int line) /* Duplicates a character string. Used instead of strndup. */ /* Dup of GLib's gstrfuncs.c:g_strndup() */ -char *mad_strndup (const char *s, int n, char *file, int line) +char *mad_strndup (const char *s, int n, const char *file, int line) { if(s) { char *new_str = mad_alloc(n + 1, file, line); @@ -257,7 +257,7 @@ char *mad_strndup (const char *s, int n, char *file, int line) } /* Frees a memory area. Used instead of free. */ -void mad_free (void *ptr, char *file, int line) +void mad_free (void *ptr, const char *file, int line) { int i; @@ -300,18 +300,18 @@ void mad_free (void *ptr, char *file, int line) Alloc_idx_hint = i; } -char *mad_tempnam (char *a, char *b) +char *mad_tempnam (char *a, char *b, const char *file, int line) { char *t, *u; t = tempnam(a,b); /* This malloc's internal buffer.. */ - u = mad_strdup(t, "(mad_tempnam)", 0); + u = mad_strdup(t, file, line); free(t); return u; } /* Outputs a list of unfreed memory areas, to be called as a last thing before exiting */ -void mad_finalize (char *file, int line) +void mad_finalize (const char *file, int line) { int i; @@ -399,4 +399,13 @@ mad_strdup_printf (const char *format, ...) return buffer; } + +char* +mad_get_current_dir (const char *file, int line) +{ + char *cwd = g_get_current_dir (); + char *ret = mad_strdup (cwd, file, line); + g_free (cwd); + return ret; +} #endif /* HAVE_MAD */ diff --git a/src/mad.h b/src/mad.h index 6fcac8078..9351f5231 100644 --- a/src/mad.h +++ b/src/mad.h @@ -30,7 +30,7 @@ # undef calloc #endif -#define tempnam(x,y) mad_tempnam (x, y) +#define tempnam(x,y) mad_tempnam (x, y, __FILE__, __LINE__) #define malloc(x) mad_alloc (x, __FILE__, __LINE__) #define calloc(x, y) mad_alloc0 ((x) * (y), __FILE__, __LINE__) @@ -50,8 +50,8 @@ * Define MAD_GLIB to debug allocations in glib as well. * This code is not functional yet. */ -#undef MAD_GLIB +#define MAD_GLIB #ifdef MAD_GLIB /* These definitions are grabbed from GLib.h */ #define g_new(type, count) \ @@ -70,22 +70,24 @@ #define g_strconcat mad_strconcat #define g_strdup_printf mad_strdup_printf #define g_strdup_vprintf mad_strdup_vprintf +#define g_get_current_dir() mad_get_current_dir (__FILE__, __LINE__) #endif /* MAD_GLIB */ void mad_init (void); void mad_set_debug (const char *file); void mad_check (const char *file, int line); void *mad_alloc (int size, const char *file, int line); -void *mad_alloc0 (int size, char *file, int line); -void *mad_realloc (void *ptr, int newsize, char *file, int line); -char *mad_strdup (const char *s, char *file, int line); -char *mad_strndup (const char *s, int n, char *file, int line); -void mad_free (void *ptr, char *file, int line); -void mad_finalize (char *file, int line); -char *mad_tempnam (char *s1, char *s2); +void *mad_alloc0 (int size, const char *file, int line); +void *mad_realloc (void *ptr, int newsize, const char *file, int line); +char *mad_strdup (const char *s, const char *file, int line); +char *mad_strndup (const char *s, int n, const char *file, int line); +void mad_free (void *ptr, const char *file, int line); +void mad_finalize (const char *file, int line); +char *mad_tempnam (char *s1, char *s2, const char *file, int line); char *mad_strconcat (const char *first, ...); char *mad_strdup_printf (const char *format, ...); char *mad_strdup_vprintf (const char *format, va_list args); +char *mad_get_current_dir (const char *file, int line); #else -- 2.11.4.GIT