Skip to content
Snippets Groups Projects
Commit df07f110 authored by Dmitry E. Oboukhov's avatar Dmitry E. Oboukhov
Browse files

Add some tests for fio.dirname, #491

Fix some bugs in the function (now it uses libc's (3) dirname ffi.call).
parent 2ed9a2ed
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ local ffi = require('ffi')
ffi.cdef[[
int umask(int mask);
char *dirname(char *path);
]]
local internal = fio.internal
......@@ -209,18 +210,8 @@ fio.dirname = function(path)
return nil
end
path = tostring(path)
while true do
if path == "" or string.sub(path, -1) == "/" then
break
end
path = string.sub(path, 1, -2)
end
if path == "" then
path = "."
end
return path
path = ffi.new('char[?]', #path, path)
return ffi.string(ffi.C.dirname(path))
end
fio.umask = function(umask)
......
......@@ -286,3 +286,24 @@ fio.unlink(nil)
---
- false
...
-- dirname
fio.dirname('abc')
---
- .
...
fio.dirname('/abc')
---
- /
...
fio.dirname('/abc/cde')
---
- /abc
...
fio.dirname('/abc/cde/')
---
- /abc
...
fio.dirname('/')
---
- /
...
......@@ -97,3 +97,11 @@ fio.rmdir(tmpdir)
fio.unlink()
fio.unlink(nil)
-- dirname
fio.dirname('abc')
fio.dirname('/abc')
fio.dirname('/abc/cde')
fio.dirname('/abc/cde/')
fio.dirname('/')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment