* configure.in: check struct statvfs and struct statvfs.f_fstypename.
* configure.in: on NetBSD fstatfs is obsoleted. * file.c: support NetBSD for File::Statfs. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1782a16e88
commit
559d689ca6
@ -1,3 +1,11 @@
|
|||||||
|
Mon Apr 28 18:06:08 2014 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* configure.in: check struct statvfs and struct statvfs.f_fstypename.
|
||||||
|
|
||||||
|
* configure.in: on NetBSD fstatfs is obsoleted.
|
||||||
|
|
||||||
|
* file.c: support NetBSD for File::Statfs.
|
||||||
|
|
||||||
Mon Apr 28 17:42:42 2014 Narihiro Nakamura <authornari@gmail.com>
|
Mon Apr 28 17:42:42 2014 Narihiro Nakamura <authornari@gmail.com>
|
||||||
|
|
||||||
* gc.c: This argument must be a pointer.
|
* gc.c: This argument must be a pointer.
|
||||||
|
@ -1083,6 +1083,9 @@ main()
|
|||||||
ac_cv_func_shutdown=no
|
ac_cv_func_shutdown=no
|
||||||
ac_cv_func_close=no
|
ac_cv_func_close=no
|
||||||
],
|
],
|
||||||
|
[netbsd*], [ LIBS="-lm $LIBS"
|
||||||
|
ac_cv_func_fstatfs=no
|
||||||
|
],
|
||||||
[dragonfly*], [ LIBS="-lm $LIBS"
|
[dragonfly*], [ LIBS="-lm $LIBS"
|
||||||
# isinf() and isnan() are macros on DragonFly.
|
# isinf() and isnan() are macros on DragonFly.
|
||||||
ac_cv_func_isinf=yes
|
ac_cv_func_isinf=yes
|
||||||
@ -1743,6 +1746,9 @@ AC_CHECK_MEMBERS([struct statfs.f_fstypename], [], [], [@%:@ifdef HAVE_SYS_PARAM
|
|||||||
@%:@ include <sys/vfs.h>
|
@%:@ include <sys/vfs.h>
|
||||||
@%:@endif])
|
@%:@endif])
|
||||||
])
|
])
|
||||||
|
# NetBSD
|
||||||
|
AC_CHECK_TYPES([struct statvfs], [], [], [@%:@ include <sys/statvfs.h>])
|
||||||
|
AC_CHECK_MEMBERS([struct statvfs.f_fstypename], [], [], [@%:@ include <sys/statvfs.h>])
|
||||||
|
|
||||||
AC_CHECK_TYPES([clockid_t], [], [], [@%:@ifdef HAVE_TIME_H
|
AC_CHECK_TYPES([clockid_t], [], [], [@%:@ifdef HAVE_TIME_H
|
||||||
@%:@ include <time.h>
|
@%:@ include <time.h>
|
||||||
@ -1951,6 +1957,7 @@ AC_CHECK_FUNCS(fdatasync)
|
|||||||
AC_CHECK_FUNCS(fmod)
|
AC_CHECK_FUNCS(fmod)
|
||||||
AC_CHECK_FUNCS(fork)
|
AC_CHECK_FUNCS(fork)
|
||||||
AC_CHECK_FUNCS(fstatfs)
|
AC_CHECK_FUNCS(fstatfs)
|
||||||
|
AC_CHECK_FUNCS(fstatvfs)
|
||||||
AC_CHECK_FUNCS(fsync)
|
AC_CHECK_FUNCS(fsync)
|
||||||
AC_CHECK_FUNCS(ftruncate)
|
AC_CHECK_FUNCS(ftruncate)
|
||||||
AC_CHECK_FUNCS(ftruncate64) # used for Win32 platform
|
AC_CHECK_FUNCS(ftruncate64) # used for Win32 platform
|
||||||
|
76
file.c
76
file.c
@ -70,7 +70,14 @@ int flock(int, int);
|
|||||||
#include <sys/vfs.h>
|
#include <sys/vfs.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_STRUCT_STATFS
|
#ifdef HAVE_STRUCT_STATFS
|
||||||
static VALUE rb_statfs_new(const struct statfs *st);
|
typedef struct statfs statfs_t;
|
||||||
|
#elif defined(HAVE_STRUCT_STATVFS)
|
||||||
|
typedef struct statvfs statfs_t;
|
||||||
|
#else
|
||||||
|
# define WITHOUT_STATFS
|
||||||
|
#endif
|
||||||
|
#ifndef WITHOUT_STATFS
|
||||||
|
static VALUE rb_statfs_new(const statfs_t *st);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__native_client__) && defined(NACL_NEWLIB)
|
#if defined(__native_client__) && defined(NACL_NEWLIB)
|
||||||
@ -1099,7 +1106,7 @@ rb_file_lstat(VALUE obj)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_STRUCT_STATFS
|
#ifndef WITHOUT_STATFS
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* ios.statfs -> statfs
|
* ios.statfs -> statfs
|
||||||
@ -1119,17 +1126,18 @@ static VALUE
|
|||||||
rb_io_statfs(VALUE obj)
|
rb_io_statfs(VALUE obj)
|
||||||
{
|
{
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
struct statfs st;
|
statfs_t st;
|
||||||
#ifndef HAVE_FSTATFS
|
#if !defined(HAVE_FSTATFS) && !defined(HAVE_FSTATVFS)
|
||||||
VALUE path;
|
VALUE path;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GetOpenFile(obj, fptr);
|
GetOpenFile(obj, fptr);
|
||||||
#ifdef HAVE_FSTATFS
|
#ifdef HAVE_FSTATFS
|
||||||
if (fstatfs(fptr->fd, &st) == -1)
|
if (fstatfs(fptr->fd, &st) == -1)
|
||||||
|
#elif defined(HAVE_FSTATVFS)
|
||||||
|
if (fstatvfs(fptr->fd, &st) == -1)
|
||||||
#else
|
#else
|
||||||
path = rb_str_encode_ospath(fptr->pathv);
|
if (statfs(StringValueCStr(rb_str_encode_ospath(fptr->pathv)), &st) == -1)
|
||||||
if (statfs(StringValueCStr(path), &st) == -1)
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
rb_sys_fail_path(fptr->pathv);
|
rb_sys_fail_path(fptr->pathv);
|
||||||
@ -5317,13 +5325,13 @@ rb_stat_sticky(VALUE obj)
|
|||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_STRUCT_STATFS
|
#ifndef WITHOUT_STATFS
|
||||||
/* File::Statfs */
|
/* File::Statfs */
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
statfs_memsize(const void *p)
|
statfs_memsize(const void *p)
|
||||||
{
|
{
|
||||||
return p ? sizeof(struct statfs) : 0;
|
return p ? sizeof(statfs_t) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const rb_data_type_t statfs_data_type = {
|
static const rb_data_type_t statfs_data_type = {
|
||||||
@ -5333,28 +5341,28 @@ static const rb_data_type_t statfs_data_type = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
statfs_new_0(VALUE klass, const struct statfs *st)
|
statfs_new_0(VALUE klass, const statfs_t *st)
|
||||||
{
|
{
|
||||||
struct statfs *nst = 0;
|
statfs_t *nst = 0;
|
||||||
|
|
||||||
if (st) {
|
if (st) {
|
||||||
nst = ALLOC(struct statfs);
|
nst = ALLOC(statfs_t);
|
||||||
*nst = *st;
|
*nst = *st;
|
||||||
}
|
}
|
||||||
return TypedData_Wrap_Struct(klass, &statfs_data_type, nst);
|
return TypedData_Wrap_Struct(klass, &statfs_data_type, nst);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_statfs_new(const struct statfs *st)
|
rb_statfs_new(const statfs_t *st)
|
||||||
{
|
{
|
||||||
return statfs_new_0(rb_cStatfs, st);
|
return statfs_new_0(rb_cStatfs, st);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct statfs*
|
static statfs_t*
|
||||||
get_statfs(VALUE self)
|
get_statfs(VALUE self)
|
||||||
{
|
{
|
||||||
struct statfs* st;
|
statfs_t* st;
|
||||||
TypedData_Get_Struct(self, struct statfs, &statfs_data_type, st);
|
TypedData_Get_Struct(self, statfs_t, &statfs_data_type, st);
|
||||||
if (!st) rb_raise(rb_eTypeError, "uninitialized File::Statfs");
|
if (!st) rb_raise(rb_eTypeError, "uninitialized File::Statfs");
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
@ -5388,19 +5396,23 @@ rb_statfs_s_alloc(VALUE klass)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_statfs_init(VALUE obj, VALUE fname)
|
rb_statfs_init(VALUE obj, VALUE fname)
|
||||||
{
|
{
|
||||||
struct statfs st, *nst;
|
statfs_t st, *nst;
|
||||||
|
|
||||||
rb_secure(2);
|
rb_secure(2);
|
||||||
FilePathValue(fname);
|
FilePathValue(fname);
|
||||||
fname = rb_str_encode_ospath(fname);
|
fname = rb_str_encode_ospath(fname);
|
||||||
|
#ifdef HAVE_FSTATFS
|
||||||
if (statfs(StringValueCStr(fname), &st) == -1) {
|
if (statfs(StringValueCStr(fname), &st) == -1) {
|
||||||
|
#elif HAVE_FSTATVFS
|
||||||
|
if (statvfs(StringValueCStr(fname), &st) == -1) {
|
||||||
|
#endif
|
||||||
rb_sys_fail_path(fname);
|
rb_sys_fail_path(fname);
|
||||||
}
|
}
|
||||||
if (DATA_PTR(obj)) {
|
if (DATA_PTR(obj)) {
|
||||||
xfree(DATA_PTR(obj));
|
xfree(DATA_PTR(obj));
|
||||||
DATA_PTR(obj) = NULL;
|
DATA_PTR(obj) = NULL;
|
||||||
}
|
}
|
||||||
nst = ALLOC(struct statfs);
|
nst = ALLOC(statfs_t);
|
||||||
*nst = st;
|
*nst = st;
|
||||||
DATA_PTR(obj) = nst;
|
DATA_PTR(obj) = nst;
|
||||||
|
|
||||||
@ -5411,7 +5423,7 @@ rb_statfs_init(VALUE obj, VALUE fname)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_statfs_init_copy(VALUE copy, VALUE orig)
|
rb_statfs_init_copy(VALUE copy, VALUE orig)
|
||||||
{
|
{
|
||||||
struct statfs *nst;
|
statfs_t *nst;
|
||||||
|
|
||||||
if (!OBJ_INIT_COPY(copy, orig)) return copy;
|
if (!OBJ_INIT_COPY(copy, orig)) return copy;
|
||||||
if (DATA_PTR(copy)) {
|
if (DATA_PTR(copy)) {
|
||||||
@ -5419,14 +5431,15 @@ rb_statfs_init_copy(VALUE copy, VALUE orig)
|
|||||||
DATA_PTR(copy) = 0;
|
DATA_PTR(copy) = 0;
|
||||||
}
|
}
|
||||||
if (DATA_PTR(orig)) {
|
if (DATA_PTR(orig)) {
|
||||||
nst = ALLOC(struct statfs);
|
nst = ALLOC(statfs_t);
|
||||||
*nst = *(struct statfs*)DATA_PTR(orig);
|
*nst = *(statfs_t*)DATA_PTR(orig);
|
||||||
DATA_PTR(copy) = nst;
|
DATA_PTR(copy) = nst;
|
||||||
}
|
}
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_STRUCT_STATFS
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* st.type -> fixnum
|
* st.type -> fixnum
|
||||||
@ -5444,6 +5457,9 @@ statfs_type(VALUE self)
|
|||||||
{
|
{
|
||||||
return LL2NUM(get_statfs(self)->f_type);
|
return LL2NUM(get_statfs(self)->f_type);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
#define statfs_type rb_f_notimplement
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
@ -5529,7 +5545,7 @@ statfs_ffree(VALUE self)
|
|||||||
return LL2NUM(get_statfs(self)->f_ffree);
|
return LL2NUM(get_statfs(self)->f_ffree);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_STRUCT_STATFS_F_FSTYPENAME
|
#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* st.fstypename -> string
|
* st.fstypename -> string
|
||||||
@ -5569,17 +5585,23 @@ statfs_fstypename(VALUE self)
|
|||||||
static VALUE
|
static VALUE
|
||||||
statfs_inspect(VALUE self)
|
statfs_inspect(VALUE self)
|
||||||
{
|
{
|
||||||
struct statfs*st = get_statfs(self);
|
statfs_t *st = get_statfs(self);
|
||||||
return rb_sprintf("#<%"PRIsVALUE" type=%ld"
|
return rb_sprintf("#<%"PRIsVALUE" "
|
||||||
#ifdef HAVE_STRUCT_STATFS_F_FSTYPENAME
|
#ifdef HAVE_STRUCT_STATFS
|
||||||
|
"type=%ld"
|
||||||
|
#endif
|
||||||
|
#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
|
||||||
"(%s)"
|
"(%s)"
|
||||||
#endif
|
#endif
|
||||||
", bsize=%ld"
|
", bsize=%ld"
|
||||||
", blocks=%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d"
|
", blocks=%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d"
|
||||||
", files=%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d"
|
", files=%"PRI_LL_PREFIX"d/%"PRI_LL_PREFIX"d"
|
||||||
">",
|
">",
|
||||||
rb_obj_class(self), (long)st->f_type,
|
rb_obj_class(self),
|
||||||
#ifdef HAVE_STRUCT_STATFS_F_FSTYPENAME
|
#ifdef HAVE_STRUCT_STATFS
|
||||||
|
(long)st->f_type,
|
||||||
|
#endif
|
||||||
|
#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
|
||||||
st->f_fstypename,
|
st->f_fstypename,
|
||||||
#endif
|
#endif
|
||||||
(long)st->f_bsize,
|
(long)st->f_bsize,
|
||||||
@ -6173,7 +6195,7 @@ Init_File(void)
|
|||||||
rb_define_method(rb_cStat, "setgid?", rb_stat_sgid, 0);
|
rb_define_method(rb_cStat, "setgid?", rb_stat_sgid, 0);
|
||||||
rb_define_method(rb_cStat, "sticky?", rb_stat_sticky, 0);
|
rb_define_method(rb_cStat, "sticky?", rb_stat_sticky, 0);
|
||||||
|
|
||||||
#ifdef HAVE_STRUCT_STATFS
|
#ifndef WITHOUT_STATFS
|
||||||
rb_cStatfs = rb_define_class_under(rb_cFile, "Statfs", rb_cObject);
|
rb_cStatfs = rb_define_class_under(rb_cFile, "Statfs", rb_cObject);
|
||||||
rb_define_alloc_func(rb_cStatfs, rb_statfs_s_alloc);
|
rb_define_alloc_func(rb_cStatfs, rb_statfs_s_alloc);
|
||||||
rb_define_method(rb_cStatfs, "initialize", rb_statfs_init, 1);
|
rb_define_method(rb_cStatfs, "initialize", rb_statfs_init, 1);
|
||||||
|
@ -389,7 +389,10 @@ class TestFile < Test::Unit::TestCase
|
|||||||
open(__FILE__) do |f|
|
open(__FILE__) do |f|
|
||||||
st = f.statfs
|
st = f.statfs
|
||||||
assert_kind_of File::Statfs, st
|
assert_kind_of File::Statfs, st
|
||||||
assert_kind_of Integer, st.type
|
begin
|
||||||
|
assert_kind_of Integer, st.type
|
||||||
|
rescue NotImplementedError
|
||||||
|
end
|
||||||
assert_kind_of Integer, st.bsize
|
assert_kind_of Integer, st.bsize
|
||||||
assert_kind_of Integer, st.blocks
|
assert_kind_of Integer, st.blocks
|
||||||
assert_kind_of Integer, st.bfree
|
assert_kind_of Integer, st.bfree
|
||||||
|
Loading…
x
Reference in New Issue
Block a user