__EXPORT BOOL __handle_ce_reent_(HANDLE hinstDLL, DWORD dwReason, LPVOID lpvReserved) { struct _cereent* reent; switch (dwReason) { case DLL_PROCESS_ATTACH: if (!__init_ce_reent()) return FALSE; /* fall-through */ case DLL_THREAD_ATTACH: reent = (struct _cereent*)__getreent (); if (!reent) return FALSE; break; case DLL_THREAD_DETACH: __freereent(); break; case DLL_PROCESS_DETACH: __freereent(); TlsFree(libc_thread_index); break; } return TRUE; }
static void test_open(dummy_vfs_t* instance, const char* path, bool should_be_called, bool should_be_opened, int line) { const int flags = O_CREAT | O_TRUNC | O_RDWR; instance->called = false; int fd = esp_vfs_open(__getreent(), path, flags, 0); UNITY_TEST_ASSERT_EQUAL_INT(should_be_called, instance->called, line, "should_be_called check failed"); if (should_be_called) { if (should_be_opened) { UNITY_TEST_ASSERT(fd >= 0, line, "should be opened"); } else { UNITY_TEST_ASSERT(fd < 0, line, "should not be opened"); } } esp_vfs_close(__getreent(), fd); }
void seekdir(DIR* pdir, long loc) { const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx); struct _reent* r = __getreent(); if (vfs == NULL) { errno = EBADF; return; } CHECK_AND_CALLV(r, vfs, seekdir, pdir, loc); }
int closedir(DIR* pdir) { const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx); struct _reent* r = __getreent(); if (vfs == NULL) { errno = EBADF; return -1; } int ret; CHECK_AND_CALL(ret, r, vfs, closedir, pdir); return ret; }
int readdir_r(DIR* pdir, struct dirent* entry, struct dirent** out_dirent) { const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx); struct _reent* r = __getreent(); if (vfs == NULL) { errno = EBADF; return -1; } int ret; CHECK_AND_CALL(ret, r, vfs, readdir_r, pdir, entry, out_dirent); return ret; }
struct dirent* readdir(DIR* pdir) { const vfs_entry_t* vfs = get_vfs_for_fd(pdir->dd_vfs_idx); struct _reent* r = __getreent(); if (vfs == NULL) { __errno_r(r) = EBADF; return NULL; } struct dirent* ret; CHECK_AND_CALLP(ret, r, vfs, readdir, pdir); return ret; }
int rmdir(const char* name) { const vfs_entry_t* vfs = get_vfs_for_path(name); struct _reent* r = __getreent(); if (vfs == NULL) { __errno_r(r) = ENOENT; return -1; } const char* path_within_vfs = translate_path(vfs, name); int ret; CHECK_AND_CALL(ret, r, vfs, rmdir, path_within_vfs); return ret; }
DIR* opendir(const char* name) { const vfs_entry_t* vfs = get_vfs_for_path(name); struct _reent* r = __getreent(); if (vfs == NULL) { __errno_r(r) = ENOENT; return NULL; } const char* path_within_vfs = translate_path(vfs, name); DIR* ret; CHECK_AND_CALLP(ret, r, vfs, opendir, path_within_vfs); if (ret != NULL) { ret->dd_vfs_idx = vfs->offset << VFS_INDEX_S; } return ret; }
int *__errno( void ) { return &__getreent()->_errno; }
MPU_WRAPPER(int, init_signal, (__getreent_mpu())) MPU_WRAPPER(int, _sigtramp, (__getreent_mpu(), sig), int sig) MPU_WRAPPER(int, sleep, (__getreent_mpu(), seconds), unsigned int seconds) MPU_WRAPPER(int, stat, (__getreent_mpu(), path, buf), const char *restrict path, struct stat *restrict buf) MPU_WRAPPER(int, symlink, (__getreent_mpu(), path1, path2), const char *path1, const char *path2) MPU_WRAPPER(clock_t, times, (__getreent_mpu(), buffer), struct tms *buffer) MPU_WRAPPER(int, unlink, (__getreent_mpu(), path), const char *path) MPU_WRAPPER(int, usleep, (__getreent_mpu(), usec), useconds_t usec) MPU_WRAPPER(ssize_t, write, (__getreent_mpu(), fd, buf, nbyte), int fd, const void *buf, size_t nbyte) // The following is a list of non-"_r" symbols used in the Newlib build that // are referenced but not defined (and thus need to be provided here). Similarly // to the above MPU wrappers, these need to call __getreent() thus need to raise // and lower their privileges. REENT_WRAPPER(void *, calloc, (__getreent(), count, size), size_t count, size_t size) REENT_WRAPPER(int, fclose, (__getreent(), stream), FILE *stream) REENT_WRAPPER(int, fflush, (__getreent(), stream), FILE *stream) REENT_WRAPPER(int, fputc, (__getreent(), c, stream), int c, FILE *stream) REENT_WRAPPER(int, fputs, (__getreent(), str, stream), const char *restrict str, FILE *restrict stream) REENT_WRAPPER(size_t, fread, (__getreent(), ptr, size, nitems, stream), void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream) REENT_WRAPPER_VOID( free, (__getreent(), ptr), void *ptr) REENT_WRAPPER(size_t, fwrite, (__getreent(), ptr, size, nitems, stream), const void *ptr, size_t size, size_t nitems, FILE *stream) REENT_WRAPPER(int, getc_unlocked, (__getreent(), stream), FILE *stream) REENT_WRAPPER(char *, getenv, (__getreent(), name), const char *name) REENT_WRAPPER(void *, malloc, (__getreent(), size), size_t size) REENT_WRAPPER(size_t, mbrtowc, (__getreent(), pwc, s, n, ps), wchar_t *restrict pwc, const char *restrict s, size_t n, mbstate_t *restrict ps) REENT_WRAPPER(void *, memalign, (__getreent(), blocksize, bytes), size_t blocksize, size_t bytes) REENT_WRAPPER(int, mkstemp, (__getreent(), template), char *template) REENT_WRAPPER(int, putc_unlocked, (__getreent(), c, stream), int c, FILE *stream) REENT_WRAPPER(int, puts, (__getreent(), str), const char *str)