mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
@@ -118,6 +118,8 @@ proc c_setvbuf(f: File, buf: pointer, mode: cint, size: int): cint {.
|
||||
|
||||
proc c_fprintf(f: File, frmt: cstring): cint {.
|
||||
importc: "fprintf", header: "<stdio.h>", varargs, discardable.}
|
||||
proc c_fputc(c: char, f: File): cint {.
|
||||
importc: "fputc", header: "<stdio.h>".}
|
||||
|
||||
## When running nim in android app stdout goes no where, so echo gets ignored
|
||||
## To redreict echo to the android logcat use -d:androidNDK
|
||||
@@ -218,6 +220,10 @@ when defined(windows):
|
||||
var i = c_fprintf(f, "%s", s)
|
||||
while i < s.len:
|
||||
if s[i] == '\0':
|
||||
let w = c_fputc('\0', f)
|
||||
if w != 0:
|
||||
if doRaise: raiseEIO("cannot write string to file")
|
||||
break
|
||||
inc i
|
||||
else:
|
||||
let w = c_fprintf(f, "%s", unsafeAddr s[i])
|
||||
|
||||
@@ -4,7 +4,7 @@ abasdfdsmÄhmaИ
|
||||
Иnastystring
|
||||
A你好
|
||||
ИnastystringA你好
|
||||
ÖÜhmabasdfdsmÄhmaИ'''
|
||||
ÖÜhmabasdfdsmÄhmaИOK'''
|
||||
disabled: "posix"
|
||||
joinable: "false"
|
||||
"""
|
||||
@@ -13,10 +13,10 @@ import winlean
|
||||
|
||||
echo "ÄhmÖÜ"
|
||||
echo "abasdfdsmÄhmaИ"
|
||||
echo "И\0nasty\0\0\0\0string\0"
|
||||
echo "Иnastystring"
|
||||
echo "A你好"
|
||||
|
||||
write stdout, "И\0nasty\0\0\0\0string\0"
|
||||
write stdout, "Иnastystring"
|
||||
writeLine stdout, "A你好"
|
||||
stdout.flushFile()
|
||||
|
||||
@@ -25,3 +25,17 @@ var a = "ÖÜhmabasdfdsmÄhmaИ"
|
||||
var ac = 0'i32
|
||||
discard writeFile(handle, addr a[0], int32(len(a)), addr ac, nil)
|
||||
stdout.flushFile()
|
||||
|
||||
import os
|
||||
|
||||
let str = "some nulls: \0\0\0 (three of them)"
|
||||
|
||||
let fpath = getTempDir() / "file_with_nulls.bin"
|
||||
|
||||
writeFile(fpath, str)
|
||||
|
||||
doAssert(getFileSize(fpath) == 31)
|
||||
doAssert(readFile(fpath) == str)
|
||||
removeFile(fpath)
|
||||
|
||||
echo "OK"
|
||||
|
||||
Reference in New Issue
Block a user