Browse Source

faux.base: faux_rm() returns bool-t instead int

Serj Kalichev 3 years ago
parent
commit
b63d50b4d4
2 changed files with 14 additions and 8 deletions
  1. 13 7
      faux/base/fs.c
  2. 1 1
      faux/faux.h

+ 13 - 7
faux/base/fs.c

@@ -95,24 +95,27 @@ bool_t faux_isdir(const char *path)
  * Function can remove file or directory (recursively).
  *
  * @param [in] path File/directory name.
- * @return 0 - success, < 0 on error.
+ * @return BOOL_TRUE - success, BOOL_FALSE on error.
  */
-int faux_rm(const char *path)
+bool_t faux_rm(const char *path)
 {
 	DIR *dir = NULL;
 	struct dirent *dir_entry = NULL;
 
 	assert(path);
 	if (!path)
-		return -1;
+		return BOOL_FALSE;
 
 	// Common file (not dir)
-	if (!faux_isdir(path))
-		return unlink(path);
+	if (!faux_isdir(path)) {
+		if (unlink(path) < 0)
+			return BOOL_FALSE;
+		return BOOL_TRUE;
+	}
 
 	// Directory
 	if ((dir = opendir(path)) == NULL)
-		return -1;
+		return BOOL_FALSE;
 	while ((dir_entry = readdir(dir))) {
 		if (!strcmp(dir_entry->d_name, ".") ||
 			!strcmp(dir_entry->d_name, ".."))
@@ -121,7 +124,10 @@ int faux_rm(const char *path)
 	}
 	closedir(dir);
 
-	return rmdir(path);
+	if (rmdir(path) < 0)
+		return BOOL_FALSE;
+
+	return BOOL_TRUE;
 }
 
 /** @brief Expand tilde within path due to HOME env var.

+ 1 - 1
faux/faux.h

@@ -88,7 +88,7 @@ ssize_t faux_read_whole_file(const char *path, void **data);
 // Filesystem
 ssize_t faux_filesize(const char *path);
 bool_t faux_isdir(const char *path);
-int faux_rm(const char *path);
+bool_t faux_rm(const char *path);
 char *faux_expand_tilde(const char *path);
 
 C_DECL_END