aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-08-16 20:45:29 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-08-16 22:53:00 +0900
commitf0edcd8283e1aeda9ff2d04926ec8041b421f890 (patch)
treeb0c175f6147262d1a79c08437c99900f5fb6cbe1 /io.c
parent82e480ff40cd41de993b92ddc42ef79a807ff2be (diff)
downloadruby-f0edcd8283e1aeda9ff2d04926ec8041b421f890.tar.gz
Extract platform dependent part as `fdopen_internal`
Diffstat (limited to 'io.c')
-rw-r--r--io.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/io.c b/io.c
index f54f01963f..90b6cc1db0 100644
--- a/io.c
+++ b/io.c
@@ -6966,8 +6966,8 @@ rb_sysopen(VALUE fname, int oflags, mode_t perm)
return fd;
}
-FILE *
-rb_fdopen(int fd, const char *modestr)
+static inline FILE *
+fdopen_internal(int fd, const char *modestr)
{
FILE *file;
@@ -6976,24 +6976,25 @@ rb_fdopen(int fd, const char *modestr)
#endif
file = fdopen(fd, modestr);
if (!file) {
- int e = errno;
-#if defined(__sun)
- if (e == 0) {
- rb_gc();
- errno = 0;
- file = fdopen(fd, modestr);
- }
- else
+#ifdef _WIN32
+ if (errno == 0) errno = EINVAL;
+#elif defined(__sun)
+ if (errno == 0) errno = EMFILE;
#endif
+ }
+ return file;
+}
+
+FILE *
+rb_fdopen(int fd, const char *modestr)
+{
+ FILE *file = fdopen_internal(fd, modestr);
+ if (!file) {
+ int e = errno;
if (rb_gc_for_fd(e)) {
- file = fdopen(fd, modestr);
+ file = fdopen_internal(fd, modestr);
}
if (!file) {
-#ifdef _WIN32
- if (e == 0) e = EINVAL;
-#elif defined(__sun)
- if (e == 0) e = EMFILE;
-#endif
rb_syserr_fail(e, 0);
}
}