summaryrefslogtreecommitdiff
path: root/tests/test-creat.lua
blob: 0c553e5471acb1ad25001dc0ebed97d13c5210bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- See LICENSE file for copyright and license details.
local l = require "luxio"
local sio = require "luxio.simple"

path = "luxio-test-creat-test-file"

local fd, errno = l.creat(path, nil)

if fd == -1 then
	io.stderr:write(("create: %s\n"):format(l.strerror(errno)))
	os.exit(l.EXIT_FAILURE)
end

if l.stat(path) == 0 then
	print(("Successfully created test file %s"):format(path))
end

l.unlink(path)

local mode = sio.tomode("-rw-r--r--")
local fd, errno = l.creat(path, mode)

if fd == -1 then
	io.stderr:write(("creat: %s\n"):format(l.strerror(errno)))
	os.exit(l.EXIT_FAILURE)
end

local r, st = l.stat(path)

if r == 0 and l.bit.band(st['mode'], tonumber(777, 8)) == mode then
	print(("Successfully created test file %s"):format(path))
else
	print("Test failed!")
end

l.unlink(path)