summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 28c6e8d..3038dd0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
}
/**