Browse Source

faux.file: faux_file_ functions returns bool_t instead int

Serj Kalichev 3 years ago
parent
commit
061b26ec81
3 changed files with 25 additions and 25 deletions
  1. 3 3
      faux/ini.h
  2. 20 20
      faux/ini/ini.c
  3. 2 2
      faux/ini/testc_ini.c

+ 3 - 3
faux/ini.h

@@ -30,9 +30,9 @@ const char *faux_ini_find(const faux_ini_t *ini, const char *name);
 faux_ini_node_t *faux_ini_iter(const faux_ini_t *ini);
 const faux_pair_t *faux_ini_each(faux_ini_node_t **iter);
 
-int faux_ini_parse_str(faux_ini_t *ini, const char *str);
-int faux_ini_parse_file(faux_ini_t *ini, const char *fn);
-int faux_ini_write_file(const faux_ini_t *ini, const char *fn);
+bool_t faux_ini_parse_str(faux_ini_t *ini, const char *str);
+bool_t faux_ini_parse_file(faux_ini_t *ini, const char *fn);
+bool_t faux_ini_write_file(const faux_ini_t *ini, const char *fn);
 
 C_DECL_END
 

+ 20 - 20
faux/ini/ini.c

@@ -287,9 +287,9 @@ static char *faux_ini_purify_word(const char *str)
  *
  * @param [in] ini Allocated and initialized INI object.
  * @param [in] string String to parse.
- * @return 0 - succes, < 0 - error
+ * @return BOOL_TRUE - succes, BOOL_FALSE - error
  */
-int faux_ini_parse_str(faux_ini_t *ini, const char *string)
+bool_t faux_ini_parse_str(faux_ini_t *ini, const char *string)
 {
 	char *buffer = NULL;
 	char *saveptr = NULL;
@@ -297,9 +297,9 @@ int faux_ini_parse_str(faux_ini_t *ini, const char *string)
 
 	assert(ini);
 	if (!ini)
-		return -1;
+		return BOOL_FALSE;
 	if (!string)
-		return 0;
+		return BOOL_TRUE;
 
 	buffer = faux_str_dup(string);
 	// Now loop though each line
@@ -349,7 +349,7 @@ int faux_ini_parse_str(faux_ini_t *ini, const char *string)
 	}
 	faux_str_free(buffer);
 
-	return 0;
+	return BOOL_TRUE;
 }
 
 
@@ -365,10 +365,10 @@ int faux_ini_parse_str(faux_ini_t *ini, const char *string)
  *
  * @param [in] ini Allocated and initialized INI object.
  * @param [in] string String to parse.
- * @return 0 - succes, < 0 - error
+ * @return BOOL_TRUE - succes, BOOL_FALSE - error
  * @sa faux_ini_parse_str()
  */
-int faux_ini_parse_file(faux_ini_t *ini, const char *fn)
+bool_t faux_ini_parse_file(faux_ini_t *ini, const char *fn)
 {
 	bool_t eof = BOOL_FALSE;
 	faux_file_t *f = NULL;
@@ -377,13 +377,13 @@ int faux_ini_parse_file(faux_ini_t *ini, const char *fn)
 	assert(ini);
 	assert(fn);
 	if (!ini)
-		return -1;
+		return BOOL_FALSE;
 	if (!fn || '\0' == *fn)
-		return -1;
+		return BOOL_FALSE;
 
 	f = faux_file_open(fn, O_RDONLY, 0);
 	if (!f)
-		return -1;
+		return BOOL_FALSE;
 
 	while ((buf = faux_file_getline(f))) {
 		// Don't analyze retval because it's not obvious what
@@ -395,9 +395,9 @@ int faux_ini_parse_file(faux_ini_t *ini, const char *fn)
 	eof = faux_file_eof(f);
 	faux_file_close(f);
 	if (!eof) // File reading was interrupted before EOF
-		return -1;
+		return BOOL_FALSE;
 
-	return 0;
+	return BOOL_TRUE;
 }
 
 
@@ -408,9 +408,9 @@ int faux_ini_parse_file(faux_ini_t *ini, const char *fn)
  *
  * @param [in] ini Allocated and initialized INI object.
  * @param [in] fn File name to write to.
- * @return 0 - success, < 0 - error
+ * @return BOOL_TRUE - success, BOOL_FALSE - error
  */
-int faux_ini_write_file(const faux_ini_t *ini, const char *fn)
+bool_t faux_ini_write_file(const faux_ini_t *ini, const char *fn)
 {
 	faux_file_t *f = NULL;
 	faux_ini_node_t *iter = NULL;
@@ -420,13 +420,13 @@ int faux_ini_write_file(const faux_ini_t *ini, const char *fn)
 	assert(ini);
 	assert(fn);
 	if (!ini)
-		return -1;
+		return BOOL_FALSE;
 	if (!fn || '\0' == *fn)
-		return -1;
+		return BOOL_FALSE;
 
 	f = faux_file_open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0644);
 	if (!f)
-		return -1;
+		return BOOL_FALSE;
 
 	iter = faux_ini_iter(ini);
 	while ((pair = faux_ini_each(&iter))) {
@@ -447,7 +447,7 @@ int faux_ini_write_file(const faux_ini_t *ini, const char *fn)
 			quote_value, value, quote_value);
 		if (!line) {
 			faux_file_close(f);
-			return -1;
+			return BOOL_FALSE;
 		}
 
 		// Write to file
@@ -455,11 +455,11 @@ int faux_ini_write_file(const faux_ini_t *ini, const char *fn)
 		faux_str_free(line);
 		if (bytes_written < 0) { // Can't write to file
 			faux_file_close(f);
-			return -1;
+			return BOOL_FALSE;
 		}
 	}
 
 	faux_file_close(f);
 
-	return 0;
+	return BOOL_TRUE;
 }

+ 2 - 2
faux/ini/testc_ini.c

@@ -58,7 +58,7 @@ int testc_faux_ini_parse_file(void)
 	dst_fn = faux_str_sprintf("%s/dst", getenv(FAUX_TESTC_TMPDIR_ENV));
 
 	ini = faux_ini_new();
-	if (faux_ini_parse_file(ini, src_fn) < 0) {
+	if (!faux_ini_parse_file(ini, src_fn)) {
 		fprintf(stderr, "Can't parse INI file %s\n", src_fn);
 		goto parse_error;
 	}
@@ -69,7 +69,7 @@ int testc_faux_ini_parse_file(void)
 	}
 
 	faux_ini_set(ini, "test space", "lk lk lk ");
-	if (faux_ini_write_file(ini, dst_fn) < 0) {
+	if (!faux_ini_write_file(ini, dst_fn)) {
 		fprintf(stderr, "Can't write INI file %s\n", dst_fn);
 		goto parse_error;
 	}