@@ -4203,203 +4203,6 @@ test_check(int n, int argc, VALUE *argv)
42034203 }
42044204}
42054205
4206- #define CHECK (n ) test_check((n), argc, argv)
4207-
4208- /*
4209- * call-seq:
4210- * test(int_cmd, file1 [, file2] ) -> obj
4211- *
4212- * Uses the integer +int_cmd+ to perform various tests on +file1+ (first
4213- * table below) or on +file1+ and +file2+ (second table).
4214- *
4215- * File tests on a single file:
4216- *
4217- * Test Returns Meaning
4218- * "A" | Time | Last access time for file1
4219- * "b" | boolean | True if file1 is a block device
4220- * "c" | boolean | True if file1 is a character device
4221- * "C" | Time | Last change time for file1
4222- * "d" | boolean | True if file1 exists and is a directory
4223- * "e" | boolean | True if file1 exists
4224- * "f" | boolean | True if file1 exists and is a regular file
4225- * "g" | boolean | True if file1 has the \CF{setgid} bit
4226- * | | set (false under NT)
4227- * "G" | boolean | True if file1 exists and has a group
4228- * | | ownership equal to the caller's group
4229- * "k" | boolean | True if file1 exists and has the sticky bit set
4230- * "l" | boolean | True if file1 exists and is a symbolic link
4231- * "M" | Time | Last modification time for file1
4232- * "o" | boolean | True if file1 exists and is owned by
4233- * | | the caller's effective uid
4234- * "O" | boolean | True if file1 exists and is owned by
4235- * | | the caller's real uid
4236- * "p" | boolean | True if file1 exists and is a fifo
4237- * "r" | boolean | True if file1 is readable by the effective
4238- * | | uid/gid of the caller
4239- * "R" | boolean | True if file is readable by the real
4240- * | | uid/gid of the caller
4241- * "s" | int/nil | If file1 has nonzero size, return the size,
4242- * | | otherwise return nil
4243- * "S" | boolean | True if file1 exists and is a socket
4244- * "u" | boolean | True if file1 has the setuid bit set
4245- * "w" | boolean | True if file1 exists and is writable by
4246- * | | the effective uid/gid
4247- * "W" | boolean | True if file1 exists and is writable by
4248- * | | the real uid/gid
4249- * "x" | boolean | True if file1 exists and is executable by
4250- * | | the effective uid/gid
4251- * "X" | boolean | True if file1 exists and is executable by
4252- * | | the real uid/gid
4253- * "z" | boolean | True if file1 exists and has a zero length
4254- *
4255- * Tests that take two files:
4256- *
4257- * "-" | boolean | True if file1 and file2 are identical
4258- * "=" | boolean | True if the modification times of file1
4259- * | | and file2 are equal
4260- * "<" | boolean | True if the modification time of file1
4261- * | | is prior to that of file2
4262- * ">" | boolean | True if the modification time of file1
4263- * | | is after that of file2
4264- */
4265-
4266- static VALUE
4267- rb_f_test (int argc , VALUE * argv )
4268- {
4269- int cmd ;
4270-
4271- if (argc == 0 ) rb_raise (rb_eArgError , "wrong number of arguments (0 for 2..3)" );
4272- cmd = NUM2CHR (argv [0 ]);
4273- if (cmd == 0 ) goto unknown ;
4274- if (strchr ("bcdefgGkloOprRsSuwWxXz" , cmd )) {
4275- CHECK (1 );
4276- switch (cmd ) {
4277- case 'b' :
4278- return rb_file_blockdev_p (0 , argv [1 ]);
4279-
4280- case 'c' :
4281- return rb_file_chardev_p (0 , argv [1 ]);
4282-
4283- case 'd' :
4284- return rb_file_directory_p (0 , argv [1 ]);
4285-
4286- case 'a' :
4287- case 'e' :
4288- return rb_file_exist_p (0 , argv [1 ]);
4289-
4290- case 'f' :
4291- return rb_file_file_p (0 , argv [1 ]);
4292-
4293- case 'g' :
4294- return rb_file_sgid_p (0 , argv [1 ]);
4295-
4296- case 'G' :
4297- return rb_file_grpowned_p (0 , argv [1 ]);
4298-
4299- case 'k' :
4300- return rb_file_sticky_p (0 , argv [1 ]);
4301-
4302- case 'l' :
4303- return rb_file_symlink_p (0 , argv [1 ]);
4304-
4305- case 'o' :
4306- return rb_file_owned_p (0 , argv [1 ]);
4307-
4308- case 'O' :
4309- return rb_file_rowned_p (0 , argv [1 ]);
4310-
4311- case 'p' :
4312- return rb_file_pipe_p (0 , argv [1 ]);
4313-
4314- case 'r' :
4315- return rb_file_readable_p (0 , argv [1 ]);
4316-
4317- case 'R' :
4318- return rb_file_readable_real_p (0 , argv [1 ]);
4319-
4320- case 's' :
4321- return rb_file_size_p (0 , argv [1 ]);
4322-
4323- case 'S' :
4324- return rb_file_socket_p (0 , argv [1 ]);
4325-
4326- case 'u' :
4327- return rb_file_suid_p (0 , argv [1 ]);
4328-
4329- case 'w' :
4330- return rb_file_writable_p (0 , argv [1 ]);
4331-
4332- case 'W' :
4333- return rb_file_writable_real_p (0 , argv [1 ]);
4334-
4335- case 'x' :
4336- return rb_file_executable_p (0 , argv [1 ]);
4337-
4338- case 'X' :
4339- return rb_file_executable_real_p (0 , argv [1 ]);
4340-
4341- case 'z' :
4342- return rb_file_zero_p (0 , argv [1 ]);
4343- }
4344- }
4345-
4346- if (strchr ("MAC" , cmd )) {
4347- struct stat st ;
4348- VALUE fname = argv [1 ];
4349-
4350- CHECK (1 );
4351- if (rb_stat (fname , & st ) == -1 ) {
4352- FilePathValue (fname );
4353- rb_sys_fail (RSTRING_PTR (fname ));
4354- }
4355-
4356- switch (cmd ) {
4357- case 'A' :
4358- return stat_atime (& st );
4359- case 'M' :
4360- return stat_mtime (& st );
4361- case 'C' :
4362- return stat_ctime (& st );
4363- }
4364- }
4365-
4366- if (cmd == '-' ) {
4367- CHECK (2 );
4368- return rb_file_identical_p (0 , argv [1 ], argv [2 ]);
4369- }
4370-
4371- if (strchr ("=<>" , cmd )) {
4372- struct stat st1 , st2 ;
4373-
4374- CHECK (2 );
4375- if (rb_stat (argv [1 ], & st1 ) < 0 ) return Qfalse ;
4376- if (rb_stat (argv [2 ], & st2 ) < 0 ) return Qfalse ;
4377-
4378- switch (cmd ) {
4379- case '=' :
4380- if (st1 .st_mtime == st2 .st_mtime ) return Qtrue ;
4381- return Qfalse ;
4382-
4383- case '>' :
4384- if (st1 .st_mtime > st2 .st_mtime ) return Qtrue ;
4385- return Qfalse ;
4386-
4387- case '<' :
4388- if (st1 .st_mtime < st2 .st_mtime ) return Qtrue ;
4389- return Qfalse ;
4390- }
4391- }
4392- unknown :
4393- /* unknown command */
4394- if (ISPRINT (cmd )) {
4395- rb_raise (rb_eArgError , "unknown command '%s%c'" , cmd == '\'' || cmd == '\\' ? "\\" : "" , cmd );
4396- }
4397- else {
4398- rb_raise (rb_eArgError , "unknown command \"\\x%02X\"" , cmd );
4399- }
4400- return Qnil ; /* not reached */
4401- }
4402-
44034206
44044207/*
44054208 * Document-class: File::Stat
0 commit comments