Skip to content

Commit

Permalink
Merge pull request #56 from thotypous/realpath
Browse files Browse the repository at this point in the history
Implement util.realpath
  • Loading branch information
chrox committed Aug 23, 2013
2 parents f888730 + 3df11fb commit 6f8eaea
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ffi/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ struct statvfs {
int __f_spare[6];
};
int statvfs(const char *restrict, struct statvfs *restrict) __attribute__((__nothrow__, __leaf__));
char *realpath(const char *restrict, char *restrict) __attribute__((__nothrow__));
void *malloc(unsigned int) __attribute__((malloc, leaf, nothrow));
void free(void *) __attribute__((nothrow));
]]

local util = {}
Expand All @@ -52,6 +55,16 @@ function util.df(path)
tonumber(statvfs.f_bfree * statvfs.f_bsize)
end

function util.realpath(path)
local path_ptr = ffi.C.realpath(path, nil)
if path_ptr == nil then
return nil
end
path = ffi.string(path_ptr)
ffi.C.free(path_ptr)
return path
end

function util.utf8charcode(charstring)
local ptr = ffi.cast("uint8_t *", charstring)
local len = #charstring
Expand Down

0 comments on commit 6f8eaea

Please sign in to comment.