diff options
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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"); + } } /* |