diff --git a/posix.ipkg b/posix.ipkg index e7d0818..b34447d 100644 --- a/posix.ipkg +++ b/posix.ipkg @@ -2,6 +2,7 @@ package posix sourcedir = src modules = System.Posix.Directory + , System.Posix.Files , System.Posix.Time , System.Posix.Signal , System.Posix.Syslog @@ -13,6 +14,7 @@ objs = dirent_accessors.c , signal_wrappers.c , syslog_wrappers.c , getcwd_wrapper.c + , files_wrappers.c , create_dir_wrappers.c tests = System.Posix.Test.Syslog.test_syslog diff --git a/src/System/Posix/Files.idr b/src/System/Posix/Files.idr new file mode 100644 index 0000000..7d26327 --- /dev/null +++ b/src/System/Posix/Files.idr @@ -0,0 +1,29 @@ +module System.Posix.Files + +%include C "files_wrappers.c" + +||| Checks if @file exists using access +export +fileExists : String -> IO Bool +fileExists path = map (/= 0) $ foreign FFI_C "idris_file_exists" (String -> IO Int) path + +||| Creates a link from @old to @new +export +createLink : String -> String -> IO () +createLink old new = foreign FFI_C "link" (String -> String -> IO Int) old new *> pure () + +||| Removes a link from @path +export +removeLink : String -> IO () +removeLink path = foreign FFI_C "unlink" (String -> IO Int) path *> pure () + +||| Creates a symbolic named @path2 that contains @path1 +export +createSymbolicLink : String -> String -> IO () +createSymbolicLink path1 path2 = foreign FFI_C + "symlink" (String -> String -> IO Unit) path1 path2 + +||| Changes the name of @old to @new +export +rename : String -> String -> IO () +rename old new = foreign FFI_C "rename" (String -> String -> IO Int) old new *> pure () diff --git a/src/files_wrappers.c b/src/files_wrappers.c new file mode 100644 index 0000000..8dc466d --- /dev/null +++ b/src/files_wrappers.c @@ -0,0 +1,6 @@ +#include + +int idris_file_exists(const char *path) { + // simply check for existence + return access(path, F_OK) == 0; +}