From 9e6e39c3512f7a962c44dc3729c98a0f8be90341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Wed, 8 Apr 2020 13:28:13 +0900 Subject: Merge pull request #2991 from shyouhei/ruby.h Split ruby.h --- file.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index e14a658fa9..542a4fc7ee 100644 --- a/file.c +++ b/file.c @@ -11,7 +11,7 @@ **********************************************************************/ -#include "ruby/config.h" +#include "ruby/3/config.h" #ifdef _WIN32 # include "missing/file.h" @@ -682,7 +682,21 @@ rb_stat_mode(VALUE self) static VALUE rb_stat_nlink(VALUE self) { - return UINT2NUM(get_stat(self)->st_nlink); + /* struct stat::st_nlink is nlink_t in POSIX. Not the case for Windows. */ + const struct stat *ptr = get_stat(self); + + if (sizeof(ptr->st_nlink) <= sizeof(int)) { + return UINT2NUM((unsigned)ptr->st_nlink); + } + else if (sizeof(ptr->st_nlink) == sizeof(long)) { + return ULONG2NUM((unsigned long)ptr->st_nlink); + } + else if (sizeof(ptr->st_nlink) == sizeof(LONG_LONG)) { + return ULL2NUM((unsigned LONG_LONG)ptr->st_nlink); + } + else { + rb_bug(":FIXME: don't know what to do"); + } } /* -- cgit v1.2.3