diff options
author | Sijmen J. Mulder <ik@sjmulder.nl> | 2018-06-15 09:37:43 +0200 |
---|---|---|
committer | Sijmen J. Mulder <ik@sjmulder.nl> | 2018-06-15 09:37:43 +0200 |
commit | 69f863ed7e7475db5aa13b89fbc10b3f9152413c (patch) | |
tree | 7d7bb813b8b13e4b5c5f4983ac4b6ee75bee320f /src/main.c | |
parent | a7f9e7d9584c90862791d7c19d663841dd82ac9c (diff) |
Add NO_WORDEXP codepaths for OpenBSD
OpenBSD does not implement wordexp(). For rationale, see:
http://openbsd-archive.7691.n7.nabble.com/patch-libc-wordexp-support-td159368.html
This commit adds support for a NO_WORDEXP macro and enables it on
OpenBSD. If the macro is defined, shell expansion is simply skipped.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 36 |
1 files changed, 24 insertions, 12 deletions
@@ -60,9 +60,12 @@ #include <fcntl.h> // for F_GETFL O_NONBLOCK F_SETFL #include <locale.h> #include <wchar.h> -#include <wordexp.h> #include <sys/ioctl.h> // for ioctl +#ifndef NO_WORDEXP +#include <wordexp.h> +#endif + #include "main.h" #include "shift.h" #include "macros.h" @@ -551,28 +554,37 @@ void read_argv(int argc, char ** argv) { */ void load_sc() { + char name[PATHLEN]; + int c; + #ifndef NO_WORDEXP wordexp_t p; - wordexp(loadingfile, &p, 0); + #endif - int c; - char word[PATHLEN] = ""; + #ifdef NO_WORDEXP + if (strlcpy(name, loadingfile, sizeof(name)) >= sizeof(name)) { + sc_info("File path too long: '%s'", loadingfile); + return; + } + #else + wordexp(loadingfile, &p, 0); for (c=0; c < p.we_wordc; c++) { - if (c) sprintf(word + strlen(word), " "); - sprintf(word + strlen(word), "%s", p.we_wordv[c]); + if (c) sprintf(name + strlen(name), " "); + sprintf(name + strlen(name), "%s", p.we_wordv[c]); } - if (strlen(word) != 0) { - sc_readfile_result result = readfile(word, 0); + wordfree(&p); + #endif + + if (strlen(name) != 0) { + sc_readfile_result result = readfile(name, 0); if (!atoi((char *) get_conf_value("nocurses"))) { if (result == SC_READFILE_DOESNTEXIST) { // It's a new record! - sc_info("New file: \"%s\"", word); + sc_info("New file: \"%s\"", name); } else if (result == SC_READFILE_ERROR) { - sc_info("\"%s\" is not a SC-IM compatible file", word); + sc_info("\"%s\" is not a SC-IM compatible file", name); } } } - wordfree(&p); - return; } /** |