1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
--- a/runtime/phobos/std/stdio.d 2019-10-25 12:00:00.000000000 +0900
+++ b/runtime/phobos/std/stdio.d 2019-10-25 12:42:42.000000000 +0900
@@ -1098,6 +1098,14 @@ Throws: `Exception` if the file is not o
import std.conv : to, text;
import std.exception : enforce, errnoEnforce;
+ // Some libc sanitize the whence input (e.g. glibc), but some don't,
+ // e.g. Microsoft runtime crashes on an invalid origin,
+ // and Musl additionally accept SEEK_DATA & SEEK_HOLE (Linux extension).
+ // To provide a consistent behavior cross platform, we use the glibc check
+ // See also https://issues.dlang.org/show_bug.cgi?id=19797
+ enforce(origin == SEEK_SET || origin == SEEK_CUR || origin == SEEK_END,
+ "Invalid `origin` argument passed to `seek`, must be one of: SEEK_SET, SEEK_CUR, SEEK_END");
+
enforce(isOpen, "Attempting to seek() in an unopened file");
version (Windows)
{
@@ -1105,9 +1113,6 @@ Throws: `Exception` if the file is not o
{
alias fseekFun = _fseeki64;
alias off_t = long;
- // Issue 19797
- enforce(origin >= SEEK_SET && origin <= SEEK_END,
- "Could not seek in file `"~_name~"' (Invalid argument)");
}
else
{
@@ -1151,7 +1156,8 @@ Throws: `Exception` if the file is not o
// f.rawWrite("abcdefghijklmnopqrstuvwxyz");
// f.seek(-3, SEEK_END);
// assert(f.readln() == "xyz");
- assertThrown(f.seek(0, 3));
+
+ assertThrown(f.seek(0, ushort.max));
}
/**
|