elua: when using file module's map_all or map_new, prefer a copy by default (safer) but allow also raw with a parameter; and unmap if we're doing a copy

This commit is contained in:
Daniel Kolesa 2014-04-09 16:35:15 +01:00 committed by Daniel Kolesa
parent 957e61c518
commit 9e00121fa4
1 changed files with 12 additions and 4 deletions

View File

@ -350,18 +350,26 @@ M.File = ffi.metatype("Eina_File", {
xattr_get = M.Xattr_Iterator,
xattr_value_get = M.Xattr_Value_Iterator,
map_all = function(self, rule, copy)
map_all = function(self, rule, raw)
local v = ffi.cast("char*", eina.eina_file_map_all(self, rule or 0))
if v == nil then return nil end
if copy then return ffi.string(v) end
if not raw then
local r = ffi.string(v)
self:map_free(v)
return r
end
return v
end,
map_new = function(self, rule, offset, length, copy)
map_new = function(self, rule, offset, length, raw)
local v = ffi.cast("char*", eina.eina_file_map_new(self, rule or 0,
offset or 0, length))
if v == nil then return nil end
if copy then return ffi.string(v, length) end
if not raw then
local r = ffi.string(v, length)
self:map_free(v)
return r
end
return v
end,