--- /dev/null
+/* $OpenBSD: basename.c,v 1.11 2003/06/17 21:56:23 millert Exp $ */
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: basename.c,v 1.11 2003/06/17 21:56:23 millert Exp $";
+#endif /* not lint */
+
+#include <string.h>
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#elif !defined(MAXPATHLEN)
+#define MAXPATHLEN 1024
+#endif
+
+char *
+basename(const char *path)
+{
+ static char bname[MAXPATHLEN];
+ register const char *endp, *startp;
+
+ /* Empty or NULL string gets treated as "." */
+ if (path == NULL || *path == '\0') {
+ (void)strcpy(bname, ".");
+ return(bname);
+ }
+
+ /* Strip trailing slashes */
+ endp = path + strlen(path) - 1;
+ while (endp > path && *endp == '/')
+ endp--;
+
+ /* All slashes become "/" */
+ if (endp == path && *endp == '/') {
+ (void)strcpy(bname, "/");
+ return(bname);
+ }
+
+ /* Find the start of the base */
+ startp = endp;
+ while (startp > path && *(startp - 1) != '/')
+ startp--;
+
+ if (endp - startp + 2 > sizeof(bname)) {
+ return(NULL);
+ }
+ (void)strncpy(bname, startp, endp - startp + 1);
+ bname[endp - startp + 1] = '\0';
+ return(bname);
+}
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_VPRINTF
-AC_CHECK_FUNCS([abort basename memcpy memmove strrchr toascii vsnprintf])
+AC_CHECK_FUNCS([abort memcpy memmove strrchr toascii vsnprintf])
AC_CHECK_FUNCS([strsep mergesort])
# Look for the case-insensitive comparison functions
AC_CHECK_FUNCS([strcasecmp strncasecmp stricmp strcmpi])
# Check for stuff wanted by the test suite. None of this is required.
AC_CHECK_FUNCS([msgctl msgget msgrcv msgsnd strerror snprintf wait])
+AC_REPLACE_FUNCS([basename dirname])
AC_LIB_LTDL
#
--- /dev/null
+/* $OpenBSD: dirname.c,v 1.10 2003/06/17 21:56:23 millert Exp $ */
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * 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 THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR 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.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: dirname.c,v 1.10 2003/06/17 21:56:23 millert Exp $";
+#endif /* not lint */
+
+#include <string.h>
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#elif !defined(MAXPATHLEN)
+#define MAXPATHLEN 1024
+#endif
+
+char *
+dirname(const char *path)
+{
+ static char bname[MAXPATHLEN];
+ register const char *endp;
+
+ /* Empty or NULL string gets treated as "." */
+ if (path == NULL || *path == '\0') {
+ (void)strcpy(bname, ".");
+ return(bname);
+ }
+
+ /* Strip trailing slashes */
+ endp = path + strlen(path) - 1;
+ while (endp > path && *endp == '/')
+ endp--;
+
+ /* Find the start of the dir */
+ while (endp > path && *endp != '/')
+ endp--;
+
+ /* Either the dir is "/" or there are no slashes */
+ if (endp == path) {
+ (void)strcpy(bname, *endp == '/' ? "/" : ".");
+ return(bname);
+ } else {
+ do {
+ endp--;
+ } while (endp > path && *endp == '/');
+ }
+
+ if (endp - path + 2 > sizeof(bname)) {
+ return(NULL);
+ }
+ (void)strncpy(bname, path, endp - path + 1);
+ bname[endp - path + 1] = '\0';
+ return(bname);
+}
#include "yasm-module.h"
+extern char *basename(const char *path);
+
extern const lt_dlsymlist lt_preloaded_symbols[];
typedef struct module {
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++;
- return base;
-}
-#endif
-
static int
list_module_load(const char *filename, lt_ptr data)
{
#endif
#ifndef WIN32
+extern char *dirname(const char *path);
+
extern const lt_dlsymlist lt_preloaded_symbols[];
#endif
const char *path = getenv(YASM_MODULE_PATH_ENV);
if (path)
errors = lt_dladdsearchdir(path);
+ }
#if defined(YASM_MODULEDIR)
- if (errors == 0)
- errors = lt_dladdsearchdir(YASM_MODULEDIR);
+ if (errors == 0)
+ errors = lt_dladdsearchdir(YASM_MODULEDIR);
#endif
+ if (errors == 0) {
+ /* Path where yasm executable is running from (argv[0]) */
+ errors = lt_dladdsearchdir(dirname(argv[0]));
}
if (errors != 0) {
print_error(_("%s: module loader initialization failed"), _("FATAL"));