HAL: rename functions to mrb_hal_<feature>_<name> convention

rename all HAL functions from mrb_<feature>_hal_<name>() to
mrb_hal_<feature>_<name>() for better grouping and clarity. this makes all
HAL functions immediately identifiable with the mrb_hal_* prefix.

affected gems:
- mruby-task: mrb_task_hal_* -> mrb_hal_task_*
- mruby-io: mrb_io_hal_* -> mrb_hal_io_*
- mruby-socket: mrb_socket_hal_* -> mrb_hal_socket_*
- mruby-dir: mrb_dir_hal_* -> mrb_hal_dir_*

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-10-16 09:59:02 +09:00
parent 74c0fb9c6e
commit 610ff67906
18 changed files with 295 additions and 295 deletions
+15 -15
View File
@@ -30,7 +30,7 @@ struct mrb_dir_handle {
*/ */
mrb_dir_handle* mrb_dir_handle*
mrb_dir_hal_open(mrb_state *mrb, const char *path) mrb_hal_dir_open(mrb_state *mrb, const char *path)
{ {
DIR *dir = opendir(path); DIR *dir = opendir(path);
if (dir == NULL) { if (dir == NULL) {
@@ -43,7 +43,7 @@ mrb_dir_hal_open(mrb_state *mrb, const char *path)
} }
int int
mrb_dir_hal_close(mrb_state *mrb, mrb_dir_handle *handle) mrb_hal_dir_close(mrb_state *mrb, mrb_dir_handle *handle)
{ {
int result = closedir(handle->dir); int result = closedir(handle->dir);
mrb_free(mrb, handle); mrb_free(mrb, handle);
@@ -51,7 +51,7 @@ mrb_dir_hal_close(mrb_state *mrb, mrb_dir_handle *handle)
} }
const char* const char*
mrb_dir_hal_read(mrb_state *mrb, mrb_dir_handle *handle) mrb_hal_dir_read(mrb_state *mrb, mrb_dir_handle *handle)
{ {
(void)mrb; (void)mrb;
struct dirent *dp = readdir(handle->dir); struct dirent *dp = readdir(handle->dir);
@@ -59,7 +59,7 @@ mrb_dir_hal_read(mrb_state *mrb, mrb_dir_handle *handle)
} }
void void
mrb_dir_hal_rewind(mrb_state *mrb, mrb_dir_handle *handle) mrb_hal_dir_rewind(mrb_state *mrb, mrb_dir_handle *handle)
{ {
(void)mrb; (void)mrb;
rewinddir(handle->dir); rewinddir(handle->dir);
@@ -70,7 +70,7 @@ mrb_dir_hal_rewind(mrb_state *mrb, mrb_dir_handle *handle)
*/ */
int int
mrb_dir_hal_seek(mrb_state *mrb, mrb_dir_handle *handle, long pos) mrb_hal_dir_seek(mrb_state *mrb, mrb_dir_handle *handle, long pos)
{ {
#if defined(__ANDROID__) #if defined(__ANDROID__)
/* Android doesn't have reliable seekdir */ /* Android doesn't have reliable seekdir */
@@ -85,7 +85,7 @@ mrb_dir_hal_seek(mrb_state *mrb, mrb_dir_handle *handle, long pos)
} }
long long
mrb_dir_hal_tell(mrb_state *mrb, mrb_dir_handle *handle) mrb_hal_dir_tell(mrb_state *mrb, mrb_dir_handle *handle)
{ {
#if defined(__ANDROID__) #if defined(__ANDROID__)
/* Android doesn't have reliable telldir */ /* Android doesn't have reliable telldir */
@@ -103,35 +103,35 @@ mrb_dir_hal_tell(mrb_state *mrb, mrb_dir_handle *handle)
*/ */
int int
mrb_dir_hal_mkdir(mrb_state *mrb, const char *path, int mode) mrb_hal_dir_mkdir(mrb_state *mrb, const char *path, int mode)
{ {
(void)mrb; (void)mrb;
return mkdir(path, (mode_t)mode); return mkdir(path, (mode_t)mode);
} }
int int
mrb_dir_hal_rmdir(mrb_state *mrb, const char *path) mrb_hal_dir_rmdir(mrb_state *mrb, const char *path)
{ {
(void)mrb; (void)mrb;
return rmdir(path); return rmdir(path);
} }
int int
mrb_dir_hal_chdir(mrb_state *mrb, const char *path) mrb_hal_dir_chdir(mrb_state *mrb, const char *path)
{ {
(void)mrb; (void)mrb;
return chdir(path); return chdir(path);
} }
int int
mrb_dir_hal_getcwd(mrb_state *mrb, char *buf, size_t size) mrb_hal_dir_getcwd(mrb_state *mrb, char *buf, size_t size)
{ {
(void)mrb; (void)mrb;
return getcwd(buf, size) ? 0 : -1; return getcwd(buf, size) ? 0 : -1;
} }
int int
mrb_dir_hal_chroot(mrb_state *mrb, const char *path) mrb_hal_dir_chroot(mrb_state *mrb, const char *path)
{ {
#if defined(__ANDROID__) || defined(__MSDOS__) #if defined(__ANDROID__) || defined(__MSDOS__)
/* Not available on these platforms */ /* Not available on these platforms */
@@ -145,7 +145,7 @@ mrb_dir_hal_chroot(mrb_state *mrb, const char *path)
} }
int int
mrb_dir_hal_is_directory(mrb_state *mrb, const char *path) mrb_hal_dir_is_directory(mrb_state *mrb, const char *path)
{ {
struct stat sb; struct stat sb;
(void)mrb; (void)mrb;
@@ -161,14 +161,14 @@ mrb_dir_hal_is_directory(mrb_state *mrb, const char *path)
*/ */
void void
mrb_dir_hal_init(mrb_state *mrb) mrb_hal_dir_init(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* No initialization needed for POSIX */ /* No initialization needed for POSIX */
} }
void void
mrb_dir_hal_final(mrb_state *mrb) mrb_hal_dir_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* No cleanup needed for POSIX */ /* No cleanup needed for POSIX */
@@ -189,5 +189,5 @@ void
mrb_hal_posix_dir_gem_final(mrb_state *mrb) mrb_hal_posix_dir_gem_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup handled by mrb_dir_hal_final called from mruby-dir */ /* Cleanup handled by mrb_hal_dir_final called from mruby-dir */
} }
+35 -35
View File
@@ -80,7 +80,7 @@ convert_stat(const struct stat *src, mrb_io_stat *dst)
*/ */
int int
mrb_io_hal_stat(mrb_state *mrb, const char *path, mrb_io_stat *st) mrb_hal_io_stat(mrb_state *mrb, const char *path, mrb_io_stat *st)
{ {
struct stat s; struct stat s;
(void)mrb; (void)mrb;
@@ -93,7 +93,7 @@ mrb_io_hal_stat(mrb_state *mrb, const char *path, mrb_io_stat *st)
} }
int int
mrb_io_hal_fstat(mrb_state *mrb, int fd, mrb_io_stat *st) mrb_hal_io_fstat(mrb_state *mrb, int fd, mrb_io_stat *st)
{ {
struct stat s; struct stat s;
(void)mrb; (void)mrb;
@@ -106,7 +106,7 @@ mrb_io_hal_fstat(mrb_state *mrb, int fd, mrb_io_stat *st)
} }
int int
mrb_io_hal_lstat(mrb_state *mrb, const char *path, mrb_io_stat *st) mrb_hal_io_lstat(mrb_state *mrb, const char *path, mrb_io_stat *st)
{ {
struct stat s; struct stat s;
(void)mrb; (void)mrb;
@@ -119,14 +119,14 @@ mrb_io_hal_lstat(mrb_state *mrb, const char *path, mrb_io_stat *st)
} }
int int
mrb_io_hal_chmod(mrb_state *mrb, const char *path, uint32_t mode) mrb_hal_io_chmod(mrb_state *mrb, const char *path, uint32_t mode)
{ {
(void)mrb; (void)mrb;
return chmod(path, (mode_t)mode); return chmod(path, (mode_t)mode);
} }
uint32_t uint32_t
mrb_io_hal_umask(mrb_state *mrb, int32_t mask) mrb_hal_io_umask(mrb_state *mrb, int32_t mask)
{ {
mode_t old; mode_t old;
(void)mrb; (void)mrb;
@@ -143,14 +143,14 @@ mrb_io_hal_umask(mrb_state *mrb, int32_t mask)
} }
int int
mrb_io_hal_ftruncate(mrb_state *mrb, int fd, int64_t length) mrb_hal_io_ftruncate(mrb_state *mrb, int fd, int64_t length)
{ {
(void)mrb; (void)mrb;
return ftruncate(fd, (off_t)length); return ftruncate(fd, (off_t)length);
} }
int int
mrb_io_hal_flock(mrb_state *mrb, int fd, int operation) mrb_hal_io_flock(mrb_state *mrb, int fd, int operation)
{ {
(void)mrb; (void)mrb;
@@ -164,28 +164,28 @@ mrb_io_hal_flock(mrb_state *mrb, int fd, int operation)
} }
int int
mrb_io_hal_unlink(mrb_state *mrb, const char *path) mrb_hal_io_unlink(mrb_state *mrb, const char *path)
{ {
(void)mrb; (void)mrb;
return unlink(path); return unlink(path);
} }
int int
mrb_io_hal_rename(mrb_state *mrb, const char *oldpath, const char *newpath) mrb_hal_io_rename(mrb_state *mrb, const char *oldpath, const char *newpath)
{ {
(void)mrb; (void)mrb;
return rename(oldpath, newpath); return rename(oldpath, newpath);
} }
int int
mrb_io_hal_symlink(mrb_state *mrb, const char *target, const char *linkpath) mrb_hal_io_symlink(mrb_state *mrb, const char *target, const char *linkpath)
{ {
(void)mrb; (void)mrb;
return symlink(target, linkpath); return symlink(target, linkpath);
} }
int64_t int64_t
mrb_io_hal_readlink(mrb_state *mrb, const char *path, char *buf, size_t bufsize) mrb_hal_io_readlink(mrb_state *mrb, const char *path, char *buf, size_t bufsize)
{ {
ssize_t rc; ssize_t rc;
(void)mrb; (void)mrb;
@@ -195,28 +195,28 @@ mrb_io_hal_readlink(mrb_state *mrb, const char *path, char *buf, size_t bufsize)
} }
char* char*
mrb_io_hal_realpath(mrb_state *mrb, const char *path, char *resolved) mrb_hal_io_realpath(mrb_state *mrb, const char *path, char *resolved)
{ {
(void)mrb; (void)mrb;
return realpath(path, resolved); return realpath(path, resolved);
} }
char* char*
mrb_io_hal_getcwd(mrb_state *mrb, char *buf, size_t size) mrb_hal_io_getcwd(mrb_state *mrb, char *buf, size_t size)
{ {
(void)mrb; (void)mrb;
return getcwd(buf, size); return getcwd(buf, size);
} }
const char* const char*
mrb_io_hal_getenv(mrb_state *mrb, const char *name) mrb_hal_io_getenv(mrb_state *mrb, const char *name)
{ {
(void)mrb; (void)mrb;
return getenv(name); return getenv(name);
} }
const char* const char*
mrb_io_hal_gethome(mrb_state *mrb, const char *username) mrb_hal_io_gethome(mrb_state *mrb, const char *username)
{ {
const char *home; const char *home;
@@ -246,7 +246,7 @@ mrb_io_hal_gethome(mrb_state *mrb, const char *username)
*/ */
int int
mrb_io_hal_open(mrb_state *mrb, const char *path, int flags, uint32_t mode) mrb_hal_io_open(mrb_state *mrb, const char *path, int flags, uint32_t mode)
{ {
int fd; int fd;
(void)mrb; (void)mrb;
@@ -270,14 +270,14 @@ mrb_io_hal_open(mrb_state *mrb, const char *path, int flags, uint32_t mode)
} }
int int
mrb_io_hal_close(mrb_state *mrb, int fd) mrb_hal_io_close(mrb_state *mrb, int fd)
{ {
(void)mrb; (void)mrb;
return close(fd); return close(fd);
} }
int64_t int64_t
mrb_io_hal_read(mrb_state *mrb, int fd, void *buf, size_t count) mrb_hal_io_read(mrb_state *mrb, int fd, void *buf, size_t count)
{ {
ssize_t n; ssize_t n;
(void)mrb; (void)mrb;
@@ -287,7 +287,7 @@ mrb_io_hal_read(mrb_state *mrb, int fd, void *buf, size_t count)
} }
int64_t int64_t
mrb_io_hal_write(mrb_state *mrb, int fd, const void *buf, size_t count) mrb_hal_io_write(mrb_state *mrb, int fd, const void *buf, size_t count)
{ {
ssize_t n; ssize_t n;
(void)mrb; (void)mrb;
@@ -297,7 +297,7 @@ mrb_io_hal_write(mrb_state *mrb, int fd, const void *buf, size_t count)
} }
int64_t int64_t
mrb_io_hal_lseek(mrb_state *mrb, int fd, int64_t offset, int whence) mrb_hal_io_lseek(mrb_state *mrb, int fd, int64_t offset, int whence)
{ {
off_t pos; off_t pos;
int posix_whence; int posix_whence;
@@ -318,7 +318,7 @@ mrb_io_hal_lseek(mrb_state *mrb, int fd, int64_t offset, int whence)
} }
int int
mrb_io_hal_dup(mrb_state *mrb, int fd) mrb_hal_io_dup(mrb_state *mrb, int fd)
{ {
int new_fd; int new_fd;
(void)mrb; (void)mrb;
@@ -342,21 +342,21 @@ mrb_io_hal_dup(mrb_state *mrb, int fd)
} }
int int
mrb_io_hal_fcntl(mrb_state *mrb, int fd, int cmd, int arg) mrb_hal_io_fcntl(mrb_state *mrb, int fd, int cmd, int arg)
{ {
(void)mrb; (void)mrb;
return fcntl(fd, cmd, arg); return fcntl(fd, cmd, arg);
} }
int int
mrb_io_hal_isatty(mrb_state *mrb, int fd) mrb_hal_io_isatty(mrb_state *mrb, int fd)
{ {
(void)mrb; (void)mrb;
return isatty(fd) ? 1 : 0; return isatty(fd) ? 1 : 0;
} }
int int
mrb_io_hal_pipe(mrb_state *mrb, int fds[2]) mrb_hal_io_pipe(mrb_state *mrb, int fds[2])
{ {
int ret; int ret;
(void)mrb; (void)mrb;
@@ -384,7 +384,7 @@ mrb_io_hal_pipe(mrb_state *mrb, int fds[2])
*/ */
int int
mrb_io_hal_spawn_process(mrb_state *mrb, const char *cmd, mrb_hal_io_spawn_process(mrb_state *mrb, const char *cmd,
int stdin_fd, int stdout_fd, int stderr_fd, int stdin_fd, int stdout_fd, int stderr_fd,
int *pid) int *pid)
{ {
@@ -448,7 +448,7 @@ mrb_io_hal_spawn_process(mrb_state *mrb, const char *cmd,
} }
int int
mrb_io_hal_waitpid(mrb_state *mrb, int pid, int *status, int options) mrb_hal_io_waitpid(mrb_state *mrb, int pid, int *status, int options)
{ {
pid_t result; pid_t result;
int stat; int stat;
@@ -475,7 +475,7 @@ struct mrb_io_fdset {
}; };
mrb_io_fdset* mrb_io_fdset*
mrb_io_hal_fdset_alloc(mrb_state *mrb) mrb_hal_io_fdset_alloc(mrb_state *mrb)
{ {
mrb_io_fdset *fdset = (mrb_io_fdset*)mrb_malloc(mrb, sizeof(mrb_io_fdset)); mrb_io_fdset *fdset = (mrb_io_fdset*)mrb_malloc(mrb, sizeof(mrb_io_fdset));
FD_ZERO(&fdset->fds); FD_ZERO(&fdset->fds);
@@ -483,7 +483,7 @@ mrb_io_hal_fdset_alloc(mrb_state *mrb)
} }
void void
mrb_io_hal_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset) mrb_hal_io_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset)
{ {
if (fdset) { if (fdset) {
mrb_free(mrb, fdset); mrb_free(mrb, fdset);
@@ -491,7 +491,7 @@ mrb_io_hal_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset)
} }
void void
mrb_io_hal_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset) mrb_hal_io_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset)
{ {
(void)mrb; (void)mrb;
if (fdset) { if (fdset) {
@@ -500,7 +500,7 @@ mrb_io_hal_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset)
} }
void void
mrb_io_hal_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset) mrb_hal_io_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
{ {
(void)mrb; (void)mrb;
if (fdset) { if (fdset) {
@@ -509,7 +509,7 @@ mrb_io_hal_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
} }
int int
mrb_io_hal_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset) mrb_hal_io_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
{ {
(void)mrb; (void)mrb;
if (fdset) { if (fdset) {
@@ -519,7 +519,7 @@ mrb_io_hal_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
} }
int int
mrb_io_hal_select(mrb_state *mrb, int nfds, mrb_hal_io_select(mrb_state *mrb, int nfds,
mrb_io_fdset *readfds, mrb_io_fdset *readfds,
mrb_io_fdset *writefds, mrb_io_fdset *writefds,
mrb_io_fdset *errorfds, mrb_io_fdset *errorfds,
@@ -546,14 +546,14 @@ mrb_io_hal_select(mrb_state *mrb, int nfds,
*/ */
void void
mrb_io_hal_init(mrb_state *mrb) mrb_hal_io_init(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* No special initialization needed for POSIX */ /* No special initialization needed for POSIX */
} }
void void
mrb_io_hal_final(mrb_state *mrb) mrb_hal_io_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* No special cleanup needed for POSIX */ /* No special cleanup needed for POSIX */
@@ -574,5 +574,5 @@ void
mrb_hal_posix_io_gem_final(mrb_state *mrb) mrb_hal_posix_io_gem_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup handled by mrb_io_hal_final called from mruby-io */ /* Cleanup handled by mrb_hal_io_final called from mruby-io */
} }
+9 -9
View File
@@ -29,14 +29,14 @@
*/ */
void void
mrb_socket_hal_init(mrb_state *mrb) mrb_hal_socket_init(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* No initialization needed for POSIX sockets */ /* No initialization needed for POSIX sockets */
} }
void void
mrb_socket_hal_final(mrb_state *mrb) mrb_hal_socket_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* No cleanup needed for POSIX sockets */ /* No cleanup needed for POSIX sockets */
@@ -47,7 +47,7 @@ mrb_socket_hal_final(mrb_state *mrb)
*/ */
int int
mrb_socket_hal_set_nonblock(mrb_state *mrb, int fd, int nonblock) mrb_hal_socket_set_nonblock(mrb_state *mrb, int fd, int nonblock)
{ {
(void)mrb; (void)mrb;
@@ -75,13 +75,13 @@ mrb_socket_hal_set_nonblock(mrb_state *mrb, int fd, int nonblock)
*/ */
const char* const char*
mrb_socket_hal_inet_ntop(int af, const void *src, char *dst, size_t size) mrb_hal_socket_inet_ntop(int af, const void *src, char *dst, size_t size)
{ {
return inet_ntop(af, src, dst, (socklen_t)size); return inet_ntop(af, src, dst, (socklen_t)size);
} }
int int
mrb_socket_hal_inet_pton(int af, const char *src, void *dst) mrb_hal_socket_inet_pton(int af, const char *src, void *dst)
{ {
return inet_pton(af, src, dst); return inet_pton(af, src, dst);
} }
@@ -91,7 +91,7 @@ mrb_socket_hal_inet_pton(int af, const char *src, void *dst)
*/ */
mrb_value mrb_value
mrb_socket_hal_sockaddr_un(mrb_state *mrb, const char *path, size_t pathlen) mrb_hal_socket_sockaddr_un(mrb_state *mrb, const char *path, size_t pathlen)
{ {
struct sockaddr_un *sunp; struct sockaddr_un *sunp;
@@ -117,14 +117,14 @@ mrb_socket_hal_sockaddr_un(mrb_state *mrb, const char *path, size_t pathlen)
} }
int int
mrb_socket_hal_socketpair(mrb_state *mrb, int domain, int type, int protocol, int sv[2]) mrb_hal_socket_socketpair(mrb_state *mrb, int domain, int type, int protocol, int sv[2])
{ {
(void)mrb; (void)mrb;
return socketpair(domain, type, protocol, sv); return socketpair(domain, type, protocol, sv);
} }
mrb_value mrb_value
mrb_socket_hal_unix_path(mrb_state *mrb, const char *sockaddr, size_t socklen) mrb_hal_socket_unix_path(mrb_state *mrb, const char *sockaddr, size_t socklen)
{ {
const struct sockaddr *sa = (const struct sockaddr*)sockaddr; const struct sockaddr *sa = (const struct sockaddr*)sockaddr;
@@ -154,5 +154,5 @@ void
mrb_hal_posix_socket_gem_final(mrb_state *mrb) mrb_hal_posix_socket_gem_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup handled by mrb_socket_hal_final called from mruby-socket */ /* Cleanup handled by mrb_hal_socket_final called from mruby-socket */
} }
+5 -5
View File
@@ -46,7 +46,7 @@ sigalrm_handler(int sig)
*/ */
void void
mrb_task_hal_init(mrb_state *mrb) mrb_hal_task_init(mrb_state *mrb)
{ {
struct sigaction sa; struct sigaction sa;
struct itimerval timer; struct itimerval timer;
@@ -119,7 +119,7 @@ mrb_task_disable_irq(void)
} }
void void
mrb_task_hal_idle_cpu(mrb_state *mrb) mrb_hal_task_idle_cpu(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* On POSIX, just pause briefly */ /* On POSIX, just pause briefly */
@@ -127,7 +127,7 @@ mrb_task_hal_idle_cpu(mrb_state *mrb)
} }
void void
mrb_task_hal_sleep_us(mrb_state *mrb, mrb_int usec) mrb_hal_task_sleep_us(mrb_state *mrb, mrb_int usec)
{ {
struct timespec start, now, sleep_time; struct timespec start, now, sleep_time;
int ret; int ret;
@@ -178,7 +178,7 @@ mrb_task_hal_sleep_us(mrb_state *mrb, mrb_int usec)
} }
void void
mrb_task_hal_final(mrb_state *mrb) mrb_hal_task_final(mrb_state *mrb)
{ {
struct itimerval timer; struct itimerval timer;
int i, j; int i, j;
@@ -227,5 +227,5 @@ void
mrb_hal_posix_task_gem_final(mrb_state *mrb) mrb_hal_posix_task_gem_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup handled by mrb_task_hal_final called from mruby-task */ /* Cleanup handled by mrb_hal_task_final called from mruby-task */
} }
+15 -15
View File
@@ -36,7 +36,7 @@ struct mrb_dir_handle {
*/ */
mrb_dir_handle* mrb_dir_handle*
mrb_dir_hal_open(mrb_state *mrb, const char *path) mrb_hal_dir_open(mrb_state *mrb, const char *path)
{ {
mrb_dir_handle *handle; mrb_dir_handle *handle;
size_t len = strlen(path); size_t len = strlen(path);
@@ -62,7 +62,7 @@ mrb_dir_hal_open(mrb_state *mrb, const char *path)
} }
int int
mrb_dir_hal_close(mrb_state *mrb, mrb_dir_handle *handle) mrb_hal_dir_close(mrb_state *mrb, mrb_dir_handle *handle)
{ {
int result = -1; int result = -1;
@@ -82,7 +82,7 @@ mrb_dir_hal_close(mrb_state *mrb, mrb_dir_handle *handle)
} }
const char* const char*
mrb_dir_hal_read(mrb_state *mrb, mrb_dir_handle *handle) mrb_hal_dir_read(mrb_state *mrb, mrb_dir_handle *handle)
{ {
(void)mrb; (void)mrb;
@@ -106,7 +106,7 @@ mrb_dir_hal_read(mrb_state *mrb, mrb_dir_handle *handle)
} }
void void
mrb_dir_hal_rewind(mrb_state *mrb, mrb_dir_handle *handle) mrb_hal_dir_rewind(mrb_state *mrb, mrb_dir_handle *handle)
{ {
(void)mrb; (void)mrb;
@@ -126,7 +126,7 @@ mrb_dir_hal_rewind(mrb_state *mrb, mrb_dir_handle *handle)
*/ */
int int
mrb_dir_hal_seek(mrb_state *mrb, mrb_dir_handle *handle, long pos) mrb_hal_dir_seek(mrb_state *mrb, mrb_dir_handle *handle, long pos)
{ {
/* Not supported on Windows */ /* Not supported on Windows */
(void)mrb; (void)handle; (void)pos; (void)mrb; (void)handle; (void)pos;
@@ -135,7 +135,7 @@ mrb_dir_hal_seek(mrb_state *mrb, mrb_dir_handle *handle, long pos)
} }
long long
mrb_dir_hal_tell(mrb_state *mrb, mrb_dir_handle *handle) mrb_hal_dir_tell(mrb_state *mrb, mrb_dir_handle *handle)
{ {
/* Not supported on Windows */ /* Not supported on Windows */
(void)mrb; (void)handle; (void)mrb; (void)handle;
@@ -148,7 +148,7 @@ mrb_dir_hal_tell(mrb_state *mrb, mrb_dir_handle *handle)
*/ */
int int
mrb_dir_hal_mkdir(mrb_state *mrb, const char *path, int mode) mrb_hal_dir_mkdir(mrb_state *mrb, const char *path, int mode)
{ {
/* Windows _mkdir ignores mode parameter */ /* Windows _mkdir ignores mode parameter */
(void)mrb; (void)mode; (void)mrb; (void)mode;
@@ -156,28 +156,28 @@ mrb_dir_hal_mkdir(mrb_state *mrb, const char *path, int mode)
} }
int int
mrb_dir_hal_rmdir(mrb_state *mrb, const char *path) mrb_hal_dir_rmdir(mrb_state *mrb, const char *path)
{ {
(void)mrb; (void)mrb;
return _rmdir(path); return _rmdir(path);
} }
int int
mrb_dir_hal_chdir(mrb_state *mrb, const char *path) mrb_hal_dir_chdir(mrb_state *mrb, const char *path)
{ {
(void)mrb; (void)mrb;
return _chdir(path); return _chdir(path);
} }
int int
mrb_dir_hal_getcwd(mrb_state *mrb, char *buf, size_t size) mrb_hal_dir_getcwd(mrb_state *mrb, char *buf, size_t size)
{ {
(void)mrb; (void)mrb;
return _getcwd(buf, (int)size) ? 0 : -1; return _getcwd(buf, (int)size) ? 0 : -1;
} }
int int
mrb_dir_hal_chroot(mrb_state *mrb, const char *path) mrb_hal_dir_chroot(mrb_state *mrb, const char *path)
{ {
/* Not available on Windows */ /* Not available on Windows */
(void)mrb; (void)path; (void)mrb; (void)path;
@@ -186,7 +186,7 @@ mrb_dir_hal_chroot(mrb_state *mrb, const char *path)
} }
int int
mrb_dir_hal_is_directory(mrb_state *mrb, const char *path) mrb_hal_dir_is_directory(mrb_state *mrb, const char *path)
{ {
struct _stat sb; struct _stat sb;
(void)mrb; (void)mrb;
@@ -202,14 +202,14 @@ mrb_dir_hal_is_directory(mrb_state *mrb, const char *path)
*/ */
void void
mrb_dir_hal_init(mrb_state *mrb) mrb_hal_dir_init(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* No initialization needed for Windows */ /* No initialization needed for Windows */
} }
void void
mrb_dir_hal_final(mrb_state *mrb) mrb_hal_dir_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* No cleanup needed for Windows */ /* No cleanup needed for Windows */
@@ -230,7 +230,7 @@ void
mrb_hal_win_dir_gem_final(mrb_state *mrb) mrb_hal_win_dir_gem_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup handled by mrb_dir_hal_final called from mruby-dir */ /* Cleanup handled by mrb_hal_dir_final called from mruby-dir */
} }
/* /*
+36 -36
View File
@@ -79,7 +79,7 @@ set_errno_from_win_error(DWORD error)
*/ */
int int
mrb_io_hal_stat(mrb_state *mrb, const char *path, mrb_io_stat *st) mrb_hal_io_stat(mrb_state *mrb, const char *path, mrb_io_stat *st)
{ {
struct _stat64 s; struct _stat64 s;
(void)mrb; (void)mrb;
@@ -92,7 +92,7 @@ mrb_io_hal_stat(mrb_state *mrb, const char *path, mrb_io_stat *st)
} }
int int
mrb_io_hal_fstat(mrb_state *mrb, int fd, mrb_io_stat *st) mrb_hal_io_fstat(mrb_state *mrb, int fd, mrb_io_stat *st)
{ {
struct _stat64 s; struct _stat64 s;
(void)mrb; (void)mrb;
@@ -105,21 +105,21 @@ mrb_io_hal_fstat(mrb_state *mrb, int fd, mrb_io_stat *st)
} }
int int
mrb_io_hal_lstat(mrb_state *mrb, const char *path, mrb_io_stat *st) mrb_hal_io_lstat(mrb_state *mrb, const char *path, mrb_io_stat *st)
{ {
/* Windows doesn't distinguish lstat from stat */ /* Windows doesn't distinguish lstat from stat */
return mrb_io_hal_stat(mrb, path, st); return mrb_hal_io_stat(mrb, path, st);
} }
int int
mrb_io_hal_chmod(mrb_state *mrb, const char *path, uint32_t mode) mrb_hal_io_chmod(mrb_state *mrb, const char *path, uint32_t mode)
{ {
(void)mrb; (void)mrb;
return _chmod(path, (int)mode); return _chmod(path, (int)mode);
} }
uint32_t uint32_t
mrb_io_hal_umask(mrb_state *mrb, int32_t mask) mrb_hal_io_umask(mrb_state *mrb, int32_t mask)
{ {
int old; int old;
(void)mrb; (void)mrb;
@@ -136,14 +136,14 @@ mrb_io_hal_umask(mrb_state *mrb, int32_t mask)
} }
int int
mrb_io_hal_ftruncate(mrb_state *mrb, int fd, int64_t length) mrb_hal_io_ftruncate(mrb_state *mrb, int fd, int64_t length)
{ {
(void)mrb; (void)mrb;
return _chsize_s(fd, length); return _chsize_s(fd, length);
} }
int int
mrb_io_hal_flock(mrb_state *mrb, int fd, int operation) mrb_hal_io_flock(mrb_state *mrb, int fd, int operation)
{ {
HANDLE h; HANDLE h;
OVERLAPPED overlapped; OVERLAPPED overlapped;
@@ -182,21 +182,21 @@ mrb_io_hal_flock(mrb_state *mrb, int fd, int operation)
} }
int int
mrb_io_hal_unlink(mrb_state *mrb, const char *path) mrb_hal_io_unlink(mrb_state *mrb, const char *path)
{ {
(void)mrb; (void)mrb;
return _unlink(path); return _unlink(path);
} }
int int
mrb_io_hal_rename(mrb_state *mrb, const char *oldpath, const char *newpath) mrb_hal_io_rename(mrb_state *mrb, const char *oldpath, const char *newpath)
{ {
(void)mrb; (void)mrb;
return rename(oldpath, newpath); return rename(oldpath, newpath);
} }
int int
mrb_io_hal_symlink(mrb_state *mrb, const char *target, const char *linkpath) mrb_hal_io_symlink(mrb_state *mrb, const char *target, const char *linkpath)
{ {
DWORD flags = 0; DWORD flags = 0;
(void)mrb; (void)mrb;
@@ -215,7 +215,7 @@ mrb_io_hal_symlink(mrb_state *mrb, const char *target, const char *linkpath)
} }
int64_t int64_t
mrb_io_hal_readlink(mrb_state *mrb, const char *path, char *buf, size_t bufsize) mrb_hal_io_readlink(mrb_state *mrb, const char *path, char *buf, size_t bufsize)
{ {
HANDLE h; HANDLE h;
DWORD ret; DWORD ret;
@@ -252,7 +252,7 @@ mrb_io_hal_readlink(mrb_state *mrb, const char *path, char *buf, size_t bufsize)
} }
char* char*
mrb_io_hal_realpath(mrb_state *mrb, const char *path, char *resolved) mrb_hal_io_realpath(mrb_state *mrb, const char *path, char *resolved)
{ {
DWORD ret; DWORD ret;
(void)mrb; (void)mrb;
@@ -266,21 +266,21 @@ mrb_io_hal_realpath(mrb_state *mrb, const char *path, char *resolved)
} }
char* char*
mrb_io_hal_getcwd(mrb_state *mrb, char *buf, size_t size) mrb_hal_io_getcwd(mrb_state *mrb, char *buf, size_t size)
{ {
(void)mrb; (void)mrb;
return _getcwd(buf, (int)size); return _getcwd(buf, (int)size);
} }
const char* const char*
mrb_io_hal_getenv(mrb_state *mrb, const char *name) mrb_hal_io_getenv(mrb_state *mrb, const char *name)
{ {
(void)mrb; (void)mrb;
return getenv(name); return getenv(name);
} }
const char* const char*
mrb_io_hal_gethome(mrb_state *mrb, const char *username) mrb_hal_io_gethome(mrb_state *mrb, const char *username)
{ {
const char *home; const char *home;
(void)mrb; (void)mrb;
@@ -313,7 +313,7 @@ mrb_io_hal_gethome(mrb_state *mrb, const char *username)
*/ */
int int
mrb_io_hal_open(mrb_state *mrb, const char *path, int flags, uint32_t mode) mrb_hal_io_open(mrb_state *mrb, const char *path, int flags, uint32_t mode)
{ {
int fd; int fd;
(void)mrb; (void)mrb;
@@ -333,14 +333,14 @@ mrb_io_hal_open(mrb_state *mrb, const char *path, int flags, uint32_t mode)
} }
int int
mrb_io_hal_close(mrb_state *mrb, int fd) mrb_hal_io_close(mrb_state *mrb, int fd)
{ {
(void)mrb; (void)mrb;
return _close(fd); return _close(fd);
} }
int64_t int64_t
mrb_io_hal_read(mrb_state *mrb, int fd, void *buf, size_t count) mrb_hal_io_read(mrb_state *mrb, int fd, void *buf, size_t count)
{ {
int n; int n;
(void)mrb; (void)mrb;
@@ -350,7 +350,7 @@ mrb_io_hal_read(mrb_state *mrb, int fd, void *buf, size_t count)
} }
int64_t int64_t
mrb_io_hal_write(mrb_state *mrb, int fd, const void *buf, size_t count) mrb_hal_io_write(mrb_state *mrb, int fd, const void *buf, size_t count)
{ {
int n; int n;
(void)mrb; (void)mrb;
@@ -360,7 +360,7 @@ mrb_io_hal_write(mrb_state *mrb, int fd, const void *buf, size_t count)
} }
int64_t int64_t
mrb_io_hal_lseek(mrb_state *mrb, int fd, int64_t offset, int whence) mrb_hal_io_lseek(mrb_state *mrb, int fd, int64_t offset, int whence)
{ {
__int64 pos; __int64 pos;
int win_whence; int win_whence;
@@ -381,7 +381,7 @@ mrb_io_hal_lseek(mrb_state *mrb, int fd, int64_t offset, int whence)
} }
int int
mrb_io_hal_dup(mrb_state *mrb, int fd) mrb_hal_io_dup(mrb_state *mrb, int fd)
{ {
int new_fd; int new_fd;
(void)mrb; (void)mrb;
@@ -400,7 +400,7 @@ mrb_io_hal_dup(mrb_state *mrb, int fd)
} }
int int
mrb_io_hal_fcntl(mrb_state *mrb, int fd, int cmd, int arg) mrb_hal_io_fcntl(mrb_state *mrb, int fd, int cmd, int arg)
{ {
/* Windows has limited fcntl support */ /* Windows has limited fcntl support */
(void)mrb; (void)mrb;
@@ -412,14 +412,14 @@ mrb_io_hal_fcntl(mrb_state *mrb, int fd, int cmd, int arg)
} }
int int
mrb_io_hal_isatty(mrb_state *mrb, int fd) mrb_hal_io_isatty(mrb_state *mrb, int fd)
{ {
(void)mrb; (void)mrb;
return _isatty(fd) ? 1 : 0; return _isatty(fd) ? 1 : 0;
} }
int int
mrb_io_hal_pipe(mrb_state *mrb, int fds[2]) mrb_hal_io_pipe(mrb_state *mrb, int fds[2])
{ {
int ret; int ret;
(void)mrb; (void)mrb;
@@ -441,7 +441,7 @@ mrb_io_hal_pipe(mrb_state *mrb, int fds[2])
*/ */
int int
mrb_io_hal_spawn_process(mrb_state *mrb, const char *cmd, mrb_hal_io_spawn_process(mrb_state *mrb, const char *cmd,
int stdin_fd, int stdout_fd, int stderr_fd, int stdin_fd, int stdout_fd, int stderr_fd,
int *pid) int *pid)
{ {
@@ -516,7 +516,7 @@ mrb_io_hal_spawn_process(mrb_state *mrb, const char *cmd,
} }
int int
mrb_io_hal_waitpid(mrb_state *mrb, int pid, int *status, int options) mrb_hal_io_waitpid(mrb_state *mrb, int pid, int *status, int options)
{ {
HANDLE h = (HANDLE)pid; HANDLE h = (HANDLE)pid;
DWORD wait_result; DWORD wait_result;
@@ -564,7 +564,7 @@ struct mrb_io_fdset {
}; };
mrb_io_fdset* mrb_io_fdset*
mrb_io_hal_fdset_alloc(mrb_state *mrb) mrb_hal_io_fdset_alloc(mrb_state *mrb)
{ {
mrb_io_fdset *fdset = (mrb_io_fdset*)mrb_malloc(mrb, sizeof(mrb_io_fdset)); mrb_io_fdset *fdset = (mrb_io_fdset*)mrb_malloc(mrb, sizeof(mrb_io_fdset));
FD_ZERO(&fdset->fds); FD_ZERO(&fdset->fds);
@@ -572,7 +572,7 @@ mrb_io_hal_fdset_alloc(mrb_state *mrb)
} }
void void
mrb_io_hal_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset) mrb_hal_io_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset)
{ {
if (fdset) { if (fdset) {
mrb_free(mrb, fdset); mrb_free(mrb, fdset);
@@ -580,7 +580,7 @@ mrb_io_hal_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset)
} }
void void
mrb_io_hal_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset) mrb_hal_io_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset)
{ {
(void)mrb; (void)mrb;
if (fdset) { if (fdset) {
@@ -589,7 +589,7 @@ mrb_io_hal_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset)
} }
void void
mrb_io_hal_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset) mrb_hal_io_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
{ {
(void)mrb; (void)mrb;
if (fdset) { if (fdset) {
@@ -598,7 +598,7 @@ mrb_io_hal_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
} }
int int
mrb_io_hal_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset) mrb_hal_io_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
{ {
(void)mrb; (void)mrb;
if (fdset) { if (fdset) {
@@ -608,7 +608,7 @@ mrb_io_hal_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset)
} }
int int
mrb_io_hal_select(mrb_state *mrb, int nfds, mrb_hal_io_select(mrb_state *mrb, int nfds,
mrb_io_fdset *readfds, mrb_io_fdset *readfds,
mrb_io_fdset *writefds, mrb_io_fdset *writefds,
mrb_io_fdset *errorfds, mrb_io_fdset *errorfds,
@@ -636,7 +636,7 @@ mrb_io_hal_select(mrb_state *mrb, int nfds,
*/ */
void void
mrb_io_hal_init(mrb_state *mrb) mrb_hal_io_init(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Initialize Winsock for select() support */ /* Initialize Winsock for select() support */
@@ -645,7 +645,7 @@ mrb_io_hal_init(mrb_state *mrb)
} }
void void
mrb_io_hal_final(mrb_state *mrb) mrb_hal_io_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup Winsock */ /* Cleanup Winsock */
@@ -667,5 +667,5 @@ void
mrb_hal_win_io_gem_final(mrb_state *mrb) mrb_hal_win_io_gem_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup handled by mrb_io_hal_final called from mruby-io */ /* Cleanup handled by mrb_hal_io_final called from mruby-io */
} }
+9 -9
View File
@@ -25,7 +25,7 @@
*/ */
void void
mrb_socket_hal_init(mrb_state *mrb) mrb_hal_socket_init(mrb_state *mrb)
{ {
WSADATA wsaData; WSADATA wsaData;
int result = WSAStartup(MAKEWORD(2, 2), &wsaData); int result = WSAStartup(MAKEWORD(2, 2), &wsaData);
@@ -35,7 +35,7 @@ mrb_socket_hal_init(mrb_state *mrb)
} }
void void
mrb_socket_hal_final(mrb_state *mrb) mrb_hal_socket_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
WSACleanup(); WSACleanup();
@@ -46,7 +46,7 @@ mrb_socket_hal_final(mrb_state *mrb)
*/ */
int int
mrb_socket_hal_set_nonblock(mrb_state *mrb, int fd, int nonblock) mrb_hal_socket_set_nonblock(mrb_state *mrb, int fd, int nonblock)
{ {
(void)mrb; (void)mrb;
u_long mode = nonblock ? 1 : 0; u_long mode = nonblock ? 1 : 0;
@@ -62,7 +62,7 @@ mrb_socket_hal_set_nonblock(mrb_state *mrb, int fd, int nonblock)
*/ */
const char* const char*
mrb_socket_hal_inet_ntop(int af, const void *src, char *dst, size_t size) mrb_hal_socket_inet_ntop(int af, const void *src, char *dst, size_t size)
{ {
if (af == AF_INET) { if (af == AF_INET) {
struct sockaddr_in in = {0}; struct sockaddr_in in = {0};
@@ -88,7 +88,7 @@ mrb_socket_hal_inet_ntop(int af, const void *src, char *dst, size_t size)
} }
int int
mrb_socket_hal_inet_pton(int af, const char *src, void *dst) mrb_hal_socket_inet_pton(int af, const char *src, void *dst)
{ {
struct addrinfo hints = {0}; struct addrinfo hints = {0};
hints.ai_family = af; hints.ai_family = af;
@@ -123,7 +123,7 @@ mrb_socket_hal_inet_pton(int af, const char *src, void *dst)
*/ */
mrb_value mrb_value
mrb_socket_hal_sockaddr_un(mrb_state *mrb, const char *path, size_t pathlen) mrb_hal_socket_sockaddr_un(mrb_state *mrb, const char *path, size_t pathlen)
{ {
(void)path; (void)path;
(void)pathlen; (void)pathlen;
@@ -133,7 +133,7 @@ mrb_socket_hal_sockaddr_un(mrb_state *mrb, const char *path, size_t pathlen)
} }
int int
mrb_socket_hal_socketpair(mrb_state *mrb, int domain, int type, int protocol, int sv[2]) mrb_hal_socket_socketpair(mrb_state *mrb, int domain, int type, int protocol, int sv[2])
{ {
(void)mrb; (void)mrb;
(void)domain; (void)domain;
@@ -146,7 +146,7 @@ mrb_socket_hal_socketpair(mrb_state *mrb, int domain, int type, int protocol, in
} }
mrb_value mrb_value
mrb_socket_hal_unix_path(mrb_state *mrb, const char *sockaddr, size_t socklen) mrb_hal_socket_unix_path(mrb_state *mrb, const char *sockaddr, size_t socklen)
{ {
(void)sockaddr; (void)sockaddr;
(void)socklen; (void)socklen;
@@ -170,5 +170,5 @@ void
mrb_hal_win_socket_gem_final(mrb_state *mrb) mrb_hal_win_socket_gem_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup handled by mrb_socket_hal_final called from mruby-socket */ /* Cleanup handled by mrb_hal_socket_final called from mruby-socket */
} }
+5 -5
View File
@@ -43,7 +43,7 @@ timer_callback(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR d
*/ */
void void
mrb_task_hal_init(mrb_state *mrb) mrb_hal_task_init(mrb_state *mrb)
{ {
int i; int i;
LONG idx; LONG idx;
@@ -115,7 +115,7 @@ mrb_task_disable_irq(void)
} }
void void
mrb_task_hal_idle_cpu(mrb_state *mrb) mrb_hal_task_idle_cpu(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* On Windows, just sleep briefly */ /* On Windows, just sleep briefly */
@@ -123,7 +123,7 @@ mrb_task_hal_idle_cpu(mrb_state *mrb)
} }
void void
mrb_task_hal_sleep_us(mrb_state *mrb, mrb_int usec) mrb_hal_task_sleep_us(mrb_state *mrb, mrb_int usec)
{ {
(void)mrb; (void)mrb;
@@ -134,7 +134,7 @@ mrb_task_hal_sleep_us(mrb_state *mrb, mrb_int usec)
} }
void void
mrb_task_hal_final(mrb_state *mrb) mrb_hal_task_final(mrb_state *mrb)
{ {
int i, j; int i, j;
@@ -183,5 +183,5 @@ void
mrb_hal_win_task_gem_final(mrb_state *mrb) mrb_hal_win_task_gem_final(mrb_state *mrb)
{ {
(void)mrb; (void)mrb;
/* Cleanup handled by mrb_task_hal_final called from mruby-task */ /* Cleanup handled by mrb_hal_task_final called from mruby-task */
} }
+14 -14
View File
@@ -23,57 +23,57 @@ typedef struct mrb_dir_handle mrb_dir_handle;
*/ */
/* Open directory for reading. Returns handle or NULL on error (sets errno). */ /* Open directory for reading. Returns handle or NULL on error (sets errno). */
mrb_dir_handle* mrb_dir_hal_open(mrb_state *mrb, const char *path); mrb_dir_handle* mrb_hal_dir_open(mrb_state *mrb, const char *path);
/* Close directory handle. Returns 0 on success, -1 on error. */ /* Close directory handle. Returns 0 on success, -1 on error. */
int mrb_dir_hal_close(mrb_state *mrb, mrb_dir_handle *dir); int mrb_hal_dir_close(mrb_state *mrb, mrb_dir_handle *dir);
/* Read next entry from directory. Returns name or NULL at end/error. */ /* Read next entry from directory. Returns name or NULL at end/error. */
const char* mrb_dir_hal_read(mrb_state *mrb, mrb_dir_handle *dir); const char* mrb_hal_dir_read(mrb_state *mrb, mrb_dir_handle *dir);
/* Rewind directory to beginning */ /* Rewind directory to beginning */
void mrb_dir_hal_rewind(mrb_state *mrb, mrb_dir_handle *dir); void mrb_hal_dir_rewind(mrb_state *mrb, mrb_dir_handle *dir);
/* /*
* Optional Operations (may not be available on all platforms) * Optional Operations (may not be available on all platforms)
*/ */
/* Seek to position in directory. Returns -1 if unsupported (sets errno to ENOSYS). */ /* Seek to position in directory. Returns -1 if unsupported (sets errno to ENOSYS). */
int mrb_dir_hal_seek(mrb_state *mrb, mrb_dir_handle *dir, long pos); int mrb_hal_dir_seek(mrb_state *mrb, mrb_dir_handle *dir, long pos);
/* Get current position in directory. Returns -1 if unsupported (sets errno to ENOSYS). */ /* Get current position in directory. Returns -1 if unsupported (sets errno to ENOSYS). */
long mrb_dir_hal_tell(mrb_state *mrb, mrb_dir_handle *dir); long mrb_hal_dir_tell(mrb_state *mrb, mrb_dir_handle *dir);
/* /*
* Filesystem Operations * Filesystem Operations
*/ */
/* Create directory with mode (mode may be ignored on some platforms). Returns 0 on success, -1 on error. */ /* Create directory with mode (mode may be ignored on some platforms). Returns 0 on success, -1 on error. */
int mrb_dir_hal_mkdir(mrb_state *mrb, const char *path, int mode); int mrb_hal_dir_mkdir(mrb_state *mrb, const char *path, int mode);
/* Remove empty directory. Returns 0 on success, -1 on error. */ /* Remove empty directory. Returns 0 on success, -1 on error. */
int mrb_dir_hal_rmdir(mrb_state *mrb, const char *path); int mrb_hal_dir_rmdir(mrb_state *mrb, const char *path);
/* Change current working directory. Returns 0 on success, -1 on error. */ /* Change current working directory. Returns 0 on success, -1 on error. */
int mrb_dir_hal_chdir(mrb_state *mrb, const char *path); int mrb_hal_dir_chdir(mrb_state *mrb, const char *path);
/* Get current working directory. Returns 0 on success, -1 on error. */ /* Get current working directory. Returns 0 on success, -1 on error. */
int mrb_dir_hal_getcwd(mrb_state *mrb, char *buf, size_t size); int mrb_hal_dir_getcwd(mrb_state *mrb, char *buf, size_t size);
/* Change root directory (privileged operation). Returns -1 if unsupported (sets errno to ENOSYS). */ /* Change root directory (privileged operation). Returns -1 if unsupported (sets errno to ENOSYS). */
int mrb_dir_hal_chroot(mrb_state *mrb, const char *path); int mrb_hal_dir_chroot(mrb_state *mrb, const char *path);
/* Check if path is a directory. Returns 1 if directory, 0 if not. */ /* Check if path is a directory. Returns 1 if directory, 0 if not. */
int mrb_dir_hal_is_directory(mrb_state *mrb, const char *path); int mrb_hal_dir_is_directory(mrb_state *mrb, const char *path);
/* /*
* HAL Initialization/Finalization * HAL Initialization/Finalization
*/ */
/* Initialize HAL (called once at gem initialization) */ /* Initialize HAL (called once at gem initialization) */
void mrb_dir_hal_init(mrb_state *mrb); void mrb_hal_dir_init(mrb_state *mrb);
/* Cleanup HAL (called once at gem finalization) */ /* Cleanup HAL (called once at gem finalization) */
void mrb_dir_hal_final(mrb_state *mrb); void mrb_hal_dir_final(mrb_state *mrb);
#endif /* MRUBY_DIR_HAL_H */ #endif /* MRUBY_DIR_HAL_H */
+24 -24
View File
@@ -28,7 +28,7 @@ mrb_dir_free(mrb_state *mrb, void *ptr)
struct mrb_dir *mdir = (struct mrb_dir*)ptr; struct mrb_dir *mdir = (struct mrb_dir*)ptr;
if (mdir->handle) { if (mdir->handle) {
mrb_dir_hal_close(mrb, mdir->handle); mrb_hal_dir_close(mrb, mdir->handle);
mdir->handle = NULL; mdir->handle = NULL;
} }
mrb_free(mrb, mdir); mrb_free(mrb, mdir);
@@ -55,7 +55,7 @@ mrb_dir_close(mrb_state *mrb, mrb_value self)
if (!mdir->handle) { if (!mdir->handle) {
mrb_raise(mrb, E_IO_ERROR, "closed directory"); mrb_raise(mrb, E_IO_ERROR, "closed directory");
} }
if (mrb_dir_hal_close(mrb, mdir->handle) == -1) { if (mrb_hal_dir_close(mrb, mdir->handle) == -1) {
mrb_sys_fail(mrb, "closedir"); mrb_sys_fail(mrb, "closedir");
} }
mdir->handle = NULL; mdir->handle = NULL;
@@ -89,7 +89,7 @@ mrb_dir_init(mrb_state *mrb, mrb_value self)
DATA_PTR(self) = mdir; DATA_PTR(self) = mdir;
mrb_get_args(mrb, "z", &path); mrb_get_args(mrb, "z", &path);
if ((handle = mrb_dir_hal_open(mrb, path)) == NULL) { if ((handle = mrb_hal_dir_open(mrb, path)) == NULL) {
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, path);
} }
mdir->handle = handle; mdir->handle = handle;
@@ -111,7 +111,7 @@ mrb_dir_delete(mrb_state *mrb, mrb_value klass)
const char *path; const char *path;
mrb_get_args(mrb, "z", &path); mrb_get_args(mrb, "z", &path);
if (mrb_dir_hal_rmdir(mrb, path) == -1) { if (mrb_hal_dir_rmdir(mrb, path) == -1) {
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, path);
} }
return mrb_fixnum_value(0); return mrb_fixnum_value(0);
@@ -132,7 +132,7 @@ mrb_dir_existp(mrb_state *mrb, mrb_value klass)
const char *path; const char *path;
mrb_get_args(mrb, "z", &path); mrb_get_args(mrb, "z", &path);
if (mrb_dir_hal_is_directory(mrb, path)) { if (mrb_hal_dir_is_directory(mrb, path)) {
return mrb_true_value(); return mrb_true_value();
} }
else { else {
@@ -156,7 +156,7 @@ mrb_dir_getwd(mrb_state *mrb, mrb_value klass)
mrb_int size = 64; mrb_int size = 64;
path = mrb_str_buf_new(mrb, size); path = mrb_str_buf_new(mrb, size);
while (mrb_dir_hal_getcwd(mrb, RSTRING_PTR(path), (size_t)size) == -1) { while (mrb_hal_dir_getcwd(mrb, RSTRING_PTR(path), (size_t)size) == -1) {
int e = errno; int e = errno;
if (e != ERANGE) { if (e != ERANGE) {
mrb_sys_fail(mrb, "getcwd(2)"); mrb_sys_fail(mrb, "getcwd(2)");
@@ -188,7 +188,7 @@ mrb_dir_mkdir(mrb_state *mrb, mrb_value klass)
mode = 0777; mode = 0777;
mrb_get_args(mrb, "z|i", &path, &mode); mrb_get_args(mrb, "z|i", &path, &mode);
if (mrb_dir_hal_mkdir(mrb, path, (int)mode) == -1) { if (mrb_hal_dir_mkdir(mrb, path, (int)mode) == -1) {
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, path);
} }
return mrb_fixnum_value(0); return mrb_fixnum_value(0);
@@ -201,7 +201,7 @@ mrb_dir_chdir(mrb_state *mrb, mrb_value klass)
const char *path; const char *path;
mrb_get_args(mrb, "z", &path); mrb_get_args(mrb, "z", &path);
if (mrb_dir_hal_chdir(mrb, path) == -1) { if (mrb_hal_dir_chdir(mrb, path) == -1) {
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, path);
} }
return mrb_fixnum_value(0); return mrb_fixnum_value(0);
@@ -223,7 +223,7 @@ mrb_dir_chroot(mrb_state *mrb, mrb_value self)
int res; int res;
mrb_get_args(mrb, "z", &path); mrb_get_args(mrb, "z", &path);
res = mrb_dir_hal_chroot(mrb, path); res = mrb_hal_dir_chroot(mrb, path);
if (res == -1) { if (res == -1) {
if (errno == ENOSYS) { if (errno == ENOSYS) {
mrb_raise(mrb, E_NOTIMP_ERROR, "chroot() unreliable on your system"); mrb_raise(mrb, E_NOTIMP_ERROR, "chroot() unreliable on your system");
@@ -262,16 +262,16 @@ mrb_dir_empty(mrb_state *mrb, mrb_value self)
mrb_value result = mrb_true_value(); mrb_value result = mrb_true_value();
mrb_get_args(mrb, "z", &path); mrb_get_args(mrb, "z", &path);
if ((handle = mrb_dir_hal_open(mrb, path)) == NULL) { if ((handle = mrb_hal_dir_open(mrb, path)) == NULL) {
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, path);
} }
while ((name = mrb_dir_hal_read(mrb, handle)) != NULL) { while ((name = mrb_hal_dir_read(mrb, handle)) != NULL) {
if (!skip_name_p(name)) { if (!skip_name_p(name)) {
result = mrb_false_value(); result = mrb_false_value();
break; break;
} }
} }
mrb_dir_hal_close(mrb, handle); mrb_hal_dir_close(mrb, handle);
return result; return result;
} }
@@ -298,7 +298,7 @@ mrb_dir_read(mrb_state *mrb, mrb_value self)
if (!mdir->handle) { if (!mdir->handle) {
mrb_raise(mrb, E_IO_ERROR, "closed directory"); mrb_raise(mrb, E_IO_ERROR, "closed directory");
} }
name = mrb_dir_hal_read(mrb, mdir->handle); name = mrb_hal_dir_read(mrb, mdir->handle);
if (name != NULL) { if (name != NULL) {
return mrb_str_new_cstr(mrb, name); return mrb_str_new_cstr(mrb, name);
} }
@@ -328,7 +328,7 @@ mrb_dir_rewind(mrb_state *mrb, mrb_value self)
if (!mdir->handle) { if (!mdir->handle) {
mrb_raise(mrb, E_IO_ERROR, "closed directory"); mrb_raise(mrb, E_IO_ERROR, "closed directory");
} }
mrb_dir_hal_rewind(mrb, mdir->handle); mrb_hal_dir_rewind(mrb, mdir->handle);
return self; return self;
} }
@@ -357,7 +357,7 @@ mrb_dir_seek(mrb_state *mrb, mrb_value self)
mrb_raise(mrb, E_IO_ERROR, "closed directory"); mrb_raise(mrb, E_IO_ERROR, "closed directory");
} }
mrb_get_args(mrb, "i", &pos); mrb_get_args(mrb, "i", &pos);
if (mrb_dir_hal_seek(mrb, mdir->handle, (long)pos) == -1) { if (mrb_hal_dir_seek(mrb, mdir->handle, (long)pos) == -1) {
if (errno == ENOSYS) { if (errno == ENOSYS) {
mrb_raise(mrb, E_NOTIMP_ERROR, "dirseek() unreliable on your system"); mrb_raise(mrb, E_NOTIMP_ERROR, "dirseek() unreliable on your system");
} }
@@ -388,7 +388,7 @@ mrb_dir_tell(mrb_state *mrb, mrb_value self)
if (!mdir->handle) { if (!mdir->handle) {
mrb_raise(mrb, E_IO_ERROR, "closed directory"); mrb_raise(mrb, E_IO_ERROR, "closed directory");
} }
pos = mrb_dir_hal_tell(mrb, mdir->handle); pos = mrb_hal_dir_tell(mrb, mdir->handle);
if (pos == -1) { if (pos == -1) {
if (errno == ENOSYS) { if (errno == ENOSYS) {
mrb_raise(mrb, E_NOTIMP_ERROR, "dirtell() unreliable on your system"); mrb_raise(mrb, E_NOTIMP_ERROR, "dirtell() unreliable on your system");
@@ -414,17 +414,17 @@ mrb_dir_entries(mrb_state *mrb, mrb_value klass)
mrb_get_args(mrb, "z", &path); mrb_get_args(mrb, "z", &path);
handle = mrb_dir_hal_open(mrb, path); handle = mrb_hal_dir_open(mrb, path);
if (handle == NULL) { if (handle == NULL) {
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, path);
} }
ary = mrb_ary_new(mrb); ary = mrb_ary_new(mrb);
while ((name = mrb_dir_hal_read(mrb, handle)) != NULL) { while ((name = mrb_hal_dir_read(mrb, handle)) != NULL) {
mrb_ary_push(mrb, ary, mrb_str_new_cstr(mrb, name)); mrb_ary_push(mrb, ary, mrb_str_new_cstr(mrb, name));
} }
mrb_dir_hal_close(mrb, handle); mrb_hal_dir_close(mrb, handle);
return ary; return ary;
} }
@@ -446,19 +446,19 @@ mrb_dir_children(mrb_state *mrb, mrb_value klass)
mrb_get_args(mrb, "z", &path); mrb_get_args(mrb, "z", &path);
handle = mrb_dir_hal_open(mrb, path); handle = mrb_hal_dir_open(mrb, path);
if (handle == NULL) { if (handle == NULL) {
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, path);
} }
ary = mrb_ary_new(mrb); ary = mrb_ary_new(mrb);
while ((name = mrb_dir_hal_read(mrb, handle)) != NULL) { while ((name = mrb_hal_dir_read(mrb, handle)) != NULL) {
if (!skip_name_p(name)) { if (!skip_name_p(name)) {
mrb_ary_push(mrb, ary, mrb_str_new_cstr(mrb, name)); mrb_ary_push(mrb, ary, mrb_str_new_cstr(mrb, name));
} }
} }
mrb_dir_hal_close(mrb, handle); mrb_hal_dir_close(mrb, handle);
return ary; return ary;
} }
@@ -467,7 +467,7 @@ mrb_mruby_dir_gem_init(mrb_state *mrb)
{ {
struct RClass *d; struct RClass *d;
mrb_dir_hal_init(mrb); mrb_hal_dir_init(mrb);
d = mrb_define_class_id(mrb, MRB_SYM(Dir), mrb->object_class); d = mrb_define_class_id(mrb, MRB_SYM(Dir), mrb->object_class);
MRB_SET_INSTANCE_TT(d, MRB_TT_DATA); MRB_SET_INSTANCE_TT(d, MRB_TT_DATA);
@@ -494,5 +494,5 @@ mrb_mruby_dir_gem_init(mrb_state *mrb)
void void
mrb_mruby_dir_gem_final(mrb_state *mrb) mrb_mruby_dir_gem_final(mrb_state *mrb)
{ {
mrb_dir_hal_final(mrb); mrb_hal_dir_final(mrb);
} }
+34 -34
View File
@@ -90,7 +90,7 @@ typedef struct mrb_io_fdset mrb_io_fdset;
* @param st Output stat structure * @param st Output stat structure
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_stat(mrb_state *mrb, const char *path, mrb_io_stat *st); int mrb_hal_io_stat(mrb_state *mrb, const char *path, mrb_io_stat *st);
/** /**
* Get file status by descriptor * Get file status by descriptor
@@ -100,7 +100,7 @@ int mrb_io_hal_stat(mrb_state *mrb, const char *path, mrb_io_stat *st);
* @param st Output stat structure * @param st Output stat structure
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_fstat(mrb_state *mrb, int fd, mrb_io_stat *st); int mrb_hal_io_fstat(mrb_state *mrb, int fd, mrb_io_stat *st);
/** /**
* Get link status (don't follow symlinks) * Get link status (don't follow symlinks)
@@ -110,7 +110,7 @@ int mrb_io_hal_fstat(mrb_state *mrb, int fd, mrb_io_stat *st);
* @param st Output stat structure * @param st Output stat structure
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_lstat(mrb_state *mrb, const char *path, mrb_io_stat *st); int mrb_hal_io_lstat(mrb_state *mrb, const char *path, mrb_io_stat *st);
/** /**
* Change file permissions * Change file permissions
@@ -120,7 +120,7 @@ int mrb_io_hal_lstat(mrb_state *mrb, const char *path, mrb_io_stat *st);
* @param mode New permission mode * @param mode New permission mode
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_chmod(mrb_state *mrb, const char *path, uint32_t mode); int mrb_hal_io_chmod(mrb_state *mrb, const char *path, uint32_t mode);
/** /**
* Set/get file creation mask * Set/get file creation mask
@@ -129,7 +129,7 @@ int mrb_io_hal_chmod(mrb_state *mrb, const char *path, uint32_t mode);
* @param mask New umask value (if < 0, only returns current value) * @param mask New umask value (if < 0, only returns current value)
* @return Previous umask value * @return Previous umask value
*/ */
uint32_t mrb_io_hal_umask(mrb_state *mrb, int32_t mask); uint32_t mrb_hal_io_umask(mrb_state *mrb, int32_t mask);
/** /**
* Truncate file to specified length * Truncate file to specified length
@@ -139,7 +139,7 @@ uint32_t mrb_io_hal_umask(mrb_state *mrb, int32_t mask);
* @param length New file length * @param length New file length
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_ftruncate(mrb_state *mrb, int fd, int64_t length); int mrb_hal_io_ftruncate(mrb_state *mrb, int fd, int64_t length);
/** /**
* Apply or remove advisory lock on file * Apply or remove advisory lock on file
@@ -149,7 +149,7 @@ int mrb_io_hal_ftruncate(mrb_state *mrb, int fd, int64_t length);
* @param operation Lock operation (MRB_IO_LOCK_*) * @param operation Lock operation (MRB_IO_LOCK_*)
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_flock(mrb_state *mrb, int fd, int operation); int mrb_hal_io_flock(mrb_state *mrb, int fd, int operation);
/** /**
* Delete a file * Delete a file
@@ -158,7 +158,7 @@ int mrb_io_hal_flock(mrb_state *mrb, int fd, int operation);
* @param path File path (UTF-8) * @param path File path (UTF-8)
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_unlink(mrb_state *mrb, const char *path); int mrb_hal_io_unlink(mrb_state *mrb, const char *path);
/** /**
* Rename a file * Rename a file
@@ -168,7 +168,7 @@ int mrb_io_hal_unlink(mrb_state *mrb, const char *path);
* @param newpath New file path (UTF-8) * @param newpath New file path (UTF-8)
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_rename(mrb_state *mrb, const char *oldpath, const char *newpath); int mrb_hal_io_rename(mrb_state *mrb, const char *oldpath, const char *newpath);
/** /**
* Create a symbolic link * Create a symbolic link
@@ -178,7 +178,7 @@ int mrb_io_hal_rename(mrb_state *mrb, const char *oldpath, const char *newpath);
* @param linkpath Link path (UTF-8) * @param linkpath Link path (UTF-8)
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_symlink(mrb_state *mrb, const char *target, const char *linkpath); int mrb_hal_io_symlink(mrb_state *mrb, const char *target, const char *linkpath);
/** /**
* Read value of a symbolic link * Read value of a symbolic link
@@ -189,7 +189,7 @@ int mrb_io_hal_symlink(mrb_state *mrb, const char *target, const char *linkpath)
* @param bufsize Buffer size * @param bufsize Buffer size
* @return Number of bytes placed in buf, -1 on error (sets errno) * @return Number of bytes placed in buf, -1 on error (sets errno)
*/ */
int64_t mrb_io_hal_readlink(mrb_state *mrb, const char *path, char *buf, size_t bufsize); int64_t mrb_hal_io_readlink(mrb_state *mrb, const char *path, char *buf, size_t bufsize);
/** /**
* Resolve pathname to absolute path * Resolve pathname to absolute path
@@ -199,7 +199,7 @@ int64_t mrb_io_hal_readlink(mrb_state *mrb, const char *path, char *buf, size_t
* @param resolved Buffer for resolved path (must be at least PATH_MAX size) * @param resolved Buffer for resolved path (must be at least PATH_MAX size)
* @return Pointer to resolved on success, NULL on error (sets errno) * @return Pointer to resolved on success, NULL on error (sets errno)
*/ */
char* mrb_io_hal_realpath(mrb_state *mrb, const char *path, char *resolved); char* mrb_hal_io_realpath(mrb_state *mrb, const char *path, char *resolved);
/** /**
* Get current working directory * Get current working directory
@@ -209,7 +209,7 @@ char* mrb_io_hal_realpath(mrb_state *mrb, const char *path, char *resolved);
* @param size Buffer size * @param size Buffer size
* @return Pointer to buf on success, NULL on error (sets errno) * @return Pointer to buf on success, NULL on error (sets errno)
*/ */
char* mrb_io_hal_getcwd(mrb_state *mrb, char *buf, size_t size); char* mrb_hal_io_getcwd(mrb_state *mrb, char *buf, size_t size);
/** /**
* Get environment variable * Get environment variable
@@ -218,7 +218,7 @@ char* mrb_io_hal_getcwd(mrb_state *mrb, char *buf, size_t size);
* @param name Variable name * @param name Variable name
* @return Value string (UTF-8) or NULL if not found * @return Value string (UTF-8) or NULL if not found
*/ */
const char* mrb_io_hal_getenv(mrb_state *mrb, const char *name); const char* mrb_hal_io_getenv(mrb_state *mrb, const char *name);
/** /**
* Get user's home directory * Get user's home directory
@@ -227,7 +227,7 @@ const char* mrb_io_hal_getenv(mrb_state *mrb, const char *name);
* @param username User name (NULL for current user) * @param username User name (NULL for current user)
* @return Home directory path (UTF-8) or NULL on error (sets errno) * @return Home directory path (UTF-8) or NULL on error (sets errno)
*/ */
const char* mrb_io_hal_gethome(mrb_state *mrb, const char *username); const char* mrb_hal_io_gethome(mrb_state *mrb, const char *username);
/* /*
* HAL Interface - Core I/O Operations * HAL Interface - Core I/O Operations
@@ -242,7 +242,7 @@ const char* mrb_io_hal_gethome(mrb_state *mrb, const char *username);
* @param mode Creation mode (used if O_CREAT is set) * @param mode Creation mode (used if O_CREAT is set)
* @return File descriptor on success, -1 on error (sets errno) * @return File descriptor on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_open(mrb_state *mrb, const char *path, int flags, uint32_t mode); int mrb_hal_io_open(mrb_state *mrb, const char *path, int flags, uint32_t mode);
/** /**
* Close file descriptor * Close file descriptor
@@ -251,7 +251,7 @@ int mrb_io_hal_open(mrb_state *mrb, const char *path, int flags, uint32_t mode);
* @param fd File descriptor * @param fd File descriptor
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_close(mrb_state *mrb, int fd); int mrb_hal_io_close(mrb_state *mrb, int fd);
/** /**
* Read from file descriptor * Read from file descriptor
@@ -262,7 +262,7 @@ int mrb_io_hal_close(mrb_state *mrb, int fd);
* @param count Maximum bytes to read * @param count Maximum bytes to read
* @return Number of bytes read, 0 on EOF, -1 on error (sets errno) * @return Number of bytes read, 0 on EOF, -1 on error (sets errno)
*/ */
int64_t mrb_io_hal_read(mrb_state *mrb, int fd, void *buf, size_t count); int64_t mrb_hal_io_read(mrb_state *mrb, int fd, void *buf, size_t count);
/** /**
* Write to file descriptor * Write to file descriptor
@@ -273,7 +273,7 @@ int64_t mrb_io_hal_read(mrb_state *mrb, int fd, void *buf, size_t count);
* @param count Number of bytes to write * @param count Number of bytes to write
* @return Number of bytes written, -1 on error (sets errno) * @return Number of bytes written, -1 on error (sets errno)
*/ */
int64_t mrb_io_hal_write(mrb_state *mrb, int fd, const void *buf, size_t count); int64_t mrb_hal_io_write(mrb_state *mrb, int fd, const void *buf, size_t count);
/** /**
* Reposition file offset * Reposition file offset
@@ -284,7 +284,7 @@ int64_t mrb_io_hal_write(mrb_state *mrb, int fd, const void *buf, size_t count);
* @param whence Reference point (MRB_IO_SEEK_SET/CUR/END) * @param whence Reference point (MRB_IO_SEEK_SET/CUR/END)
* @return New offset from beginning of file, -1 on error (sets errno) * @return New offset from beginning of file, -1 on error (sets errno)
*/ */
int64_t mrb_io_hal_lseek(mrb_state *mrb, int fd, int64_t offset, int whence); int64_t mrb_hal_io_lseek(mrb_state *mrb, int fd, int64_t offset, int whence);
/** /**
* Duplicate file descriptor * Duplicate file descriptor
@@ -293,7 +293,7 @@ int64_t mrb_io_hal_lseek(mrb_state *mrb, int fd, int64_t offset, int whence);
* @param fd File descriptor to duplicate * @param fd File descriptor to duplicate
* @return New descriptor on success, -1 on error (sets errno) * @return New descriptor on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_dup(mrb_state *mrb, int fd); int mrb_hal_io_dup(mrb_state *mrb, int fd);
/** /**
* Manipulate file descriptor * Manipulate file descriptor
@@ -304,7 +304,7 @@ int mrb_io_hal_dup(mrb_state *mrb, int fd);
* @param arg Command argument * @param arg Command argument
* @return Depends on command, -1 on error (sets errno) * @return Depends on command, -1 on error (sets errno)
*/ */
int mrb_io_hal_fcntl(mrb_state *mrb, int fd, int cmd, int arg); int mrb_hal_io_fcntl(mrb_state *mrb, int fd, int cmd, int arg);
/** /**
* Check if descriptor refers to terminal * Check if descriptor refers to terminal
@@ -313,7 +313,7 @@ int mrb_io_hal_fcntl(mrb_state *mrb, int fd, int cmd, int arg);
* @param fd File descriptor * @param fd File descriptor
* @return 1 if TTY, 0 if not, -1 on error (sets errno) * @return 1 if TTY, 0 if not, -1 on error (sets errno)
*/ */
int mrb_io_hal_isatty(mrb_state *mrb, int fd); int mrb_hal_io_isatty(mrb_state *mrb, int fd);
/** /**
* Create pipe * Create pipe
@@ -322,7 +322,7 @@ int mrb_io_hal_isatty(mrb_state *mrb, int fd);
* @param fds Array to store two file descriptors [read_end, write_end] * @param fds Array to store two file descriptors [read_end, write_end]
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_pipe(mrb_state *mrb, int fds[2]); int mrb_hal_io_pipe(mrb_state *mrb, int fds[2]);
/* /*
* HAL Interface - Process Operations * HAL Interface - Process Operations
@@ -345,7 +345,7 @@ int mrb_io_hal_pipe(mrb_state *mrb, int fds[2]);
* @param pid Output parameter for process ID * @param pid Output parameter for process ID
* @return 0 on success, -1 on error (sets errno) * @return 0 on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_spawn_process(mrb_state *mrb, const char *cmd, int mrb_hal_io_spawn_process(mrb_state *mrb, const char *cmd,
int stdin_fd, int stdout_fd, int stderr_fd, int stdin_fd, int stdout_fd, int stderr_fd,
int *pid); int *pid);
@@ -358,7 +358,7 @@ int mrb_io_hal_spawn_process(mrb_state *mrb, const char *cmd,
* @param options Wait options (0 for blocking wait) * @param options Wait options (0 for blocking wait)
* @return Process ID on success, -1 on error (sets errno) * @return Process ID on success, -1 on error (sets errno)
*/ */
int mrb_io_hal_waitpid(mrb_state *mrb, int pid, int *status, int options); int mrb_hal_io_waitpid(mrb_state *mrb, int pid, int *status, int options);
/* /*
* HAL Interface - I/O Multiplexing * HAL Interface - I/O Multiplexing
@@ -370,7 +370,7 @@ int mrb_io_hal_waitpid(mrb_state *mrb, int pid, int *status, int options);
* @param mrb mruby state * @param mrb mruby state
* @return Pointer to fdset or NULL on error * @return Pointer to fdset or NULL on error
*/ */
mrb_io_fdset* mrb_io_hal_fdset_alloc(mrb_state *mrb); mrb_io_fdset* mrb_hal_io_fdset_alloc(mrb_state *mrb);
/** /**
* Free file descriptor set * Free file descriptor set
@@ -378,7 +378,7 @@ mrb_io_fdset* mrb_io_hal_fdset_alloc(mrb_state *mrb);
* @param mrb mruby state * @param mrb mruby state
* @param fdset File descriptor set to free * @param fdset File descriptor set to free
*/ */
void mrb_io_hal_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset); void mrb_hal_io_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset);
/** /**
* Clear file descriptor set * Clear file descriptor set
@@ -386,7 +386,7 @@ void mrb_io_hal_fdset_free(mrb_state *mrb, mrb_io_fdset *fdset);
* @param mrb mruby state * @param mrb mruby state
* @param fdset File descriptor set * @param fdset File descriptor set
*/ */
void mrb_io_hal_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset); void mrb_hal_io_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset);
/** /**
* Add descriptor to set * Add descriptor to set
@@ -395,7 +395,7 @@ void mrb_io_hal_fdset_zero(mrb_state *mrb, mrb_io_fdset *fdset);
* @param fd File descriptor * @param fd File descriptor
* @param fdset File descriptor set * @param fdset File descriptor set
*/ */
void mrb_io_hal_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset); void mrb_hal_io_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset);
/** /**
* Check if descriptor is in set * Check if descriptor is in set
@@ -405,7 +405,7 @@ void mrb_io_hal_fdset_set(mrb_state *mrb, int fd, mrb_io_fdset *fdset);
* @param fdset File descriptor set * @param fdset File descriptor set
* @return Non-zero if fd is in set, 0 otherwise * @return Non-zero if fd is in set, 0 otherwise
*/ */
int mrb_io_hal_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset); int mrb_hal_io_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset);
/** /**
* Monitor multiple file descriptors * Monitor multiple file descriptors
@@ -418,7 +418,7 @@ int mrb_io_hal_fdset_isset(mrb_state *mrb, int fd, mrb_io_fdset *fdset);
* @param timeout Timeout (NULL = block indefinitely) * @param timeout Timeout (NULL = block indefinitely)
* @return Number of ready descriptors, 0 on timeout, -1 on error (sets errno) * @return Number of ready descriptors, 0 on timeout, -1 on error (sets errno)
*/ */
int mrb_io_hal_select(mrb_state *mrb, int nfds, int mrb_hal_io_select(mrb_state *mrb, int nfds,
mrb_io_fdset *readfds, mrb_io_fdset *readfds,
mrb_io_fdset *writefds, mrb_io_fdset *writefds,
mrb_io_fdset *errorfds, mrb_io_fdset *errorfds,
@@ -436,7 +436,7 @@ int mrb_io_hal_select(mrb_state *mrb, int nfds,
* *
* @param mrb mruby state * @param mrb mruby state
*/ */
void mrb_io_hal_init(mrb_state *mrb); void mrb_hal_io_init(mrb_state *mrb);
/** /**
* Finalize I/O HAL * Finalize I/O HAL
@@ -446,6 +446,6 @@ void mrb_io_hal_init(mrb_state *mrb);
* *
* @param mrb mruby state * @param mrb mruby state
*/ */
void mrb_io_hal_final(mrb_state *mrb); void mrb_hal_io_final(mrb_state *mrb);
#endif /* MRUBY_IO_HAL_H */ #endif /* MRUBY_IO_HAL_H */
+20 -20
View File
@@ -135,10 +135,10 @@ mrb_file_s_umask(mrb_state *mrb, mrb_value klass)
uint32_t omask; uint32_t omask;
if (mrb_get_args(mrb, "|i", &mask) == 0) { if (mrb_get_args(mrb, "|i", &mask) == 0) {
omask = mrb_io_hal_umask(mrb, -1); omask = mrb_hal_io_umask(mrb, -1);
} }
else { else {
omask = mrb_io_hal_umask(mrb, (int32_t)mask); omask = mrb_hal_io_umask(mrb, (int32_t)mask);
} }
return mrb_fixnum_value(omask); return mrb_fixnum_value(omask);
} }
@@ -164,7 +164,7 @@ mrb_file_s_unlink(mrb_state *mrb, mrb_value obj)
mrb_ensure_string_type(mrb, pathv); mrb_ensure_string_type(mrb, pathv);
const char *utf8_path = RSTRING_CSTR(mrb, pathv); const char *utf8_path = RSTRING_CSTR(mrb, pathv);
char *path = mrb_locale_from_utf8(utf8_path, -1); char *path = mrb_locale_from_utf8(utf8_path, -1);
if (mrb_io_hal_unlink(mrb, path) < 0) { if (mrb_hal_io_unlink(mrb, path) < 0) {
mrb_locale_free(path); mrb_locale_free(path);
mrb_sys_fail(mrb, utf8_path); mrb_sys_fail(mrb, utf8_path);
} }
@@ -189,12 +189,12 @@ mrb_file_s_rename(mrb_state *mrb, mrb_value obj)
mrb_get_args(mrb, "SS", &from, &to); mrb_get_args(mrb, "SS", &from, &to);
char *src = mrb_locale_from_utf8(RSTRING_CSTR(mrb, from), -1); char *src = mrb_locale_from_utf8(RSTRING_CSTR(mrb, from), -1);
char *dst = mrb_locale_from_utf8(RSTRING_CSTR(mrb, to), -1); char *dst = mrb_locale_from_utf8(RSTRING_CSTR(mrb, to), -1);
if (mrb_io_hal_rename(mrb, src, dst) < 0) { if (mrb_hal_io_rename(mrb, src, dst) < 0) {
#if defined(_WIN32) #if defined(_WIN32)
/* Windows retry: try chmod+unlink+rename if initial rename fails */ /* Windows retry: try chmod+unlink+rename if initial rename fails */
if (mrb_io_hal_chmod(mrb, dst, 0666) == 0 && if (mrb_hal_io_chmod(mrb, dst, 0666) == 0 &&
mrb_io_hal_unlink(mrb, dst) == 0 && mrb_hal_io_unlink(mrb, dst) == 0 &&
mrb_io_hal_rename(mrb, src, dst) == 0) { mrb_hal_io_rename(mrb, src, dst) == 0) {
mrb_locale_free(src); mrb_locale_free(src);
mrb_locale_free(dst); mrb_locale_free(dst);
return mrb_fixnum_value(0); return mrb_fixnum_value(0);
@@ -401,7 +401,7 @@ mrb_file_realpath(mrb_state *mrb, mrb_value klass)
} }
char *cpath = mrb_locale_from_utf8(RSTRING_CSTR(mrb, pathname), -1); char *cpath = mrb_locale_from_utf8(RSTRING_CSTR(mrb, pathname), -1);
mrb_value result = mrb_str_new_capa(mrb, PATH_MAX); mrb_value result = mrb_str_new_capa(mrb, PATH_MAX);
if (mrb_io_hal_realpath(mrb, cpath, RSTRING_PTR(result)) == NULL) { if (mrb_hal_io_realpath(mrb, cpath, RSTRING_PTR(result)) == NULL) {
mrb_locale_free(cpath); mrb_locale_free(cpath);
mrb_sys_fail(mrb, RSTRING_CSTR(mrb, pathname)); mrb_sys_fail(mrb, RSTRING_CSTR(mrb, pathname));
return result; /* not reached */ return result; /* not reached */
@@ -416,7 +416,7 @@ path_getwd(mrb_state *mrb)
{ {
char buf[MAXPATHLEN]; char buf[MAXPATHLEN];
if (mrb_io_hal_getcwd(mrb, buf, MAXPATHLEN) == NULL) { if (mrb_hal_io_getcwd(mrb, buf, MAXPATHLEN) == NULL) {
mrb_sys_fail(mrb, "getcwd(2)"); mrb_sys_fail(mrb, "getcwd(2)");
} }
char *utf8 = mrb_utf8_from_locale(buf, -1); char *utf8 = mrb_utf8_from_locale(buf, -1);
@@ -528,7 +528,7 @@ path_gethome(mrb_state *mrb, const char **pathp)
ptrdiff_t len = *pathp - username; ptrdiff_t len = *pathp - username;
if (len == 0) { if (len == 0) {
home = mrb_io_hal_gethome(mrb, NULL); home = mrb_hal_io_gethome(mrb, NULL);
if (home == NULL) { if (home == NULL) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "couldn't find HOME environment -- expanding '~'"); mrb_raise(mrb, E_ARGUMENT_ERROR, "couldn't find HOME environment -- expanding '~'");
} }
@@ -538,7 +538,7 @@ path_gethome(mrb_state *mrb, const char **pathp)
} }
else { else {
const char *uname = RSTRING_CSTR(mrb, mrb_str_new(mrb, username, (mrb_int)len)); const char *uname = RSTRING_CSTR(mrb, mrb_str_new(mrb, username, (mrb_int)len));
home = mrb_io_hal_gethome(mrb, uname); home = mrb_hal_io_gethome(mrb, uname);
if (home == NULL) { if (home == NULL) {
mrb_raisef(mrb, E_ARGUMENT_ERROR, "user %s doesn't exist", uname); mrb_raisef(mrb, E_ARGUMENT_ERROR, "user %s doesn't exist", uname);
} }
@@ -694,7 +694,7 @@ mrb_file_atime(mrb_state *mrb, mrb_value self)
mrb_io_stat st; mrb_io_stat st;
mrb->c->ci->mid = 0; mrb->c->ci->mid = 0;
if (mrb_io_hal_fstat(mrb, fd, &st) == -1) if (mrb_hal_io_fstat(mrb, fd, &st) == -1)
mrb_sys_fail(mrb, "atime"); mrb_sys_fail(mrb, "atime");
if (TIME_OVERFLOW_P(st.st_atime)) { if (TIME_OVERFLOW_P(st.st_atime)) {
TIME_BIGTIME(mrb, st.st_atime); TIME_BIGTIME(mrb, st.st_atime);
@@ -709,7 +709,7 @@ mrb_file_ctime(mrb_state *mrb, mrb_value self)
mrb_io_stat st; mrb_io_stat st;
mrb->c->ci->mid = 0; mrb->c->ci->mid = 0;
if (mrb_io_hal_fstat(mrb, fd, &st) == -1) if (mrb_hal_io_fstat(mrb, fd, &st) == -1)
mrb_sys_fail(mrb, "ctime"); mrb_sys_fail(mrb, "ctime");
if (TIME_OVERFLOW_P(st.st_ctime)) { if (TIME_OVERFLOW_P(st.st_ctime)) {
TIME_BIGTIME(mrb, st.st_ctime); TIME_BIGTIME(mrb, st.st_ctime);
@@ -724,7 +724,7 @@ mrb_file_mtime(mrb_state *mrb, mrb_value self)
mrb_io_stat st; mrb_io_stat st;
mrb->c->ci->mid = 0; mrb->c->ci->mid = 0;
if (mrb_io_hal_fstat(mrb, fd, &st) == -1) if (mrb_hal_io_fstat(mrb, fd, &st) == -1)
mrb_sys_fail(mrb, "mtime"); mrb_sys_fail(mrb, "mtime");
if (TIME_OVERFLOW_P(st.st_mtime)) { if (TIME_OVERFLOW_P(st.st_mtime)) {
TIME_BIGTIME(mrb, st.st_mtime); TIME_BIGTIME(mrb, st.st_mtime);
@@ -754,7 +754,7 @@ mrb_file_flock(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "i", &operation); mrb_get_args(mrb, "i", &operation);
int fd = mrb_io_fileno(mrb, self); int fd = mrb_io_fileno(mrb, self);
while (mrb_io_hal_flock(mrb, fd, (int)operation) == -1) { while (mrb_hal_io_flock(mrb, fd, (int)operation) == -1) {
switch (errno) { switch (errno) {
case EINTR: case EINTR:
/* retry */ /* retry */
@@ -789,7 +789,7 @@ mrb_file_size(mrb_state *mrb, mrb_value self)
{ {
mrb_io_stat st; mrb_io_stat st;
int fd = mrb_io_fileno(mrb, self); int fd = mrb_io_fileno(mrb, self);
if (mrb_io_hal_fstat(mrb, fd, &st) == -1) { if (mrb_hal_io_fstat(mrb, fd, &st) == -1) {
mrb_sys_fail(mrb, "fstat"); mrb_sys_fail(mrb, "fstat");
} }
@@ -807,7 +807,7 @@ mrb_file_size(mrb_state *mrb, mrb_value self)
static int static int
mrb_ftruncate(mrb_state *mrb, int fd, mrb_int length) mrb_ftruncate(mrb_state *mrb, int fd, mrb_int length)
{ {
return mrb_io_hal_ftruncate(mrb, fd, (int64_t)length); return mrb_hal_io_ftruncate(mrb, fd, (int64_t)length);
} }
/* /*
@@ -850,7 +850,7 @@ mrb_file_s_symlink(mrb_state *mrb, mrb_value klass)
mrb_get_args(mrb, "SS", &from, &to); mrb_get_args(mrb, "SS", &from, &to);
const char *src = mrb_locale_from_utf8(RSTRING_CSTR(mrb, from), -1); const char *src = mrb_locale_from_utf8(RSTRING_CSTR(mrb, from), -1);
const char *dst = mrb_locale_from_utf8(RSTRING_CSTR(mrb, to), -1); const char *dst = mrb_locale_from_utf8(RSTRING_CSTR(mrb, to), -1);
if (mrb_io_hal_symlink(mrb, src, dst) == -1) { if (mrb_hal_io_symlink(mrb, src, dst) == -1) {
mrb_locale_free(src); mrb_locale_free(src);
mrb_locale_free(dst); mrb_locale_free(dst);
mrb_sys_fail(mrb, RSTRING_CSTR(mrb, mrb_format(mrb, "(%v, %v)", from, to))); mrb_sys_fail(mrb, RSTRING_CSTR(mrb, mrb_format(mrb, "(%v, %v)", from, to)));
@@ -882,7 +882,7 @@ mrb_file_s_chmod(mrb_state *mrb, mrb_value klass)
mrb_ensure_string_type(mrb, filenames[i]); mrb_ensure_string_type(mrb, filenames[i]);
const char *utf8_path = RSTRING_CSTR(mrb, filenames[i]); const char *utf8_path = RSTRING_CSTR(mrb, filenames[i]);
char *path = mrb_locale_from_utf8(utf8_path, -1); char *path = mrb_locale_from_utf8(utf8_path, -1);
if (mrb_io_hal_chmod(mrb, path, (uint32_t)mode) == -1) { if (mrb_hal_io_chmod(mrb, path, (uint32_t)mode) == -1) {
mrb_locale_free(path); mrb_locale_free(path);
mrb_sys_fail(mrb, utf8_path); mrb_sys_fail(mrb, utf8_path);
} }
@@ -914,7 +914,7 @@ mrb_file_s_readlink(mrb_state *mrb, mrb_value klass)
char *buf = (char*)mrb_malloc(mrb, bufsize); char *buf = (char*)mrb_malloc(mrb, bufsize);
int64_t rc; int64_t rc;
while ((rc = mrb_io_hal_readlink(mrb, tmp, buf, bufsize)) == (int64_t)bufsize) { while ((rc = mrb_hal_io_readlink(mrb, tmp, buf, bufsize)) == (int64_t)bufsize) {
bufsize += 100; bufsize += 100;
buf = (char*)mrb_realloc(mrb, buf, bufsize); buf = (char*)mrb_realloc(mrb, buf, bufsize);
} }
+3 -3
View File
@@ -28,7 +28,7 @@ mrb_stat0(mrb_state *mrb, mrb_value obj, mrb_io_stat *st, int do_lstat)
fptr = (struct mrb_io*)mrb_data_get_ptr(mrb, obj, &mrb_io_type); fptr = (struct mrb_io*)mrb_data_get_ptr(mrb, obj, &mrb_io_type);
if (fptr && fptr->fd >= 0) { if (fptr && fptr->fd >= 0) {
return mrb_io_hal_fstat(mrb, fptr->fd, st); return mrb_hal_io_fstat(mrb, fptr->fd, st);
} }
mrb_raise(mrb, E_IO_ERROR, "closed stream"); mrb_raise(mrb, E_IO_ERROR, "closed stream");
@@ -38,10 +38,10 @@ mrb_stat0(mrb_state *mrb, mrb_value obj, mrb_io_stat *st, int do_lstat)
char *path = mrb_locale_from_utf8(RSTRING_CSTR(mrb, obj), -1); char *path = mrb_locale_from_utf8(RSTRING_CSTR(mrb, obj), -1);
int ret; int ret;
if (do_lstat) { if (do_lstat) {
ret = mrb_io_hal_lstat(mrb, path, st); ret = mrb_hal_io_lstat(mrb, path, st);
} }
else { else {
ret = mrb_io_hal_stat(mrb, path, st); ret = mrb_hal_io_stat(mrb, path, st);
} }
mrb_locale_free(path); mrb_locale_free(path);
return ret; return ret;
+45 -45
View File
@@ -374,16 +374,16 @@ io_s_popen(mrb_state *mrb, mrb_value klass)
/* Create pipes for communication */ /* Create pipes for communication */
if (readable) { if (readable) {
if (mrb_io_hal_pipe(mrb, pr) == -1) { if (mrb_hal_io_pipe(mrb, pr) == -1) {
mrb_sys_fail(mrb, "pipe"); mrb_sys_fail(mrb, "pipe");
} }
} }
if (writable) { if (writable) {
if (mrb_io_hal_pipe(mrb, pw) == -1) { if (mrb_hal_io_pipe(mrb, pw) == -1) {
if (pr[0] != -1) { if (pr[0] != -1) {
mrb_io_hal_close(mrb, pr[0]); mrb_hal_io_close(mrb, pr[0]);
mrb_io_hal_close(mrb, pr[1]); mrb_hal_io_close(mrb, pr[1]);
} }
mrb_sys_fail(mrb, "pipe"); mrb_sys_fail(mrb, "pipe");
} }
@@ -401,15 +401,15 @@ io_s_popen(mrb_state *mrb, mrb_value klass)
stderr_fd = (p.opt_err != -1) ? p.opt_err : stdout_fd; stderr_fd = (p.opt_err != -1) ? p.opt_err : stdout_fd;
/* Spawn child process using HAL */ /* Spawn child process using HAL */
if (mrb_io_hal_spawn_process(mrb, p.cmd, stdin_fd, stdout_fd, stderr_fd, &pid) == -1) { if (mrb_hal_io_spawn_process(mrb, p.cmd, stdin_fd, stdout_fd, stderr_fd, &pid) == -1) {
int saved_errno = errno; int saved_errno = errno;
if (readable) { if (readable) {
mrb_io_hal_close(mrb, pr[0]); mrb_hal_io_close(mrb, pr[0]);
mrb_io_hal_close(mrb, pr[1]); mrb_hal_io_close(mrb, pr[1]);
} }
if (writable) { if (writable) {
mrb_io_hal_close(mrb, pw[0]); mrb_hal_io_close(mrb, pw[0]);
mrb_io_hal_close(mrb, pw[1]); mrb_hal_io_close(mrb, pw[1]);
} }
errno = saved_errno; errno = saved_errno;
mrb_raisef(mrb, E_IO_ERROR, "command not found: %s", p.cmd); mrb_raisef(mrb, E_IO_ERROR, "command not found: %s", p.cmd);
@@ -417,10 +417,10 @@ io_s_popen(mrb_state *mrb, mrb_value klass)
/* Close child ends of pipes in parent */ /* Close child ends of pipes in parent */
if (readable) { if (readable) {
mrb_io_hal_close(mrb, pr[1]); /* close write end */ mrb_hal_io_close(mrb, pr[1]); /* close write end */
} }
if (writable) { if (writable) {
mrb_io_hal_close(mrb, pw[0]); /* close read end */ mrb_hal_io_close(mrb, pw[0]); /* close read end */
} }
} }
@@ -1241,7 +1241,7 @@ io_s_pipe(mrb_state *mrb, mrb_value klass)
{ {
int pipes[2]; int pipes[2];
if (mrb_io_hal_pipe(mrb, pipes) == -1) { if (mrb_hal_io_pipe(mrb, pipes) == -1) {
mrb_sys_fail(mrb, "pipe"); mrb_sys_fail(mrb, "pipe");
} }
@@ -1328,22 +1328,22 @@ io_s_select(mrb_state *mrb, mrb_value klass)
tp = &timerec; tp = &timerec;
} }
mrb_io_fdset *pset = mrb_io_hal_fdset_alloc(mrb); mrb_io_fdset *pset = mrb_hal_io_fdset_alloc(mrb);
mrb_io_fdset *rset = NULL; mrb_io_fdset *rset = NULL;
mrb_io_fdset *rp = NULL; mrb_io_fdset *rp = NULL;
mrb_io_hal_fdset_zero(mrb, pset); mrb_hal_io_fdset_zero(mrb, pset);
if (!mrb_nil_p(read)) { if (!mrb_nil_p(read)) {
mrb_check_type(mrb, read, MRB_TT_ARRAY); mrb_check_type(mrb, read, MRB_TT_ARRAY);
rset = mrb_io_hal_fdset_alloc(mrb); rset = mrb_hal_io_fdset_alloc(mrb);
rp = rset; rp = rset;
mrb_io_hal_fdset_zero(mrb, rp); mrb_hal_io_fdset_zero(mrb, rp);
for (int i = 0; i < RARRAY_LEN(read); i++) { for (int i = 0; i < RARRAY_LEN(read); i++) {
read_io = RARRAY_PTR(read)[i]; read_io = RARRAY_PTR(read)[i];
fptr = io_get_open_fptr(mrb, read_io); fptr = io_get_open_fptr(mrb, read_io);
mrb_io_hal_fdset_set(mrb, fptr->fd, rp); mrb_hal_io_fdset_set(mrb, fptr->fd, rp);
if (mrb_io_read_data_pending(mrb, fptr)) { if (mrb_io_read_data_pending(mrb, fptr)) {
pending++; pending++;
mrb_io_hal_fdset_set(mrb, fptr->fd, pset); mrb_hal_io_fdset_set(mrb, fptr->fd, pset);
} }
if (max < fptr->fd) if (max < fptr->fd)
max = fptr->fd; max = fptr->fd;
@@ -1358,16 +1358,16 @@ io_s_select(mrb_state *mrb, mrb_value klass)
mrb_io_fdset *wp = NULL; mrb_io_fdset *wp = NULL;
if (!mrb_nil_p(write)) { if (!mrb_nil_p(write)) {
mrb_check_type(mrb, write, MRB_TT_ARRAY); mrb_check_type(mrb, write, MRB_TT_ARRAY);
wset = mrb_io_hal_fdset_alloc(mrb); wset = mrb_hal_io_fdset_alloc(mrb);
wp = wset; wp = wset;
mrb_io_hal_fdset_zero(mrb, wp); mrb_hal_io_fdset_zero(mrb, wp);
for (int i = 0; i < RARRAY_LEN(write); i++) { for (int i = 0; i < RARRAY_LEN(write); i++) {
fptr = io_get_open_fptr(mrb, RARRAY_PTR(write)[i]); fptr = io_get_open_fptr(mrb, RARRAY_PTR(write)[i]);
mrb_io_hal_fdset_set(mrb, fptr->fd, wp); mrb_hal_io_fdset_set(mrb, fptr->fd, wp);
if (max < fptr->fd) if (max < fptr->fd)
max = fptr->fd; max = fptr->fd;
if (fptr->fd2 >= 0) { if (fptr->fd2 >= 0) {
mrb_io_hal_fdset_set(mrb, fptr->fd2, wp); mrb_hal_io_fdset_set(mrb, fptr->fd2, wp);
if (max < fptr->fd2) if (max < fptr->fd2)
max = fptr->fd2; max = fptr->fd2;
} }
@@ -1378,16 +1378,16 @@ io_s_select(mrb_state *mrb, mrb_value klass)
mrb_io_fdset *ep = NULL; mrb_io_fdset *ep = NULL;
if (!mrb_nil_p(except)) { if (!mrb_nil_p(except)) {
mrb_check_type(mrb, except, MRB_TT_ARRAY); mrb_check_type(mrb, except, MRB_TT_ARRAY);
eset = mrb_io_hal_fdset_alloc(mrb); eset = mrb_hal_io_fdset_alloc(mrb);
ep = eset; ep = eset;
mrb_io_hal_fdset_zero(mrb, ep); mrb_hal_io_fdset_zero(mrb, ep);
for (int i = 0; i < RARRAY_LEN(except); i++) { for (int i = 0; i < RARRAY_LEN(except); i++) {
fptr = io_get_open_fptr(mrb, RARRAY_PTR(except)[i]); fptr = io_get_open_fptr(mrb, RARRAY_PTR(except)[i]);
mrb_io_hal_fdset_set(mrb, fptr->fd, ep); mrb_hal_io_fdset_set(mrb, fptr->fd, ep);
if (max < fptr->fd) if (max < fptr->fd)
max = fptr->fd; max = fptr->fd;
if (fptr->fd2 >= 0) { if (fptr->fd2 >= 0) {
mrb_io_hal_fdset_set(mrb, fptr->fd2, ep); mrb_hal_io_fdset_set(mrb, fptr->fd2, ep);
if (max < fptr->fd2) if (max < fptr->fd2)
max = fptr->fd2; max = fptr->fd2;
} }
@@ -1398,13 +1398,13 @@ io_s_select(mrb_state *mrb, mrb_value klass)
int n; int n;
retry: retry:
n = mrb_io_hal_select(mrb, max, rp, wp, ep, tp); n = mrb_hal_io_select(mrb, max, rp, wp, ep, tp);
if (n < 0) { if (n < 0) {
if (errno != EINTR) { if (errno != EINTR) {
mrb_io_hal_fdset_free(mrb, pset); mrb_hal_io_fdset_free(mrb, pset);
mrb_io_hal_fdset_free(mrb, rset); mrb_hal_io_fdset_free(mrb, rset);
mrb_io_hal_fdset_free(mrb, wset); mrb_hal_io_fdset_free(mrb, wset);
mrb_io_hal_fdset_free(mrb, eset); mrb_hal_io_fdset_free(mrb, eset);
mrb_sys_fail(mrb, "select failed"); mrb_sys_fail(mrb, "select failed");
} }
if (tp == NULL) if (tp == NULL)
@@ -1413,10 +1413,10 @@ retry:
} }
if (!pending && n == 0) { if (!pending && n == 0) {
mrb_io_hal_fdset_free(mrb, pset); mrb_hal_io_fdset_free(mrb, pset);
mrb_io_hal_fdset_free(mrb, rset); mrb_hal_io_fdset_free(mrb, rset);
mrb_io_hal_fdset_free(mrb, wset); mrb_hal_io_fdset_free(mrb, wset);
mrb_io_hal_fdset_free(mrb, eset); mrb_hal_io_fdset_free(mrb, eset);
return mrb_nil_value(); return mrb_nil_value();
} }
@@ -1430,8 +1430,8 @@ retry:
list = RARRAY_PTR(result)[0]; list = RARRAY_PTR(result)[0];
for (int i = 0; i < RARRAY_LEN(read); i++) { for (int i = 0; i < RARRAY_LEN(read); i++) {
fptr = io_get_open_fptr(mrb, RARRAY_PTR(read)[i]); fptr = io_get_open_fptr(mrb, RARRAY_PTR(read)[i]);
if (mrb_io_hal_fdset_isset(mrb, fptr->fd, rp) || if (mrb_hal_io_fdset_isset(mrb, fptr->fd, rp) ||
mrb_io_hal_fdset_isset(mrb, fptr->fd, pset)) { mrb_hal_io_fdset_isset(mrb, fptr->fd, pset)) {
mrb_ary_push(mrb, list, RARRAY_PTR(read)[i]); mrb_ary_push(mrb, list, RARRAY_PTR(read)[i]);
} }
} }
@@ -1441,10 +1441,10 @@ retry:
list = RARRAY_PTR(result)[1]; list = RARRAY_PTR(result)[1];
for (int i = 0; i < RARRAY_LEN(write); i++) { for (int i = 0; i < RARRAY_LEN(write); i++) {
fptr = io_get_open_fptr(mrb, RARRAY_PTR(write)[i]); fptr = io_get_open_fptr(mrb, RARRAY_PTR(write)[i]);
if (mrb_io_hal_fdset_isset(mrb, fptr->fd, wp)) { if (mrb_hal_io_fdset_isset(mrb, fptr->fd, wp)) {
mrb_ary_push(mrb, list, RARRAY_PTR(write)[i]); mrb_ary_push(mrb, list, RARRAY_PTR(write)[i]);
} }
else if (fptr->fd2 >= 0 && mrb_io_hal_fdset_isset(mrb, fptr->fd2, wp)) { else if (fptr->fd2 >= 0 && mrb_hal_io_fdset_isset(mrb, fptr->fd2, wp)) {
mrb_ary_push(mrb, list, RARRAY_PTR(write)[i]); mrb_ary_push(mrb, list, RARRAY_PTR(write)[i]);
} }
} }
@@ -1454,20 +1454,20 @@ retry:
list = RARRAY_PTR(result)[2]; list = RARRAY_PTR(result)[2];
for (int i = 0; i < RARRAY_LEN(except); i++) { for (int i = 0; i < RARRAY_LEN(except); i++) {
fptr = io_get_open_fptr(mrb, RARRAY_PTR(except)[i]); fptr = io_get_open_fptr(mrb, RARRAY_PTR(except)[i]);
if (mrb_io_hal_fdset_isset(mrb, fptr->fd, ep)) { if (mrb_hal_io_fdset_isset(mrb, fptr->fd, ep)) {
mrb_ary_push(mrb, list, RARRAY_PTR(except)[i]); mrb_ary_push(mrb, list, RARRAY_PTR(except)[i]);
} }
else if (fptr->fd2 >= 0 && mrb_io_hal_fdset_isset(mrb, fptr->fd2, ep)) { else if (fptr->fd2 >= 0 && mrb_hal_io_fdset_isset(mrb, fptr->fd2, ep)) {
mrb_ary_push(mrb, list, RARRAY_PTR(except)[i]); mrb_ary_push(mrb, list, RARRAY_PTR(except)[i]);
} }
} }
} }
} }
mrb_io_hal_fdset_free(mrb, pset); mrb_hal_io_fdset_free(mrb, pset);
mrb_io_hal_fdset_free(mrb, rset); mrb_hal_io_fdset_free(mrb, rset);
mrb_io_hal_fdset_free(mrb, wset); mrb_hal_io_fdset_free(mrb, wset);
mrb_io_hal_fdset_free(mrb, eset); mrb_hal_io_fdset_free(mrb, eset);
return result; return result;
} }
+8 -8
View File
@@ -23,10 +23,10 @@ extern "C" {
*/ */
/* Initialize socket subsystem (e.g., WSAStartup on Windows) */ /* Initialize socket subsystem (e.g., WSAStartup on Windows) */
void mrb_socket_hal_init(mrb_state *mrb); void mrb_hal_socket_init(mrb_state *mrb);
/* Finalize socket subsystem (e.g., WSACleanup on Windows) */ /* Finalize socket subsystem (e.g., WSACleanup on Windows) */
void mrb_socket_hal_final(mrb_state *mrb); void mrb_hal_socket_final(mrb_state *mrb);
/* /*
* Socket Control Operations * Socket Control Operations
@@ -34,7 +34,7 @@ void mrb_socket_hal_final(mrb_state *mrb);
/* Set non-blocking mode on socket /* Set non-blocking mode on socket
* Returns 0 on success, -1 on error (sets errno) */ * Returns 0 on success, -1 on error (sets errno) */
int mrb_socket_hal_set_nonblock(mrb_state *mrb, int fd, int nonblock); int mrb_hal_socket_set_nonblock(mrb_state *mrb, int fd, int nonblock);
/* /*
* Address Conversion Functions * Address Conversion Functions
@@ -46,14 +46,14 @@ int mrb_socket_hal_set_nonblock(mrb_state *mrb, int fd, int nonblock);
* dst: buffer for string result * dst: buffer for string result
* size: size of dst buffer * size: size of dst buffer
* Returns: dst on success, NULL on error */ * Returns: dst on success, NULL on error */
const char* mrb_socket_hal_inet_ntop(int af, const void *src, char *dst, size_t size); const char* mrb_hal_socket_inet_ntop(int af, const void *src, char *dst, size_t size);
/* Convert presentation format (string) to network address /* Convert presentation format (string) to network address
* af: address family (AF_INET, AF_INET6) * af: address family (AF_INET, AF_INET6)
* src: string representation of address * src: string representation of address
* dst: buffer for network address result * dst: buffer for network address result
* Returns: 1 on success, 0 if src is not valid, -1 on error */ * Returns: 1 on success, 0 if src is not valid, -1 on error */
int mrb_socket_hal_inet_pton(int af, const char *src, void *dst); int mrb_hal_socket_inet_pton(int af, const char *src, void *dst);
/* /*
* Platform-Specific Socket Features * Platform-Specific Socket Features
@@ -62,7 +62,7 @@ int mrb_socket_hal_inet_pton(int af, const char *src, void *dst);
/* Create Unix domain socket address structure /* Create Unix domain socket address structure
* path: Unix socket path * path: Unix socket path
* Returns: packed sockaddr string, or raises exception if not supported */ * Returns: packed sockaddr string, or raises exception if not supported */
mrb_value mrb_socket_hal_sockaddr_un(mrb_state *mrb, const char *path, size_t pathlen); mrb_value mrb_hal_socket_sockaddr_un(mrb_state *mrb, const char *path, size_t pathlen);
/* Create a pair of connected sockets /* Create a pair of connected sockets
* domain: address family (e.g., AF_UNIX) * domain: address family (e.g., AF_UNIX)
@@ -70,11 +70,11 @@ mrb_value mrb_socket_hal_sockaddr_un(mrb_state *mrb, const char *path, size_t pa
* protocol: protocol (usually 0) * protocol: protocol (usually 0)
* sv: array to receive the two socket descriptors * sv: array to receive the two socket descriptors
* Returns: 0 on success, -1 on error (sets errno) */ * Returns: 0 on success, -1 on error (sets errno) */
int mrb_socket_hal_socketpair(mrb_state *mrb, int domain, int type, int protocol, int sv[2]); int mrb_hal_socket_socketpair(mrb_state *mrb, int domain, int type, int protocol, int sv[2]);
/* Get Unix socket path from sockaddr /* Get Unix socket path from sockaddr
* Returns: Unix socket path string, or raises exception if not supported */ * Returns: Unix socket path string, or raises exception if not supported */
mrb_value mrb_socket_hal_unix_path(mrb_state *mrb, const char *sockaddr, size_t socklen); mrb_value mrb_hal_socket_unix_path(mrb_state *mrb, const char *sockaddr, size_t socklen);
#ifdef __cplusplus #ifdef __cplusplus
} }
+9 -9
View File
@@ -274,7 +274,7 @@ mrb_addrinfo_unix_path(mrb_state *mrb, mrb_value self)
mrb_raise(mrb, E_SOCKET_ERROR, "invalid sockaddr"); mrb_raise(mrb, E_SOCKET_ERROR, "invalid sockaddr");
} }
return mrb_socket_hal_unix_path(mrb, RSTRING_PTR(sastr), (size_t)RSTRING_LEN(sastr)); return mrb_hal_socket_unix_path(mrb, RSTRING_PTR(sastr), (size_t)RSTRING_LEN(sastr));
} }
/* Helper to convert sockaddr to address list array [family, port, host, host] */ /* Helper to convert sockaddr to address list array [family, port, host, host] */
@@ -743,7 +743,7 @@ mrb_basicsocket_setnonblock(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "b", &nonblocking); mrb_get_args(mrb, "b", &nonblocking);
int fd = socket_fd(mrb, self); int fd = socket_fd(mrb, self);
if (mrb_socket_hal_set_nonblock(mrb, fd, nonblocking) == -1) if (mrb_hal_socket_set_nonblock(mrb, fd, nonblocking) == -1)
mrb_sys_fail(mrb, "set_nonblock"); mrb_sys_fail(mrb, "set_nonblock");
return mrb_nil_value(); return mrb_nil_value();
@@ -859,7 +859,7 @@ mrb_ipsocket_ntop(mrb_state *mrb, mrb_value klass)
mrb_get_args(mrb, "is", &af, &addr, &n); mrb_get_args(mrb, "is", &af, &addr, &n);
if ((af == AF_INET && n != 4) || (af == AF_INET6 && n != 16) || if ((af == AF_INET && n != 4) || (af == AF_INET6 && n != 16) ||
mrb_socket_hal_inet_ntop((int)af, addr, buf, sizeof(buf)) == NULL) mrb_hal_socket_inet_ntop((int)af, addr, buf, sizeof(buf)) == NULL)
mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid address"); mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid address");
return mrb_str_new_cstr(mrb, buf); return mrb_str_new_cstr(mrb, buf);
} }
@@ -886,13 +886,13 @@ mrb_ipsocket_pton(mrb_state *mrb, mrb_value klass)
if (af == AF_INET) { if (af == AF_INET) {
struct in_addr in; struct in_addr in;
if (mrb_socket_hal_inet_pton(AF_INET, buf, (void*)&in.s_addr) != 1) if (mrb_hal_socket_inet_pton(AF_INET, buf, (void*)&in.s_addr) != 1)
goto invalid; goto invalid;
return mrb_str_new(mrb, (char*)&in.s_addr, 4); return mrb_str_new(mrb, (char*)&in.s_addr, 4);
} }
else if (af == AF_INET6) { else if (af == AF_INET6) {
struct in6_addr in6; struct in6_addr in6;
if (mrb_socket_hal_inet_pton(AF_INET6, buf, (void*)&in6.s6_addr) != 1) if (mrb_hal_socket_inet_pton(AF_INET6, buf, (void*)&in6.s6_addr) != 1)
goto invalid; goto invalid;
return mrb_str_new(mrb, (char*)&in6.s6_addr, 16); return mrb_str_new(mrb, (char*)&in6.s6_addr, 16);
} }
@@ -1091,7 +1091,7 @@ mrb_socket_sockaddr_un(mrb_state *mrb, mrb_value klass)
mrb_value path; mrb_value path;
mrb_get_args(mrb, "S", &path); mrb_get_args(mrb, "S", &path);
return mrb_socket_hal_sockaddr_un(mrb, RSTRING_PTR(path), (size_t)RSTRING_LEN(path)); return mrb_hal_socket_sockaddr_un(mrb, RSTRING_PTR(path), (size_t)RSTRING_LEN(path));
} }
/* /*
@@ -1112,7 +1112,7 @@ mrb_socket_socketpair(mrb_state *mrb, mrb_value klass)
mrb_get_args(mrb, "iii", &domain, &type, &protocol); mrb_get_args(mrb, "iii", &domain, &type, &protocol);
if (mrb_socket_hal_socketpair(mrb, (int)domain, (int)type, (int)protocol, sv) == -1) { if (mrb_hal_socket_socketpair(mrb, (int)domain, (int)type, (int)protocol, sv) == -1) {
mrb_sys_fail(mrb, "socketpair"); mrb_sys_fail(mrb, "socketpair");
} }
@@ -1266,7 +1266,7 @@ mrb_win32_basicsocket_syswrite(mrb_state *mrb, mrb_value self)
void void
mrb_mruby_socket_gem_init(mrb_state* mrb) mrb_mruby_socket_gem_init(mrb_state* mrb)
{ {
mrb_socket_hal_init(mrb); mrb_hal_socket_init(mrb);
struct RClass *ainfo = mrb_define_class_id(mrb, MRB_SYM(Addrinfo), mrb->object_class); struct RClass *ainfo = mrb_define_class_id(mrb, MRB_SYM(Addrinfo), mrb->object_class);
mrb_define_class_method_id(mrb, ainfo, MRB_SYM(getaddrinfo), mrb_addrinfo_getaddrinfo, MRB_ARGS_REQ(2)|MRB_ARGS_OPT(4)); mrb_define_class_method_id(mrb, ainfo, MRB_SYM(getaddrinfo), mrb_addrinfo_getaddrinfo, MRB_ARGS_REQ(2)|MRB_ARGS_OPT(4));
@@ -1348,5 +1348,5 @@ mrb_mruby_socket_gem_init(mrb_state* mrb)
void void
mrb_mruby_socket_gem_final(mrb_state* mrb) mrb_mruby_socket_gem_final(mrb_state* mrb)
{ {
mrb_socket_hal_final(mrb); mrb_hal_socket_final(mrb);
} }
+5 -5
View File
@@ -54,13 +54,13 @@
* *
* @param mrb The mruby state to associate with the timer * @param mrb The mruby state to associate with the timer
*/ */
void mrb_task_hal_init(mrb_state *mrb); void mrb_hal_task_init(mrb_state *mrb);
/** /**
* Cleanup timer and interrupt resources * Cleanup timer and interrupt resources
* *
* Called during mruby-task gem finalization. Should clean up all resources * Called during mruby-task gem finalization. Should clean up all resources
* allocated by mrb_task_hal_init(). * allocated by mrb_hal_task_init().
* *
* Requirements: * Requirements:
* - Stop and cleanup platform timer * - Stop and cleanup platform timer
@@ -70,7 +70,7 @@ void mrb_task_hal_init(mrb_state *mrb);
* *
* @param mrb The mruby state to disassociate from the timer * @param mrb The mruby state to disassociate from the timer
*/ */
void mrb_task_hal_final(mrb_state *mrb); void mrb_hal_task_final(mrb_state *mrb);
/** /**
* Enable timer interrupts (exit critical section) * Enable timer interrupts (exit critical section)
@@ -119,7 +119,7 @@ void mrb_task_disable_irq(void);
* *
* @param mrb The mruby state (for context, may be unused) * @param mrb The mruby state (for context, may be unused)
*/ */
void mrb_task_hal_idle_cpu(mrb_state *mrb); void mrb_hal_task_idle_cpu(mrb_state *mrb);
/** /**
* Sleep for specified microseconds in wall-clock time * Sleep for specified microseconds in wall-clock time
@@ -139,7 +139,7 @@ void mrb_task_hal_idle_cpu(mrb_state *mrb);
* @param mrb The mruby state (for context, may be unused) * @param mrb The mruby state (for context, may be unused)
* @param usec Number of microseconds to sleep * @param usec Number of microseconds to sleep
*/ */
void mrb_task_hal_sleep_us(mrb_state *mrb, mrb_int usec); void mrb_hal_task_sleep_us(mrb_state *mrb, mrb_int usec);
/* /*
* Core scheduler function (implemented in task.c, called by HAL) * Core scheduler function (implemented in task.c, called by HAL)
+4 -4
View File
@@ -436,7 +436,7 @@ mrb_task_run(mrb_state *mrb)
if (!t) { if (!t) {
/* If there are tasks waiting or suspended, idle */ /* If there are tasks waiting or suspended, idle */
if (q_waiting_ || q_suspended_) { if (q_waiting_ || q_suspended_) {
mrb_task_hal_idle_cpu(mrb); mrb_hal_task_idle_cpu(mrb);
continue; continue;
} }
/* All tasks are dormant - scheduler done */ /* All tasks are dormant - scheduler done */
@@ -485,7 +485,7 @@ sleep_us_impl(mrb_state *mrb, mrb_int usec)
/* Check if we're in a task context */ /* Check if we're in a task context */
if (mrb->c == mrb->root_c) { if (mrb->c == mrb->root_c) {
/* Not in task context - sleep in real wall-clock time using HAL */ /* Not in task context - sleep in real wall-clock time using HAL */
mrb_task_hal_sleep_us(mrb, usec); mrb_hal_task_sleep_us(mrb, usec);
/* Clear switching flag - we're in root context, not switching to a task */ /* Clear switching flag - we're in root context, not switching to a task */
switching_ = FALSE; switching_ = FALSE;
return; return;
@@ -1105,7 +1105,7 @@ mrb_mruby_task_gem_init(mrb_state *mrb)
struct RClass *task_class; struct RClass *task_class;
/* Initialize HAL (timer and interrupts) */ /* Initialize HAL (timer and interrupts) */
mrb_task_hal_init(mrb); mrb_hal_task_init(mrb);
/* Initialize main task to NULL */ /* Initialize main task to NULL */
mrb->task.main_task = NULL; mrb->task.main_task = NULL;
@@ -1152,5 +1152,5 @@ mrb_mruby_task_gem_final(mrb_state *mrb)
mrb->task.main_task = NULL; mrb->task.main_task = NULL;
} }
mrb_task_hal_final(mrb); mrb_hal_task_final(mrb);
} }