Fix double initialization of field errno in std/file.d

This commit is contained in:
Razvan Nitu 2021-01-25 14:02:53 +01:00 committed by The Dlang Bot
parent 4919b7e3a8
commit 3dd5df6864

View file

@ -164,6 +164,16 @@ class FileException : Exception
+/ +/
immutable uint errno; immutable uint errno;
private this(in char[] name, in char[] msg, string file, size_t line, uint errno) @safe pure
{
if (msg.empty)
super(name.idup, file, line);
else
super(text(name, ": ", msg), file, line);
this.errno = errno;
}
/++ /++
Constructor which takes an error message. Constructor which takes an error message.
@ -175,12 +185,7 @@ class FileException : Exception
+/ +/
this(in char[] name, in char[] msg, string file = __FILE__, size_t line = __LINE__) @safe pure this(in char[] name, in char[] msg, string file = __FILE__, size_t line = __LINE__) @safe pure
{ {
if (msg.empty) this(name, msg, file, line, 0);
super(name.idup, file, line);
else
super(text(name, ": ", msg), file, line);
errno = 0;
} }
/++ /++
@ -200,7 +205,7 @@ class FileException : Exception
string file = __FILE__, string file = __FILE__,
size_t line = __LINE__) @safe size_t line = __LINE__) @safe
{ {
this(name, sysErrorString(errno), file, line); this(name, sysErrorString(errno), file, line, errno);
} }
else version (Posix) this(in char[] name, else version (Posix) this(in char[] name,
uint errno = .errno, uint errno = .errno,
@ -208,7 +213,7 @@ class FileException : Exception
size_t line = __LINE__) @trusted size_t line = __LINE__) @trusted
{ {
import std.exception : errnoString; import std.exception : errnoString;
this(name, errnoString(errno), file, line); this(name, errnoString(errno), file, line, errno);
} }
} }