fixes errno value after failing cxBufferSeek() to be consistently EINVAL

Sun, 13 Apr 2025 11:54:10 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 13 Apr 2025 11:54:10 +0200
changeset 1288
b41ad5d9bcbf
parent 1287
3a3ffc27813f
child 1289
2e8edba252a0

fixes errno value after failing cxBufferSeek() to be consistently EINVAL

fixes #628

CHANGELOG file | annotate | diff | comparison | revisions
docs/Writerside/topics/about.md file | annotate | diff | comparison | revisions
docs/Writerside/topics/buffer.h.md file | annotate | diff | comparison | revisions
src/buffer.c file | annotate | diff | comparison | revisions
--- a/CHANGELOG	Sun Apr 13 11:09:05 2025 +0200
+++ b/CHANGELOG	Sun Apr 13 11:54:10 2025 +0200
@@ -4,6 +4,7 @@
  * adds cxMempoolTransfer() and cxMempoolTransferObject()
  * adds cxListSet()
  * changes grow strategy for the mempory pool to reduce reallocations
+ * fixes errno value after failing cxBufferSeek() to be consistently EINVAL
  * fixes implementation of cxBufferTerminate()
  * fixes allocator arguments for some printf.h functions not being const
  * fixes that cx_tree_search() did not investigate subtrees with equally good distance
--- a/docs/Writerside/topics/about.md	Sun Apr 13 11:09:05 2025 +0200
+++ b/docs/Writerside/topics/about.md	Sun Apr 13 11:54:10 2025 +0200
@@ -31,6 +31,7 @@
 * adds cxMempoolTransfer() and cxMempoolTransferObject()
 * adds cxListSet()
 * changes grow strategy for the mempory pool to reduce reallocations
+* fixes errno value after failing cxBufferSeek() to be consistently EINVAL
 * fixes implementation of cxBufferTerminate()
 * fixes allocator arguments for some printf.h functions not being const
 * fixes that cx_tree_search() did not investigate subtrees with equally good distance
--- a/docs/Writerside/topics/buffer.h.md	Sun Apr 13 11:09:05 2025 +0200
+++ b/docs/Writerside/topics/buffer.h.md	Sun Apr 13 11:54:10 2025 +0200
@@ -227,9 +227,9 @@
 or end (when `whence` is `SEEK_END`) of the buffer.
 
 If the resulting position is negative, or larger than the size (i.e. the first unused byte),
-this function returns non-zero and sets `errno` to `EOVERFLOW`.
+this function returns non-zero and sets `errno` to `EINVAL`.
 
-> Note that the error behavior of `cxBufferSeek()` is not exactly the same as for POSIX `fseek()`.
+> Note that the behavior of `cxBufferSeek()` when seeking beyond the end of the buffer is not exactly the same as for POSIX `fseek()`.
 
 ## Shift Contents
 
--- a/src/buffer.c	Sun Apr 13 11:09:05 2025 +0200
+++ b/src/buffer.c	Sun Apr 13 11:54:10 2025 +0200
@@ -147,11 +147,16 @@
     npos += offset;
 
     if ((offset > 0 && npos < opos) || (offset < 0 && npos > opos)) {
-        errno = EOVERFLOW;
+        // to be compliant with fseek() specification
+        // we return EINVAL on underflow
+        errno = EINVAL;
         return -1;
     }
 
     if (npos > buffer->size) {
+        // not compliant with fseek() specification
+        // but this is the better behavior for CxBuffer
+        errno = EINVAL;
         return -1;
     } else {
         buffer->pos = npos;

mercurial