Skip to content

Commit 4cc745a

Browse files
committed
fopen: expand supported file modes
Support file modes: r+b, w+b, a+b. Closes #457
1 parent da9f439 commit 4cc745a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

_glua-tests/issues.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,26 @@ function test()
470470
end
471471
test()
472472

473+
-- issue #457
474+
function test()
475+
local file = os.tmpname()
476+
os.remove(file)
477+
assert(io.open(file) == nil)
478+
479+
local fh = io.open(file, 'r+b')
480+
assert(fh == nil)
481+
local fh = io.open(file, 'w+b')
482+
assert(fh ~= nil)
483+
fh:close()
484+
os.remove(file)
485+
assert(io.open(file) == nil)
486+
local fh = io.open(file, 'a+b')
487+
assert(fh ~= nil)
488+
fh:close()
489+
os.remove(file)
490+
end
491+
test()
492+
473493
-- issue #459
474494
function test()
475495
local a, b = io.popen("ls", nil)

iolib.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,8 @@ func ioLines(L *LState) int {
613613
return 1
614614
}
615615

616-
var ioOpenOpions = []string{"r", "rb", "w", "wb", "a", "ab", "r+", "rb+", "w+", "wb+", "a+", "ab+"}
616+
var ioOpenOpions = []string{"r", "rb", "w", "wb", "a", "ab", "r+", "rb+", "w+", "wb+", "a+", "ab+",
617+
"r+b", "w+b", "a+b"}
617618

618619
func ioOpenFile(L *LState) int {
619620
path := L.CheckString(1)
@@ -633,11 +634,11 @@ func ioOpenFile(L *LState) int {
633634
readable = false
634635
case "a", "ab":
635636
mode = os.O_WRONLY | os.O_APPEND | os.O_CREATE
636-
case "r+", "rb+":
637+
case "r+", "rb+", "r+b":
637638
mode = os.O_RDWR
638-
case "w+", "wb+":
639+
case "w+", "wb+", "w+b":
639640
mode = os.O_RDWR | os.O_TRUNC | os.O_CREATE
640-
case "a+", "ab+":
641+
case "a+", "ab+", "a+b":
641642
mode = os.O_APPEND | os.O_RDWR | os.O_CREATE
642643
}
643644
file, err := newFile(L, nil, path, mode, os.FileMode(perm), writable, readable)

0 commit comments

Comments
 (0)