@@ -7860,51 +7860,30 @@ rb_f_select(int argc, VALUE *argv, VALUE obj)
7860
7860
return rb_ensure (select_call , (VALUE )& args , select_end , (VALUE )& args );
7861
7861
}
7862
7862
7863
- struct io_cntl_arg {
7863
+ struct ioctl_arg {
7864
7864
int fd ;
7865
7865
int cmd ;
7866
7866
long narg ;
7867
- int io_p ;
7868
7867
};
7869
7868
7870
- static VALUE nogvl_io_cntl (void * ptr )
7869
+ static VALUE nogvl_ioctl (void * ptr )
7871
7870
{
7872
- st
10000
ruct io_cntl_arg * arg = ptr ;
7871
+ struct ioctl_arg * arg = ptr ;
7873
7872
7874
- if (arg -> io_p )
7875
- return (VALUE )ioctl (arg -> fd , arg -> cmd , arg -> narg );
7876
- else
7877
- #if defined(F_DUPFD )
7878
- if (arg -> cmd == F_DUPFD )
7879
- return (VALUE )rb_cloexec_fcntl_dupfd (arg -> fd , (int )arg -> narg );
7880
- else
7881
- #endif
7882
- return (VALUE )fcntl (arg -> fd , arg -> cmd , arg -> narg );
7873
+ return (VALUE )ioctl (arg -> fd , arg -> cmd , arg -> narg );
7883
7874
}
7884
7875
7885
7876
static int
7886
- io_cntl (int fd , int cmd , long narg , int io_p )
7877
+ do_ioctl (int fd , int cmd , long narg )
7887
7878
{
7888
7879
int retval ;
7889
- struct io_cntl_arg arg ;
7890
-
7891
- #ifndef HAVE_FCNTL
7892
- if (!io_p ) {
7893
- rb_notimplement ();
7894
- }
7895
- #endif
7880
+ struct ioctl_arg arg ;
7896
7881
7897
7882
arg .fd = fd ;
7898
7883
arg .cmd = cmd ;
7899
7884
arg .narg = narg ;
7900
- arg .io_p = io_p ;
7901
7885
7902
- retval = (int )rb_thread_io_blocking_region (nogvl_io_cntl , & arg , fd );
7903
- #if defined(F_DUPFD )
7904
- if (!io_p && retval != -1 && cmd == F_DUPFD ) {
7905
- rb_update_max_fd (retval );
7906
- }
7907
- #endif
7886
+ retval = (int )rb_thread_io_blocking_region (nogvl_ioctl , & arg , fd );
7908
7887
7909
7888
return retval ;
7910
7889
}
@@ -7973,7 +7952,7 @@ setup_narg(int cmd, VALUE *argp, int io_p)
7973
7952
}
7974
7953
7975
7954
static VALUE
7976
- rb_io_ctl (VALUE io , VALUE req , VALUE arg , int io_p )
7955
+ rb_ioctl (VALUE io , VALUE req , VALUE arg )
7977
7956
{
7978
7957
int cmd = NUM2INT (req );
7979
7958
rb_io_t * fptr ;
@@ -7982,28 +7961,17 @@ rb_io_ctl(VALUE io, VALUE req, VALUE arg, int io_p)
7982
7961
7983
7962
rb_secure (2 );
7984
7963
7985
- narg = setup_narg (cmd , & arg , io_p );
7964
+ narg = setup_narg (cmd , & arg , 1 );
7986
7965
GetOpenFile (io , fptr );
7987
- retval = io_cntl (fptr -> fd , cmd , narg , io_p );
7966
+ retval = do_ioctl (fptr -> fd , cmd , narg );
7988
7967
if (retval < 0 ) rb_sys_fail_path (fptr -> pathv );
7989
7968
if (RB_TYPE_P (arg , T_STRING ) && RSTRING_PTR (arg )[RSTRING_LEN (arg )- 1 ] != 17 ) {
7990
7969
rb_raise (rb_eArgError , "return value overflowed string" );
7991
7970
}
7992
7971
7993
- if (!io_p && cmd == F_SETFL ) {
7994
- if (narg & O_NONBLOCK ) {
7995
- fptr -> mode |= FMODE_WSPLIT_INITIALIZED ;
7996
- fptr -> mode &= ~FMODE_WSPLIT ;
7997
- }
7998
- else {
7999
- fptr -> mode &= ~(FMODE_WSPLIT_INITIALIZED |FMODE_WSPLIT );
8000
- }
8001
- }
8002
-
8003
7972
return INT2NUM (retval );
8004
7973
}
8005
7974
8006
-
8007
7975
/*
8008
7976
* call-seq:
8009
7977
* ios.ioctl(integer_cmd, arg) -> integer
@@ -8022,10 +7990,78 @@ rb_io_ioctl(int argc, VALUE *argv, VALUE io)
8022
7990
VALUE req , arg ;
8023
7991
8024
7992
rb_scan_args (argc , argv , "11" , & req , & arg );
8025
- return rb_io_ctl (io , req , arg , 1 );
7993
+ return rb_ioctl (io , req , arg );
8026
7994
}
8027
7995
8028
7996
#ifdef HAVE_FCNTL
7997
+ struct fcntl_arg {
7998
+ int fd ;
7999
+ int cmd ;
8000
+ long narg ;
8001
+ };
8002
+
8003
+ static VALUE nogvl_fcntl (void * ptr )
8004
+ {
8005
+ struct fcntl_arg * arg = ptr ;
8006
+
8007
+ #if defined(F_DUPFD )
8008
+ if (arg -> cmd == F_DUPFD )
8009
+ return (VALUE )rb_cloexec_fcntl_dupfd (arg -> fd , (int )arg -> narg );
8010
+ #endif
8011
+ return (VALUE )fcntl (arg -> fd , arg -> cmd , arg -> narg );
8012
+ }
8013
+
8014
+ static int
8015
+ do_fcntl (int fd , int cmd , long narg )
8016
+ {
8017
+ int retval ;
8018
+ struct fcntl_arg arg ;
8019
+
8020
+ arg .fd = fd ;
8021
+ arg .cmd = cmd ;
8022
+ arg .narg = narg ;
8023
+
8024
+ retval = (int )rb_thread_io_blocking_region (nogvl_fcntl , & arg , fd );
8025
+ #if defined(F_DUPFD )
8026
+ if (retval != -1 && cmd == F_DUPFD ) {
8027
+ rb_update_max_fd (retval );
8028
+ }
8029
+ #endif
8030
+
8031
+ return retval ;
8032
+ }
8033
+
8034
+ static VALUE
8035
+ rb_fcntl (VALUE io , VALUE req , VALUE arg )
8036
+ {
8037
+ int cmd = NUM2INT (req );
8038
+ rb_io_t * fptr ;
8039
+ long narg ;
8040
+ int retval ;
8041
+
8042
+ rb_secure (2 );
8043
+
8044
+ narg = setup_narg (cmd , & arg , 0 );
8045
+ GetOpenFile (io , fptr );
8046
+ retval = do_fcntl (fptr -> fd , cmd , narg );
8047
+ if (retval < 0 ) rb_sys_fail_path (fptr -> pathv );
8048
+ if (RB_TYPE_P (arg , T_STRING ) && RSTRING_PTR (arg )[RSTRING_LEN (arg )- 1 ] != 17 ) {
8049
+ rb_raise (rb_eArgError , "return value overflowed string" );
8050
+ }
8051
+
8052
+ if (cmd == F_SETFL ) {
8053
+ if (narg & O_NONBLOCK ) {
8054
+ fptr -> mode |= FMODE_WSPLIT_INITIALIZED ;
8055
+ fptr -> mode &= ~FMODE_WSPLIT ;
8056
+ }
8057
+ else {
8058
+ fptr -> mode &= ~(FMODE_WSPLIT_INITIALIZED |FMODE_WSPLIT );
8059
+ }
8060
+ }
8061
+
8062
+ return INT2NUM (retval );
8063
+ }
8064
+
8029
8065
/*
8030
8066
* call-seq:
8031
8067
* ios.fcntl(integer_cmd, arg) -> integer
@@ -8045,7 +8081,7 @@ rb_io_fcntl(int argc, VALUE *argv, VALUE io)
8045
8081
VALUE req , arg ;
8046
8082
8047
8083
rb_scan_args (argc , argv , "11" , & req , & arg );
8048
- return rb_io_ctl (io , req , arg , 0 );
8084
+ return rb_fcntl (io , req , arg );
8049
8085
}
8050
8086
#else
8051
8087
#define rb_io_fcntl rb_f_notimplement
0 commit comments