ports/sh: quick-and-dirty attempt at POSIX open()

This commit is contained in:
Lephenixnoir 2022-10-29 21:41:54 +02:00
parent 3431000d2f
commit 5f0dd459bd
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 14 additions and 32 deletions

View File

@ -41,6 +41,7 @@
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#ifdef _MSC_VER
#include <direct.h> // For mkdir etc.
#endif

View File

@ -35,7 +35,7 @@
#include <fcntl.h>
#include <unistd.h>
#ifdef _WIN32
#if defined(_WIN32) || defined(__sh__)
#define fsync _commit
#else
#include <poll.h>

View File

@ -124,34 +124,3 @@ void gc_collect(void) {
gc_helper_collect_regs_and_stack();
gc_collect_end();
}
// There is no filesystem so stat'ing returns nothing.
mp_import_stat_t mp_import_stat(const char *path)
{
struct stat st;
int rc = stat(path, &st);
if(rc < 0)
return MP_IMPORT_STAT_NO_EXIST;
if(S_ISDIR(st.st_mode))
return MP_IMPORT_STAT_DIR;
else
return MP_IMPORT_STAT_FILE;
}
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
{
mp_obj_t *args_items;
size_t len;
mp_obj_get_array(*args, &len, &args_items);
printf("%d %p\n", (int)len, args_items);
if(len != 2)
return mp_const_none;
char const *path = mp_obj_str_get_str(args_items[0]);
char const *mode = mp_obj_str_get_str(args_items[1]);
printf("'%s' '%s'\n", path, mode);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);

View File

@ -11,6 +11,8 @@
#define MICROPY_GC_SPLIT_HEAP (1)
#define MP_ENDIANNESS_BIG (1)
#define MICROPY_READER_POSIX (1)
#define MICROPY_VFS (1)
#define MICROPY_VFS_POSIX (1)
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
@ -21,6 +23,7 @@
#define MICROPY_ENABLE_SOURCE_LINE (1) /* in EXTRA_FEATURES */
#define MICROPY_PY_BUILTINS_STR_UNICODE (1) /* in EXTRA_FEATURES */
#define MICROPY_PY_BUILTINS_HELP_MODULES (1) /* in EXTRA_FEATURES */
#define MICROPY_ENABLE_FINALISER (1) /* in EXTRA_FEATURES */
// #define MICROPY_PY_SYS_STDFILES (1) /* in EXTRA_FEATURES */
#define MICROPY_ALLOC_PATH_MAX (256)

View File

@ -1 +1,10 @@
static inline void mp_hal_set_interrupt_char(char c) {}
/* We don't need to provide retries since gint doesn't have EINTR */
#define MP_HAL_RETRY_SYSCALL(ret, syscall, raise) { \
ret = syscall; \
if(ret == -1) { \
int err = errno; \
raise; \
} \
}