Commit d4e7e06d authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

unix: Properly recognize and report when script on cmdline not found.

Previosuly just silently exited.
parent 094d4500
......@@ -6,6 +6,7 @@
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include "nlr.h"
#include "misc.h"
......@@ -369,13 +370,19 @@ int main(int argc, char **argv) {
return usage();
}
} else {
// Set base dir of the script as first entry in sys.path
char *basedir = realpath(argv[a], NULL);
if (basedir != NULL) {
char *p = strrchr(basedir, '/');
path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir));
free(basedir);
if (basedir == NULL) {
fprintf(stderr, "%s: can't open file '%s': [Errno %d] ", argv[0], argv[1], errno);
perror("");
// CPython exits with 2 in such case
exit(2);
}
// Set base dir of the script as first entry in sys.path
char *p = strrchr(basedir, '/');
path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir));
free(basedir);
for (int i = a; i < argc; i++) {
mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i])));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment