aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2020-04-08 13:28:13 +0900
committerGitHub <noreply@github.com>2020-04-08 13:28:13 +0900
commit9e6e39c3512f7a962c44dc3729c98a0f8be90341 (patch)
tree901a22676d54d78240e450b64a8cd06eb1703910 /file.c
parent5ac4bf2cd87e1eb5779ca5ae7f96a1a22e8436d9 (diff)
downloadruby-9e6e39c3512f7a962c44dc3729c98a0f8be90341.tar.gz
Merge pull request #2991 from shyouhei/ruby.h
Split ruby.h
Diffstat (limited to 'file.c')
-rw-r--r--file.c18
1 files changed, 16 insertions, 2 deletions
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");
+ }
}
/*