+-- wrapper for posix.mkdir
+function mkdir(path, recursive)
+ if recursive then
+ local base = "."
+
+ if path:sub(1,1) == "/" then
+ base = ""
+ path = path:gsub("^/+","")
+ end
+
+ for elem in path:gmatch("([^/]+)/*") do
+ base = base .. "/" .. elem
+
+ local stat = posix.stat( base )
+
+ if not stat then
+ local stat, errmsg, errno = posix.mkdir( base )
+
+ if type(stat) ~= "number" or stat ~= 0 then
+ return stat, errmsg, errno
+ end
+ else
+ if stat.type ~= "directory" then
+ return nil, base .. ": File exists", 17
+ end
+ end
+ end
+
+ return 0
+ else
+ return posix.mkdir( path )
+ end
+end