diff options
Diffstat (limited to 'windows')
-rw-r--r-- | windows/Makefile | 2 | ||||
-rw-r--r-- | windows/alloca.h | 3 | ||||
-rw-r--r-- | windows/init.c | 5 | ||||
-rw-r--r-- | windows/init.h | 1 | ||||
-rw-r--r-- | windows/mpconfigport.h | 7 | ||||
-rw-r--r-- | windows/realpath.c | 42 | ||||
-rw-r--r-- | windows/realpath.h | 2 |
7 files changed, 62 insertions, 0 deletions
diff --git a/windows/Makefile b/windows/Makefile index 2f5418886f..ce75a60985 100644 --- a/windows/Makefile +++ b/windows/Makefile @@ -30,6 +30,8 @@ endif SRC_C = \ unix/main.c \ unix/file.c \ + realpath.c \ + init.c \ OBJ = $(PY_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) diff --git a/windows/alloca.h b/windows/alloca.h new file mode 100644 index 0000000000..1cf7722669 --- /dev/null +++ b/windows/alloca.h @@ -0,0 +1,3 @@ +// Compatibility header to workaround lack of native alloca.h in some +// Windows toolchains. +#include <malloc.h> diff --git a/windows/init.c b/windows/init.c new file mode 100644 index 0000000000..78b8738f77 --- /dev/null +++ b/windows/init.c @@ -0,0 +1,5 @@ +#include <stdlib.h> + +void init() { + putenv("PRINTF_EXPONENT_DIGITS=2"); +} diff --git a/windows/init.h b/windows/init.h new file mode 100644 index 0000000000..70e535e495 --- /dev/null +++ b/windows/init.h @@ -0,0 +1 @@ +void init(void); diff --git a/windows/mpconfigport.h b/windows/mpconfigport.h index 993fef9d59..94b3334007 100644 --- a/windows/mpconfigport.h +++ b/windows/mpconfigport.h @@ -12,8 +12,10 @@ #define MICROPY_DEBUG_PRINTERS (1) #define MICROPY_ENABLE_REPL_HELPERS (1) #define MICROPY_ENABLE_LEXER_UNIX (1) +#define MICROPY_MOD_SYS_STDFILES (1) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) +#define MICROPY_PORT_INIT_FUNC init() // type definitions for the specific machine @@ -33,3 +35,8 @@ typedef void *machine_ptr_t; // must be of pointer size typedef const void *machine_const_ptr_t; // must be of pointer size extern const struct _mp_obj_fun_native_t mp_builtin_open_obj; +#define MICROPY_EXTRA_BUILTINS \ + { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, + +#include "realpath.h" +#include "init.h" diff --git a/windows/realpath.c b/windows/realpath.c new file mode 100644 index 0000000000..550298a7d5 --- /dev/null +++ b/windows/realpath.c @@ -0,0 +1,42 @@ +#include <stdlib.h> +#include <errno.h> +#include <io.h> + +#ifndef R_OK + #define R_OK 4 +#endif + +// Make sure a path only has forward slashes. +char *to_unix_path(char *p) { + if (p != NULL) { + char *pp = p; + while (*pp != 0) { + if (*pp == '\\') + *pp = '/'; + ++pp; + } + } + return p; +} + +// Implement realpath() using _fullpath and make it use the same error codes as realpath() on unix. +// Also have it return a path with forward slashes only as some code relies on this, +// but _fullpath() returns backward slashes no matter what. +char *realpath(const char *path, char *resolved_path) { + char *ret = NULL; + if (path == NULL) { + errno = EINVAL; + } else if (access(path, R_OK) == 0) { + ret = resolved_path; + if (ret == NULL) + ret = malloc(_MAX_PATH); + if (ret == NULL) { + errno = ENOMEM; + } else { + ret = _fullpath(ret, path, _MAX_PATH); + if (ret == NULL) + errno = EIO; + } + } + return to_unix_path(ret); +} diff --git a/windows/realpath.h b/windows/realpath.h new file mode 100644 index 0000000000..77798acd57 --- /dev/null +++ b/windows/realpath.h @@ -0,0 +1,2 @@ + +extern char *realpath(const char *path, char *resolved_path); |