]> Kevux Git Server - fll/commitdiff
Bugfix: Incorrect documentation and fix return types in f_file_stream_write functions.
authorKevin Day <Kevin@kevux.org>
Sun, 25 Oct 2026 21:32:37 +0000 (16:32 -0500)
committerKevin Day <Kevin@kevux.org>
Sun, 25 Oct 2026 21:32:37 +0000 (16:32 -0500)
Clean up the logic and make it less redundant.
Move the return state logic into the private method.

This allows the reduction of some variables.
This allows the reduction of code.

This is now returning `F_okay_eos` or `F_okay_stop` when it should.
There is no `F_okay_eof` being returned.

Documentation comments are now correct and consistent.

level_0/f_file/c/file/stream.c
level_0/f_file/c/file/stream.h
level_0/f_file/c/private-file.c

index 992f409..359d54e 100644 (file)
@@ -425,24 +425,13 @@ extern "C" {
       return file.stream ? F_data_not : F_stream_not;
     }
 
-    f_status_t status = F_okay;
-
     if (written) {
-      status = private_f_file_stream_write_until(file, buffer, buffer.used, written);
-
-      if (status == F_okay && *written == buffer.used) return F_okay_eos;
-    }
-    else {
-      f_number_unsigned_t written_local = 0;
-
-      status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
-
-      if (status == F_okay && written_local == buffer.used) return F_okay_eos;
+      return private_f_file_stream_write_until(file, buffer, buffer.used, written);
     }
 
-    if (F_status_is_error(status)) return status;
+    f_number_unsigned_t written_local = 0;
 
-    return F_okay;
+    return private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
   }
 #endif // _di_f_file_stream_write_
 
@@ -457,32 +446,13 @@ extern "C" {
       return file.stream ? F_data_not : F_stream_not;
     }
 
-    const f_number_unsigned_t write_max = file.size_write > buffer.used ? buffer.used : file.size_write;
-
-    f_status_t status = F_okay;
-
     if (written) {
-      status = private_f_file_stream_write_until(file, buffer, write_max, written);
-
-      if (status == F_okay) {
-        if (*written == buffer.used) return F_okay_eos;
-        if (*written == write_max) return F_okay_stop;
-      }
-    }
-    else {
-      f_number_unsigned_t written_local = 0;
-
-      status = private_f_file_stream_write_until(file, buffer, write_max, &written_local);
-
-      if (status == F_okay) {
-        if (written_local == buffer.used) return F_okay_eos;
-        if (written_local == write_max) return F_okay_stop;
-      }
+      return private_f_file_stream_write_until(file, buffer, file.size_write > buffer.used ? buffer.used : file.size_write, written);
     }
 
-    if (F_status_is_error(status)) return status;
+    f_number_unsigned_t written_local = 0;
 
-    return F_okay;
+    return private_f_file_stream_write_until(file, buffer, file.size_write > buffer.used ? buffer.used : file.size_write, &written_local);
   }
 #endif // _di_f_file_stream_write_block_
 
@@ -497,32 +467,13 @@ extern "C" {
       return file.stream ? F_data_not : F_stream_not;
     }
 
-    const f_number_unsigned_t write_max = total > buffer.used ? buffer.used : total;
-
-    f_status_t status = F_okay;
-
     if (written) {
-      status = private_f_file_stream_write_until(file, buffer, write_max, written);
-
-      if (status == F_okay) {
-        if (*written == buffer.used) return F_okay_eos;
-        if (*written == write_max) return F_okay_stop;
-      }
-    }
-    else {
-      f_number_unsigned_t written_local = 0;
-
-      status = private_f_file_stream_write_until(file, buffer, buffer.used, &written_local);
-
-      if (status == F_okay) {
-        if (written_local == buffer.used) return F_okay_eos;
-        if (written_local == write_max) return F_okay_stop;
-      }
+      return private_f_file_stream_write_until(file, buffer, total > buffer.used ? buffer.used : total, written);
     }
 
-    if (F_status_is_error(status)) return status;
+    f_number_unsigned_t written_local = 0;
 
-    return F_okay;
+    return private_f_file_stream_write_until(file, buffer, total > buffer.used ? buffer.used : total, &written_local);
   }
 #endif // _di_f_file_stream_write_until_
 
@@ -537,33 +488,15 @@ extern "C" {
       return file.stream ? F_data_not : F_stream_not;
     }
 
-    const f_number_unsigned_t write_max = (range.stop - range.start) + 1 > buffer.used ? buffer.used : (range.stop - range.start) + 1;
-    const f_string_static_t buffer_adjusted = macro_f_string_static_t_initialize_3(buffer.string + range.start, buffer.used - range.start);
-
-    f_status_t status = F_okay;
+    const f_string_static_t adjusted = macro_f_string_static_t_initialize_3(buffer.string + range.start, buffer.used - range.start);
 
     if (written) {
-      status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, written);
-
-      if (status == F_okay) {
-        if (range.start + *written == buffer.used) return F_okay_eos;
-        if (range.start + *written == write_max) return F_okay_stop;
-      }
-    }
-    else {
-      f_number_unsigned_t written_local = 0;
-
-      status = private_f_file_stream_write_until(file, buffer_adjusted, write_max, &written_local);
-
-      if (status == F_okay) {
-        if (range.start + written_local == buffer.used) return F_okay_eos;
-        if (range.start + written_local == write_max) return F_okay_stop;
-      }
+      return private_f_file_stream_write_until(file, adjusted, (range.stop - range.start) + 1 > buffer.used ? buffer.used : (range.stop - range.start) + 1, written);
     }
 
-    if (F_status_is_error(status)) return status;
+    f_number_unsigned_t written_local = 0;
 
-    return F_okay;
+    return private_f_file_stream_write_until(file, adjusted, (range.stop - range.start) + 1 > buffer.used ? buffer.used : (range.stop - range.start) + 1, &written_local);
   }
 #endif // _di_f_file_stream_write_range_
 
index b79ac81..236a6fe 100644 (file)
@@ -403,7 +403,6 @@ extern "C" {
  *
  * @return
  *   F_okay on success.
- *   F_okay_eof when the file stream is at the end of the file.
  *   F_okay_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
  *   F_data_not on success but buffer.used is 0.
  *   F_stream_not if file.stream is NULL.
@@ -413,9 +412,9 @@ extern "C" {
  *
  *   F_file_write (with error bit) on any other error.
  *
- * @see ferror_unlocked()
  * @see flockfile()
  * @see fwrite_unlocked()
+ * @see ferror_unlocked()
  * @see funlockfile()
  */
 #ifndef _di_f_file_stream_write_
@@ -440,20 +439,18 @@ extern "C" {
  *
  * @return
  *   F_okay on success.
- *   F_okay_eof when the file stream is at the end of the file.
- *   F_okay_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
- *   F_data_not on success but buffer.used is 0.
+ *   F_okay_eos on success after reaching the end of the buffer (only wrote up to buffer.used).
+ *   F_okay_stop on success after reaching stopping point (only wrote up to the lesser of total and buffer.used).
+ *   F_data_not on success but either buffer.used or total is 0.
  *   F_stream_not if file.stream is NULL.
  *
  *   F_file_write (with error bit) on error during file write.
  *   F_parameter (with error bit) if a parameter is invalid.
  *
- *   F_file_write (with error bit) on any other error.
- *
- * @see flockfile()
- * @see fwrite_unlocked()
  * @see ferror_unlocked()
+ * @see flockfile()
  * @see funlockfile()
+ * @see fwrite_unlocked()
  */
 #ifndef _di_f_file_stream_write_block_
   extern f_status_t f_file_stream_write_block(const f_file_t file, const f_string_static_t buffer, f_number_unsigned_t * const written);
@@ -477,21 +474,18 @@ extern "C" {
  *
  * @return
  *   F_okay on success.
- *   F_okay_eof when the file stream is at the end of the file.
- *   F_okay_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used).
- *   F_okay_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
+ *   F_okay_eos on success after reaching the end of the buffer (only wrote up to buffer.used).
+ *   F_okay_stop on success after reaching stopping point (only wrote up to the lesser of total and buffer.used).
  *   F_data_not on success but either buffer.used or total is 0.
  *   F_stream_not if file.stream is NULL.
  *
  *   F_file_write (with error bit) on error during file write.
  *   F_parameter (with error bit) if a parameter is invalid.
  *
- *   F_file_write (with error bit) on any other error.
- *
- * @see flockfile()
- * @see fwrite_unlocked()
  * @see ferror_unlocked()
+ * @see flockfile()
  * @see funlockfile()
+ * @see fwrite_unlocked()
  */
 #ifndef _di_f_file_stream_write_until_
   extern f_status_t f_file_stream_write_until(const f_file_t file, const f_string_static_t buffer, const f_number_unsigned_t total, f_number_unsigned_t * const written);
@@ -514,13 +508,17 @@ extern "C" {
  *
  * @return
  *   F_okay on success.
- *   F_okay_stop on success but no data was written (written == 0) (not an error and often happens if file type is not a regular file).
- *   F_okay_eos on success but range.stop exceeded buffer.used (only wrote up to buffer.used).
+ *   F_okay_eos on success after reaching the end of the buffer (only wrote up to buffer.used).
+ *   F_okay_stop on success after reaching stopping point (only wrote up to the lesser of total and buffer.used).
+ *   F_data_not on success but either buffer.used or total is 0.
  *   F_stream_not if file.stream is NULL.
  *
  *   F_file_write (with error bit) on error during file write.
  *   F_parameter (with error bit) if a parameter is invalid.
  *
+ * @see ferror_unlocked()
+ * @see flockfile()
+ * @see funlockfile()
  * @see fwrite_unlocked()
  */
 #ifndef _di_f_file_stream_write_range_
index f336a46..af2995c 100644 (file)
@@ -685,15 +685,14 @@ extern "C" {
 
       *written += size_write * write_amount;
 
-      if (!size_write) {
-        funlockfile(file.stream);
-
-        return F_okay_stop;
-      }
+      if (!size_write) break;
     } // while
 
     funlockfile(file.stream);
 
+    if (*written == buffer.used) return F_okay_eos;
+    if (*written == total) return F_okay_stop;
+
     return F_okay;
   }
 #endif // !defined(_di_f_file_stream_write_) || !defined(_di_f_file_stream_write_block_) || !defined(_di_f_file_stream_write_until) || !defined(_di_f_file_stream_write_range)