122 Commits

Author SHA1 Message Date
Asmod4n aea2bbcbe5 add IO#autoclose= and IO#autoclose? 2026-05-14 09:53:18 +02:00
Yukihiro "Matz" Matsumoto 817ec1bd90 Merge pull request #6580 from dearblue/File.basename
Improve `File.basename`
2026-05-08 11:41:36 +09:00
Yukihiro "Matz" Matsumoto 32a27216bb test: add parentheses to method calls on assignment RHS
Preparation for future grammar simplification that may
require parentheses for method calls with arguments on
the right-hand side of assignments.

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-27 14:58:14 +09:00
Yukihiro "Matz" Matsumoto 2813f794a2 mruby-io: rename mruby/ext/io.h to mruby/io.h
Simplify the header path to be consistent with mruby/time.h.
The ext/ subdirectory was unnecessary.

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-11 18:09:11 +09:00
Yukihiro "Matz" Matsumoto 5efd0eeed2 mruby-io: normalize line endings in backtick command test
use chomp to strip line endings from backtick command output, making the
test platform-agnostic. remove unused $crlf variable since line ending
checks are now handled by chomp.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-18 23:34:09 +09:00
Yukihiro "Matz" Matsumoto ee5a6705ee mruby-io: fix cross-platform test compatibility for windows
make symlink operations raise notimplementederror on Windows since
symlinks require special privileges and differ significantly from posix.
similarly, filetest.socket? and filetest.symlink? now raise
notimplementederror on Windows since these file types don't exist in
the same way. the file.chmod test now restores write permissions before
deletion, which is required on Windows to delete read-only files.

all tests already have rescue notimplementederror clauses that skip
gracefully on unsupported platforms.

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-16 23:59:23 +09:00
dearblue 445fe9ba32 Add a test for the File.absolute_path method 2025-09-19 22:43:12 +09:00
dearblue 1f7bc64845 Added test for File.basename 2025-07-21 10:16:38 +09:00
Yukihiro Matz Matsumoto dcd661efb8 File.basename: add support for suffix removal and enhance tests 2025-06-23 22:49:43 +00:00
Yukihiro "Matz" Matsumoto dd2950211c mruby-io/mruby_io_test.c: use -1 for length (means strlen(s)) 2025-03-24 15:19:54 +09:00
dearblue c796729fa8 Add File.absolute_path? method 2025-03-05 22:23:49 +09:00
dearblue f77ebfe102 Reimplementation of File.expand_path method
The reason for this is to fix the following problems

  - Even on non-Windows, drive letter recognition was still being handled.
  - On Windows, paths starting with a slash were not expanded correctly.
  - On Windows, relative paths containing drive letters behaved differently than in CRuby.

Due to reimplementation, the internal methods `File._concat_path`, `File._gethome` and `File._getwd` methods have been removed.
2025-02-26 21:55:25 +09:00
Yukihiro "Matz" Matsumoto e35c027966 Merge pull request #6463 from dearblue/dirname 2025-01-02 21:58:01 +09:00
dearblue 5c91014530 Add level argument to File.dirname
from Ruby-3.1
https://bugs.ruby-lang.org/issues/12194
2025-01-02 18:10:14 +09:00
dearblue ef11cd94e7 Reimplement the File.dirname method
The purpose is as follows:

  - Stop using `mrb_locale_from_utf8()`.
      - Because there is no corresponding `mrb_utf8_from_locale()`.
      - Because on Windows, for example, if the code page is 932 (CP932, likely ShiftJIS), it cannot be distinguished from the second byte 0x5c (\), and returns wrong results.
  - Stop using `dirname(3)`.
      - Because leading consecutive slashes are not truncated.
        For example, if `/////a/b` is given, CRuby returns `/a`, but mruby so far returns `/////a`.
      - Because the `path` argument cannot be passed in an immutable form.
  - Stop using `_splitpath()` in the Windows implementation.
      - Because there is no support for UNC paths with up to 32767 characters.
        ref. https://learn.microsoft.com/ja-jp/dotnet/standard/io/file-path-formats#unc-paths
      - Because modifying the result of paths terminated by a directory separator.
        Previously, for example, `C:/` would return `C:.` instead of `C:/`, and `a/b/` would return `a/b` instead of `a`.
2025-01-02 17:42:40 +09:00
dearblue 3b659f5320 Properly cast the return value of memchr() 2025-01-02 15:34:36 +09:00
dearblue ce1abfb2c9 Change MRB_WITH_IO_PREAD_PWRITE configuration name
Change to `MRB_USE_IO_PREAD_PWRITE` for consistency with mruby configuration macros.
Similarly, `MRB_WITHOUT_IO_PREAD_PWRITE` is changed to `MRB_NO_IO_PREAD_PWRITE`.

The previous names are available for compatibility but are deprecated.
2024-12-12 22:18:34 +09:00
Yukihiro "Matz" Matsumoto 19cb0fc374 Merge pull request #6447 from dearblue/File.expand_path
Fixed `File.expand_path`
2024-12-10 13:54:46 +09:00
dearblue 88e3ce1b58 Fix File.expand_path for Windows
- The inner method `File._gethome` could be read as intending to use the `USERPROFILE` environment variable instead on Windows when the `HOME` environment variable is not available.
    In reality, however, this was not the case.
  - The result of `File.expand_path` should unify path separators with `/`, but it did not.
2024-12-08 10:43:20 +09:00
dearblue 06bb54d380 Improved File.expand_path test in `mruby-io
Since `mruby-io` does not depend on `mruby-env` even for test builds, it is impossible that `ENV` constants are defined.
Therefore, define `MRubyIOTestUtil::ENV_HOME` for alternative use.
2024-12-08 10:43:20 +09:00
dearblue 1326017d1d Omit the _WIN64 definition check
Checking the official MSVC documentation, if `_WIN64` is defined, then `_WIN32` is also defined.
https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros

I could not find any documentation on MinGW, but I assume it is not a problem.
2024-12-07 22:47:28 +09:00
Yukihiro "Matz" Matsumoto 87b358a342 Including header files in include/* by <> 2024-03-26 13:59:59 +09:00
dearblue 7611dc8338 Fixed IO#read with buf.
I hit the following two problems.

  - `io.read(0, buf)` always returned a new empty string object.
  - `io.read(num, buf)` was appending data to the given `buf`.
    This also meant that `buf` was never empty if EOF was reached.
2023-12-16 14:42:52 +09:00
dearblue 88bc8c9144 Add "x" mode option for IO.open
From CRuby 2.6 feature.

This is the "x" mode (`O_EXCL`; exclusive create) of `fopen(3)` introduced in C11.

ref. https://bugs.ruby-lang.org/issues/11258
2023-10-15 16:41:48 +09:00
Yukihiro "Matz" Matsumoto 53de96426a mruby-io/io.c (io_init): File.new should not take blocks 2023-05-23 15:34:37 +09:00
Yukihiro "Matz" Matsumoto c32f7915fb reformat else clause indentation style 2023-05-20 00:21:01 +09:00
Yukihiro "Matz" Matsumoto eea72ec84a fix spaces in the type cast expressions (cosmetic changes) 2023-05-18 23:29:16 +09:00
Yukihiro "Matz" Matsumoto 0529f5fc31 mruby-io/test/file.rb: add tests for File#atime, File#ctime 2023-03-03 13:33:29 +09:00
Yukihiro "Matz" Matsumoto be5266fbe6 mruby-io/test: test gets with RS multiple times; ref #5913 2023-01-23 07:26:40 +09:00
Yukihiro "Matz" Matsumoto b79563af60 mruby-io/test: remove test for internal IO#_read_buf 2022-12-30 13:59:21 +09:00
Yukihiro "Matz" Matsumoto a68b1200c2 mruby-io/test: test IO#ungetc 2022-12-30 13:59:01 +09:00
Yukihiro "Matz" Matsumoto ef0b43d9a1 mruby-io/test/io.rb: specify access mode for IO.{sysopen,open} in tests 2022-12-30 13:58:58 +09:00
Yukihiro "Matz" Matsumoto ba1b12948d mruby-io/io.c: implement _read_buf in C 2022-12-29 11:20:51 +09:00
John Bampton ea8964ef35 ruby: standardize whitespace 2022-10-31 16:25:56 +10:00
take-cheeze bf455fd582 Add IO#getbyte 2021-04-10 19:08:14 +09:00
John Bampton d8622fc68b chore: fix spelling 2021-04-03 19:51:01 +10:00
dearblue 8928bc2dce Initialize all area of struct sockaddr_un
Members of `struct sockaddr_un` are requesting the definitions of `sun_family` and `sun_path`.
https://pubs.opengroup.org/onlinepubs/009696699/basedefs/sys/un.h.html

But the other members are optional and environment dependent.

In fact, other members are defined in the BSD series.
from NetBSD-9.1 <https://github.com/NetBSD/src/blob/da504f75982b244b2288bc9970bbc203bd77a9c1/sys/sys/un.h#L49-L53>

```c
struct  sockaddr_un {
        unsigned char   sun_len;        /* sockaddr len excluding NUL */
        sa_family_t     sun_family;     /* AF_UNIX */
        char    sun_path[104];          /* path name (gag) */
};
```
2021-01-12 21:35:18 +09:00
Yukihiro "Matz" Matsumoto 86dee45f1d Remove meaningless IO.open(1<<32) test. 2020-10-12 18:20:15 +09:00
dearblue 80fe9838d2 Integrate Fixnum class into Integer class
* The `Fixnum` constant is now an alias for the `Integer` class.
* Remove `struct mrb_state::fixnum_class` member.
  If necessary, use `struct mrb_state::integer_class` instead.
2020-10-12 16:21:44 +09:00
KOBAYASHI Shuji ea31878b1f Avoid changing directory in mruby-io test 2020-10-12 16:20:46 +09:00
Yukihiro "Matz" Matsumoto d612344e48 Should not use assert with expressions with side-effect; ref #4981
`assert()` can be completely removed when `NDEBUG` is set.
2020-10-12 16:20:45 +09:00
Yukihiro "Matz" Matsumoto d7e183bfdf Fixed wrong condition in #4981. 2020-10-12 16:20:45 +09:00
Yukihiro "Matz" Matsumoto 33647b904e Avoid snprintf in mruby-io test; ref #4981 2020-10-12 16:20:43 +09:00
Yukihiro "Matz" Matsumoto 47f65a93c5 Remove the temporary file from the AF_UNIX socket test; #4981 2020-10-12 16:20:43 +09:00
Yukihiro "Matz" Matsumoto 8b65e4b73c Add test to ensure #5077 2020-09-13 11:38:06 +09:00
Yukihiro "Matz" Matsumoto 6ba542cd53 Revert part of #5019 (mruby_io_test.c) to honor #4987
The issue was reported by @shuujii.
2020-06-05 17:20:41 +09:00
Hiroshi Mimaki 81d340e042 Merge master. 2020-06-05 12:42:56 +09:00
dearblue ce12ef7e5c Hiding method implementation C functions in mruby-io 2020-06-03 14:12:51 +09:00
Yukihiro "Matz" Matsumoto 5e01674b72 Should not use assert with expressions with side-effect; ref #4981
`assert()` can be completely removed when `NDEBUG` is set.
2020-05-07 09:37:02 +09:00
Yukihiro "Matz" Matsumoto b652a4ff14 Fixed wrong condition in #4981. 2020-05-07 09:36:43 +09:00