https://gcc.gnu.org/g:91f59cb35a9e76d9d15273778a3d2e43c91727c5

commit r17-4756-g91f59cb35a9e76d9d15273778a3d2e43c91727c5
Author: Xavier Del Campo Romero <[email protected]>
Date:   Tue Sep 29 15:31:49 2026 +0200

    cobol: Add OPTIONAL arg to posix-errno
    
    It might be desirable for some applications to set errno(5) explicitly.
    However, gcobol did not define any mechanism to assign it.
    
    Therefore, this commit extends libgcobol's posix-errno with an OPTIONAL
    argument with the target value. If the new value is not OMITTED, errno
    is modified accordingly, and the old errno value is returned.
    
    libgcobol/ChangeLog:
    
            * posix/cpy/posix-errno.cpy: Add new OPTIONAL arg.
            * posix/shim/errno.cc (posix_errno): Set errno if required.
            * posix/udf/posix-errno.cbl: Add new OPTIONAL arg.

Diff:
---
 libgcobol/posix/cpy/posix-errno.cpy | 2 ++
 libgcobol/posix/shim/errno.cc       | 7 +++++--
 libgcobol/posix/udf/posix-errno.cbl | 3 +++
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libgcobol/posix/cpy/posix-errno.cpy 
b/libgcobol/posix/cpy/posix-errno.cpy
index d7064e81f2d4..4355e1175b10 100644
--- a/libgcobol/posix/cpy/posix-errno.cpy
+++ b/libgcobol/posix/cpy/posix-errno.cpy
@@ -36,9 +36,11 @@
        Linkage Section.
        77 Return-Value Binary-Long.
        01 Error-Msg PIC X ANY LENGTH.
+       77 New-Value Binary-Long.
 
        Procedure Division
            using Error-Msg
+           optional New-Value
            Returning Return-Value.
        END FUNCTION posix-errno.
         >> POP source format
diff --git a/libgcobol/posix/shim/errno.cc b/libgcobol/posix/shim/errno.cc
index 3849ef851375..c8ee291ec652 100644
--- a/libgcobol/posix/shim/errno.cc
+++ b/libgcobol/posix/shim/errno.cc
@@ -2,6 +2,9 @@
 
 extern "C"
 int
-posix_errno() {
-  return errno;
+posix_errno(int *newval) {
+  int ret = errno;
+  if (newval)
+    errno = *newval;
+  return ret;
 }
diff --git a/libgcobol/posix/udf/posix-errno.cbl 
b/libgcobol/posix/udf/posix-errno.cbl
index 5dd0f1f9cb6b..a12dbfc28812 100644
--- a/libgcobol/posix/udf/posix-errno.cbl
+++ b/libgcobol/posix/udf/posix-errno.cbl
@@ -36,11 +36,14 @@
        Linkage Section.
        77 Return-Value Binary-Long.
        01 Error-Msg PIC X ANY LENGTH.
+       77 New-Value Binary-Long.
 
        Procedure Division
            using Error-Msg
+           optional New-Value
            Returning Return-Value.
        CALL "posix_errno"
+           using New-Value
            returning Return-Value.
        CALL "strerror"
            using by value Return-Value

Reply via email to