* fixes #18550

* update the manual to reflect reality
This commit is contained in:
Andreas Rumpf 2021-07-21 16:55:50 +02:00 • committed by GitHub
commit 01fc9e58ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 57 additions and 11 deletions

View file

@ -630,8 +630,8 @@ const
""
else:
""
FormatOpen: array[FileMode, string] = [
"rb" & NoInheritFlag, "wb" & NoInheritFlag, "w+b" & NoInheritFlag,
FormatOpen: array[FileMode, cstring] = [
cstring("rb" & NoInheritFlag), "wb" & NoInheritFlag, "w+b" & NoInheritFlag,
"r+b" & NoInheritFlag, "ab" & NoInheritFlag
]
#"rt", "wt", "w+t", "r+t", "at"
@ -678,7 +678,7 @@ proc open*(f: var File, filename: string,
## This throws no exception if the file could not be opened.
##
## The file handle associated with the resulting `File` is not inheritable.
var p = fopen(filename, FormatOpen[mode])
var p = fopen(filename.cstring, FormatOpen[mode])
if p != nil:
var f2 = cast[File](p)
when defined(posix) and not defined(nimscript):
@ -711,7 +711,7 @@ proc reopen*(f: File, filename: string, mode: FileMode = fmRead): bool {.
## Default mode is readonly. Returns true if the file could be reopened.
##
## The file handle associated with `f` won't be inheritable.
if freopen(filename, FormatOpen[mode], f) != nil:
if freopen(filename.cstring, FormatOpen[mode], f) != nil:
when not defined(nimInheritHandles) and declared(setInheritable) and
NoInheritFlag.len == 0:
if not setInheritable(getOsFileHandle(f), false):

View file

@ -171,7 +171,7 @@ proc newWideCString*(s: cstring): WideCStringObj =
result = newWideCString(s, s.len)
proc newWideCString*(s: string): WideCStringObj =
result = newWideCString(s, s.len)
result = newWideCString(cstring s, s.len)
proc `$`*(w: WideCString, estimate: int, replacement: int = 0xFFFD): string =
result = newStringOfCap(estimate + estimate shr 2)