From a6109b9aba59303c408ee810adc74571b1a747d2 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 8 Jun 2003 20:45:02 +0000 Subject: [PATCH] Use standard basename() function if available. svn path=/trunk/yasm/; revision=974 --- configure.ac | 4 ++-- frontends/yasm/yasm-module.c | 39 +++++++++++++++++++++++------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index 419765df..ac01d08d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ # Process this file with autoconf to produce a configure script. -# $IdPath: yasm/configure.ac,v 1.70 2003/03/18 05:00:54 peter Exp $ +# $IdPath$ # Minimum required perl version for development PERL_VERSION=5.004 @@ -116,7 +116,7 @@ AC_TYPE_SIZE_T AC_FUNC_FORK AC_FUNC_MALLOC AC_FUNC_VPRINTF -AC_CHECK_FUNCS([abort memcpy memmove strrchr toascii vsnprintf]) +AC_CHECK_FUNCS([abort basename memcpy memmove strrchr toascii vsnprintf]) AC_CHECK_FUNCS([strsep mergesort]) # Look for the case-insensitive comparison functions AC_CHECK_FUNCS([strcasecmp strncasecmp stricmp strcmpi]) diff --git a/frontends/yasm/yasm-module.c b/frontends/yasm/yasm-module.c index 5a5218d4..a5acf5ef 100644 --- a/frontends/yasm/yasm-module.c +++ b/frontends/yasm/yasm-module.c @@ -145,11 +145,26 @@ typedef struct list_module_data { size_t matches_num, matches_alloc; } list_module_data; +#ifdef HAVE_BASENAME +extern char *basename(const char *); +#else +static const char * +basename(const char *path) +{ + const char *base; + base = strrchr(path, '/'); + if (!base) + base = path; + else + base++; +} +#endif + static int list_module_load(const char *filename, lt_ptr data) { list_module_data *lmdata = data; - const char *basename; + const char *base; const char *module_keyword = NULL, *module_name = NULL; char *name; @@ -162,24 +177,20 @@ list_module_load(const char *filename, lt_ptr data) lt_dlhandle handle; - /* All modules have '_' in them; early check */ - if (!strchr(filename, '_')) + /* Strip off path components, if any */ + base = basename(filename); + if (!base) return 0; - /* Strip off path components, if any */ - basename = strrchr(filename, '/'); - if (!basename) - basename = strrchr(filename, '\\'); - if (!basename) - basename = filename; - else - basename++; + /* All modules have '_' in them; early check */ + if (!strchr(base, '_')) + return 0; /* Check to see if module is of the type we're looking for. * Even though this check is also implicitly performed below, there's a * massive speedup in avoiding the dlopen() call. */ - if (strncmp(basename, module_type_str[lmdata->type], + if (strncmp(base, module_type_str[lmdata->type], strlen(module_type_str[lmdata->type])) != 0) return 0; @@ -189,9 +200,9 @@ list_module_load(const char *filename, lt_ptr data) return 0; /* Build base symbol name */ - name = yasm_xmalloc(strlen(basename)+5+ + name = yasm_xmalloc(strlen(base)+5+ strlen(module_type_str[lmdata->type])+1); - strcpy(name, basename); + strcpy(name, base); strcat(name, "_LTX_"); strcat(name, module_type_str[lmdata->type]); -- 2.40.0