Browse Source

faux.time: faux_timespec_diff() returns bool_t instead int

Serj Kalichev 3 years ago
parent
commit
b756a02ed0
3 changed files with 11 additions and 11 deletions
  1. 1 1
      faux/time.h
  2. 5 5
      faux/time/testc_time.c
  3. 5 5
      faux/time/time.c

+ 1 - 1
faux/time.h

@@ -15,7 +15,7 @@ C_DECL_BEGIN
 
 // Operations for struct timespec
 int faux_timespec_cmp(const struct timespec *val1, const struct timespec *val2);
-int faux_timespec_diff(struct timespec *res,
+bool_t faux_timespec_diff(struct timespec *res,
 	const struct timespec *val1, const struct timespec *val2);
 int faux_timespec_sum(struct timespec *res,
 	const struct timespec *val1, const struct timespec *val2);

+ 5 - 5
faux/time/testc_time.c

@@ -62,9 +62,9 @@ int testc_faux_timespec_diff(void)
 		{.tv_sec = 0, .tv_nsec = 0l},
 		{.tv_sec = 109, .tv_nsec = 999999999l},
 		};
-	int eretval[TNUM2] = {
-		-1,
-		0
+	bool_t eretval[TNUM2] = {
+		BOOL_FALSE,
+		BOOL_TRUE
 		};
 	int eerrno[TNUM2] = {
 		EOVERFLOW,
@@ -76,7 +76,7 @@ int testc_faux_timespec_diff(void)
 	// Diff
 	for (i = 0; i < TNUM2; i++) {
 		struct timespec res = {};
-		int retval = 0;
+		bool_t retval = 0;
 		int err = 0;
 		printf("Test %u:\n", i);
 		printf("val1=%ld:%ld, val2=%ld:%ld\n",
@@ -96,7 +96,7 @@ int testc_faux_timespec_diff(void)
 				i, retval, eretval[i]);
 			ret = -1;
 		}
-		if ((retval < 0) && (err != eerrno[i])) {
+		if (!retval && (err != eerrno[i])) {
 			printf("Test %u errno failed\n", i);
 			ret = -1;
 		}

+ 5 - 5
faux/time/time.c

@@ -50,11 +50,11 @@ int faux_timespec_cmp(const struct timespec *val1, const struct timespec *val2)
  * @param [out] res Result of operation.
  * @param [in] val1 First struct timespec value.
  * @param [in] val2 Second struct timespec value.
- * @return 0 - success or -1 on error.
+ * @return 0 - BOOL_TRUE, BOOL_FALSE on error.
  * @exception EINVAL Invalid arguments value.
  * @exception EOVERFLOW If val2>val1.
  */
-int faux_timespec_diff(struct timespec *res,
+bool_t faux_timespec_diff(struct timespec *res,
 	const struct timespec *val1, const struct timespec *val2)
 {
 	assert(res);
@@ -62,12 +62,12 @@ int faux_timespec_diff(struct timespec *res,
 	assert(val2);
 	if (!res || !val1 || !val2) {
 		errno = EINVAL;
-		return -1;
+		return BOOL_FALSE;
 	}
 
 	if (faux_timespec_cmp(val1, val2) < 0) {
 		errno = EOVERFLOW;
-		return -1;
+		return BOOL_FALSE;
 	}
 
 	res->tv_sec = val1->tv_sec - val2->tv_sec;
@@ -78,7 +78,7 @@ int faux_timespec_diff(struct timespec *res,
 		res->tv_nsec = val1->tv_nsec - val2->tv_nsec;
 	}
 
-	return 0;
+	return BOOL_TRUE;
 }
 
 /** @brief Sum of two time (struct timespec) values.