Added module for system abstraction
[project/luci.git] / src / ffluci / fs.lua
index 5a1cc6b..55da9b8 100644 (file)
@@ -31,14 +31,36 @@ require("lfs")
 -- Returns the content of file
 function readfile(filename)
        local fp = io.open(filename)
+       
        if fp == nil then
                error("Unable to open file for reading: " .. filename)
        end
+       
        local data = fp:read("*a")
        fp:close()
        return data     
 end
 
+-- Returns the content of file as array of lines
+function readfilel(filename)
+       local fp = io.open(filename)
+       local line = ""
+       local data = {}
+               
+       if fp == nil then
+               error("Unable to open file for reading: " .. filename)
+       end
+       
+       while true do
+               line = fp:read()
+               if (line == nil) then break end
+               table.insert(data, line)
+       end     
+       
+       fp:close()
+       return data     
+end
+
 -- Writes given data to a file
 function writefile(filename, data)
        local fp = io.open(filename, "w")