Commit 6e823f88
6e823f8811fbMerged
ydah <[email protected]> · 6 months ago · 5 files · +2 added · ~3 modified
Description
feat(runtime): add File directory predicates
Details
- Commit
- 6e823f8811fb
- Parent
- c3adf401f22e
lib/sp_runtime.hmodifiedView file
@@ -25,6 +25,7 @@
2525
#include <time.h>2626
#include <setjmp.h>2727
#include <errno.h>28+
#include <sys/stat.h>2829
#ifdef _WIN322930
#include <windows.h>3031
#include <process.h>@@ -52,6 +53,12 @@
5253
#ifndef MAP_ANONYMOUS5354
#define MAP_ANONYMOUS MAP_ANON5455
#endif56+
#ifndef S_ISDIR57+
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)58+
#endif59+
#ifndef S_ISREG60+
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)61+
#endif5562
5663
typedef int64_t mrb_int;5764
typedef double mrb_float;@@ -1692,6 +1699,9 @@
16921699
static volatile int sp_catch_top = 0;16931700
static void sp_throw(const char *tag, mrb_int val) { int i = sp_catch_top - 1; while (i >= 0) { if (strcmp(sp_catch_tag[i], tag) == 0) { sp_catch_val[i] = val; sp_catch_top = i + 1; longjmp(sp_catch_stack[i], 1); } i--; } fprintf(stderr, "uncaught throw: %s\n", tag); exit(1); }16941701
1702+
static mrb_bool sp_file_directory(const char *path) { struct stat st; return path && stat(path, &st) == 0 && S_ISDIR(st.st_mode); }1703+
static mrb_bool sp_file_regular(const char *path) { struct stat st; return path && stat(path, &st) == 0 && S_ISREG(st.st_mode); }1704+
16951705
/* Text mode ("r") matches CRuby's File.read: on Windows, CRLF is16961706
normalized to LF on read, which cancels out fopen("w")'s16971707
LF→CRLF on write. Without this, content from File.read passed tospinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
test/file_directory_predicates.rbaddedView file
Loading diff…
test/file_directory_predicates.rb.expectedaddedView file
Loading diff…