Extract platform dependent part as `fdopen_internal`

This commit is contained in:
Nobuyoshi Nakada 2023-08-16 20:45:29 +09:00
Родитель 82e480ff40
Коммит f0edcd8283
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 3582D74E1FEE4465
1 изменённых файлов: 17 добавлений и 16 удалений

33
io.c
Просмотреть файл

@ -6966,8 +6966,8 @@ rb_sysopen(VALUE fname, int oflags, mode_t perm)
return fd; return fd;
} }
FILE * static inline FILE *
rb_fdopen(int fd, const char *modestr) fdopen_internal(int fd, const char *modestr)
{ {
FILE *file; FILE *file;
@ -6976,24 +6976,25 @@ rb_fdopen(int fd, const char *modestr)
#endif #endif
file = fdopen(fd, modestr); file = fdopen(fd, modestr);
if (!file) { if (!file) {
int e = errno; #ifdef _WIN32
#if defined(__sun) if (errno == 0) errno = EINVAL;
if (e == 0) { #elif defined(__sun)
rb_gc(); if (errno == 0) errno = EMFILE;
errno = 0;
file = fdopen(fd, modestr);
}
else
#endif #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)) { if (rb_gc_for_fd(e)) {
file = fdopen(fd, modestr); file = fdopen_internal(fd, modestr);
} }
if (!file) { if (!file) {
#ifdef _WIN32
if (e == 0) e = EINVAL;
#elif defined(__sun)
if (e == 0) e = EMFILE;
#endif
rb_syserr_fail(e, 0); rb_syserr_fail(e, 0);
} }
} }