Merge pull request #293 from mdbtools/no-wordexp

SQL: Allow spaces in DB names (remove wordexp.h)
This commit is contained in:
Evan Miller 2021-04-05 09:00:57 -04:00 committed by GitHub
commit afd154f619
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 42 deletions

View File

@ -30,7 +30,6 @@ AC_PROG_YACC
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h limits.h unistd.h xlocale.h)
AC_CHECK_HEADERS(wordexp.h)
AC_CHECK_LIB(mswstr, DBLCMapStringW)
AC_CHECK_DECLS([program_invocation_short_name], [], [], [[
#define _GNU_SOURCE

View File

@ -20,11 +20,6 @@
#define _XOPEN_SOURCE
#include "mdbsql.h"
#ifdef HAVE_WORDEXP_H
#define HAVE_WORDEXP
#include <wordexp.h>
#endif
#ifdef HAVE_STRPTIME
#include <time.h>
#include <stdio.h>
@ -191,35 +186,9 @@ mdb_sql_close(MdbSQL *sql)
MdbHandle *mdb_sql_open(MdbSQL *sql, char *db_name)
{
char *db_namep = db_name;
#ifdef HAVE_WORDEXP
wordexp_t words;
int need_free_words = 0;
switch (wordexp(db_name, &words, 0))
{
case 0:
if (words.we_wordc>0)
{
db_namep = words.we_wordv[0];
}
need_free_words = 1;
break;
case WRDE_NOSPACE:
// If the error was WRDE_NOSPACE, then perhaps part of the result was allocated.
need_free_words = 1;
break;
default:
// Some other error
need_free_words = 0;
break;
}
#endif
sql->mdb = mdb_open(db_namep, MDB_NOFLAGS);
if ((!sql->mdb) && (!strstr(db_namep, ".mdb"))) {
char *tmpstr = (char *) g_strconcat(db_namep, ".mdb", NULL);
sql->mdb = mdb_open(db_name, MDB_NOFLAGS);
if ((!sql->mdb) && (!strstr(db_name, ".mdb"))) {
char *tmpstr = g_strconcat(db_name, ".mdb", NULL);
sql->mdb = mdb_open(tmpstr, MDB_NOFLAGS);
g_free(tmpstr);
}
@ -227,13 +196,6 @@ MdbHandle *mdb_sql_open(MdbSQL *sql, char *db_name)
mdb_sql_error(sql, "Unable to locate database %s", db_name);
}
#ifdef HAVE_WORDEXP
if ( need_free_words )
{
wordfree(&words);
}
#endif
return sql->mdb;
}
static MdbSargNode *