Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fopen: expand supported file modes #458

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,26 @@ function test()
end
test()

-- issue #457
function test()
local file = os.tmpname()
os.remove(file)
assert(io.open(file) == nil)

local fh = io.open(file, 'r+b')
assert(fh == nil)
local fh = io.open(file, 'w+b')
assert(fh ~= nil)
fh:close()
os.remove(file)
assert(io.open(file) == nil)
local fh = io.open(file, 'a+b')
assert(fh ~= nil)
fh:close()
os.remove(file)
end
test()

-- issue #459
function test()
local a, b = io.popen("ls", nil)
Expand Down
9 changes: 5 additions & 4 deletions iolib.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ func ioLines(L *LState) int {
return 1
}

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

func ioOpenFile(L *LState) int {
path := L.CheckString(1)
Expand All @@ -633,11 +634,11 @@ func ioOpenFile(L *LState) int {
readable = false
case "a", "ab":
mode = os.O_WRONLY | os.O_APPEND | os.O_CREATE
case "r+", "rb+":
case "r+", "rb+", "r+b":
mode = os.O_RDWR
case "w+", "wb+":
case "w+", "wb+", "w+b":
mode = os.O_RDWR | os.O_TRUNC | os.O_CREATE
case "a+", "ab+":
case "a+", "ab+", "a+b":
mode = os.O_APPEND | os.O_RDWR | os.O_CREATE
}
file, err := newFile(L, nil, path, mode, os.FileMode(perm), writable, readable)
Expand Down
Loading