Raise SystemCallError exception when these functions return an error.
This changes behavior for the following case (found by the tests):
```ruby
dir1 = Dir.new('..')
dir2 = Dir.for_fd(dir1.fileno)
dir1.close
dir2.close
```
The above code is basically broken, as `dir1.close` closed the file
descriptor. The subsequent `dir2.close` call is undefined behavior.
When run in isolation, it raises Errno::EBADF after the change, but
if another thread opens a file descriptor between the `dir1.close`
and `dir2.close` calls, the `dir2.close` call could close the file
descriptor opened by the other thread. Raising an exception is much
better in this case as it makes it obvious there is a bug in the code.
For the readdir check, since the GVL has already been released,
reacquire it rb_thread_call_with_gvl if an exception needs to be
raised.
Due to the number of closedir calls, this adds static close_dir_data
and check_closedir functions. The close_dir_data takes a
struct dir_data * and handles setting the dir entry to NULL regardless
of failure.
Fixes [Bug #20586]
Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
esent.h is the header for MS essential storage engine (JET) which is not
needed in ruby. basetsd.h has existed since _MSC_VER >= 1200 (VS 6.0)
and is the preferred header to use for WCHAR.
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead. This would significantly
speed up incremental builds.
We take the following inclusion order in this changeset:
1. "ruby/config.h", where _GNU_SOURCE is defined (must be the very
first thing among everything).
2. RUBY_EXTCONF_H if any.
3. Standard C headers, sorted alphabetically.
4. Other system headers, maybe guarded by #ifdef
5. Everything else, sorted alphabetically.
Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
* dir.c (glob_helper): use d_type to reduce lstat system calls.
* win32/dir.h (struct direct): add d_type instead of d_isdir and
d_isrep. SYMLINKD is unreliable, since the target can be
replaced after a link was created.
* win32/win32.c (readdir_internal): set d_type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* dir.c (glob_helper): match patterns against legacy short names
too, not only ordinary names. [ruby-core:67954] [Bug #10819]
* win32/dir.h (struct direct): add short name members.
* win32/win32.c (opendir_internal, readdir_internal): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* win32/win32.c (opendir_internal, rb_w32_opendir): extract and merge
common part of rb_w32_opendir() and rb_w32_uopendir().
* dir.c (do_opendir, glob_helper): encoding.
* dir.c (dir_initialize, do_opendir): convert path to UTF-8 and call
rb_w32_uopendir() instead of rb_w32_opendir() on Windows.
fixes#4491, reported by Joey Zhou.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
read entry with specified enc.
* win32/win32.c (readdir_internal): extract from rb_w32_opendir().
* win32/win32.c (opendir_internal): extract from rb_w32_readdir().
* dir.c (dir_read, dir_each): use new READDIR macro instead of readdir()
to pass enc for special version of readdir, such as above.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
win32/win32.c, win32/win32.h: large file support for win32.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
[ruby-dev:22486]
* pack.c (pack_unpack): unpack requires big endian offet (OFF16B
and OFF32B). The patch is from Minero Aoki in [ruby-dev:22489]
* pack.c (OFF16B): add big-endian offset again.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
[ruby-dev:22476]
* io.c (argf_eof): ARGF.eof? should not have any side effect.
[ruby-dev:22469]
* io.c (argf_each_byte): should return self. [ruby-dev:22465]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e