https://gcc.gnu.org/g:d8e3ddc3191f25b9c1412d27c8df55ed709984d4

commit r16-5367-gd8e3ddc3191f25b9c1412d27c8df55ed709984d4
Author: James K. Lowden <[email protected]>
Date:   Mon Nov 17 18:17:00 2025 -0500

    cobol: Correct libgcobol install directory and add components.
    
    Set libgcobol/Makefile.am to define libdir and libsubdir the way libada 
does.
    Reorganize libgcobol/compat directory to group by emulation, not component.
    Move orphan gcc/udf/stored-char-length.cbl to the compat directory.
    Introduce new POSIX bindings.
    
    gcc/cobol/ChangeLog:
            PR cobol/122702
            * Make-lang.in: Move stored-char-length.cbl to libgcobol.
    
    libgcobol/ChangeLog:
            PR cobol/122702
            * Makefile.am: Set libdir and libsubdir per libada example.
            * Makefile.in: Regenerate.
            * compat/README.md: Revise per new directory structure.
            * compat/gnu/lib/CBL_ALLOC_MEM.cbl: Moved from compat/lib/gnu.
            * compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl: Moved from 
compat/lib/gnu.
            * compat/gnu/lib/CBL_DELETE_FILE.cbl: Moved from compat/lib/gnu.
            * compat/gnu/lib/CBL_FREE_MEM.cbl: Moved from compat/lib/gnu.
            * compat/gnu/udf/stored-char-length.cbl: New file.
            * compat/lib/gnu/CBL_ALLOC_MEM.cbl: Moved to compat/gnu/lib.
            * compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl: Moved to compat/gnu/lib.
            * compat/lib/gnu/CBL_DELETE_FILE.cbl: Moved to compat/gnu/lib.
            * compat/lib/gnu/CBL_FREE_MEM.cbl: Moved to compat/gnu/lib.
            * posix/cpy/psx-open.cpy: New file.
            * posix/shim/open.cc: New file.
            * posix/shim/stat.h: Add mode & flag bits for open.cc
            * posix/udf/posix-lseek.cbl: New file.
            * posix/udf/posix-open.cbl: New file.
            * posix/udf/posix-read.cbl: New file.
            * posix/udf/posix-write.cbl: New file.
            * xmlparse.cc: Quell context_t initialization-order warning.

Diff:
---
 gcc/cobol/Make-lang.in                             |  2 -
 libgcobol/Makefile.am                              | 25 +++++--
 libgcobol/Makefile.in                              | 36 ++++++---
 libgcobol/compat/README.md                         |  2 +-
 .../compat/{lib/gnu => gnu/lib}/CBL_ALLOC_MEM.cbl  |  0
 .../{lib/gnu => gnu/lib}/CBL_CHECK_FILE_EXIST.cbl  |  0
 .../{lib/gnu => gnu/lib}/CBL_DELETE_FILE.cbl       |  0
 .../compat/{lib/gnu => gnu/lib}/CBL_FREE_MEM.cbl   |  0
 libgcobol/compat/gnu/udf/stored-char-length.cbl    | 21 ++++++
 libgcobol/posix/cpy/psx-open.cpy                   | 59 +++++++++++++++
 libgcobol/posix/shim/open.cc                       | 87 ++++++++++++++++++++++
 libgcobol/posix/shim/stat.h                        | 44 +++++++++++
 libgcobol/posix/udf/posix-lseek.cbl                | 25 +++++++
 libgcobol/posix/udf/posix-open.cbl                 | 53 +++++++++++++
 libgcobol/posix/udf/posix-read.cbl                 | 26 +++++++
 libgcobol/posix/udf/posix-write.cbl                | 26 +++++++
 libgcobol/xmlparse.cc                              |  2 +-
 17 files changed, 386 insertions(+), 22 deletions(-)

diff --git a/gcc/cobol/Make-lang.in b/gcc/cobol/Make-lang.in
index 9f28752f165e..5fced594d648 100644
--- a/gcc/cobol/Make-lang.in
+++ b/gcc/cobol/Make-lang.in
@@ -301,8 +301,6 @@ cobol.install-common: installdirs
              $(LN) $(GCOBC_INSTALL_NAME)$(exeext) 
$(GCOBC_TARGET_INSTALL_NAME)$(exeext) ); \
          fi; \
        fi
-       mkdir -p $(DESTDIR)$(datadir)/gcobol/udf
-       $(INSTALL_DATA) $(srcdir)/cobol/udf/*   $(DESTDIR)$(datadir)/gcobol/udf/
 
 cobol.install-man: installdirs
        $(INSTALL_DATA) $(srcdir)/cobol/gcobol.1 
$(DESTDIR)$(man1dir)/$(GCOBOL_INSTALL_NAME)$(man1ext)
diff --git a/libgcobol/Makefile.am b/libgcobol/Makefile.am
index c6772a701d6e..53d168747e7e 100644
--- a/libgcobol/Makefile.am
+++ b/libgcobol/Makefile.am
@@ -19,6 +19,17 @@
 
 # Written de novo for libgcobol.
 
+# Standard autoconf-set variables.
+SHELL = @SHELL@
+srcdir = @srcdir@
+libdir = @libdir@
+build = @build@
+target = @target@
+prefix = @prefix@
+
+target_noncanonical = @target_noncanonical@
+version := $(shell @get_gcc_base_ver@ $(srcdir)/../gcc/BASE-VER)
+
 AUTOMAKE_OPTIONS = 1.8 foreign subdir-objects
 ACLOCAL_AMFLAGS = -I .. -I ../config
 
@@ -30,7 +41,8 @@ if BUILD_LIBGCOBOL
 toolexeclib_LTLIBRARIES  = libgcobol.la
 toolexeclib_DATA = libgcobol.spec
 
-libsubincludedir = $(libdir)/gcc/cobol/$(target_noncanonical)/$(gcc_version)
+libsubdir := 
$(libdir)/gcc/$(target_noncanonical)/$(version)$(MULTISUBDIR)/cobol
+libsubincludedir = $(libsubdir)
 
 ##
 ## 2.2.12 Automatic Dependency Tracking
@@ -54,7 +66,7 @@ libgcobol_la_SOURCES =                                \
 
 libgcobol_la_LIBADD = -lxml2
 
-nobase_libsubinclude_HEADERS =                         \
+nobase_libsubinclude_HEADERS =                 \
        posix/cpy/posix-errno.cbl               \
        posix/cpy/statbuf.cpy                   \
        posix/udf/posix-exit.cbl                \
@@ -62,10 +74,11 @@ nobase_libsubinclude_HEADERS =                      \
        posix/udf/posix-mkdir.cbl               \
        posix/udf/posix-stat.cbl                \
        posix/udf/posix-unlink.cbl              \
-       compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl \
-       compat/lib/gnu/CBL_ALLOC_MEM.cbl        \
-       compat/lib/gnu/CBL_DELETE_FILE.cbl      \
-       compat/lib/gnu/CBL_FREE_MEM.cbl
+       compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl \
+       compat/gnu/lib/CBL_ALLOC_MEM.cbl        \
+       compat/gnu/lib/CBL_DELETE_FILE.cbl      \
+       compat/gnu/lib/CBL_FREE_MEM.cbl         \
+       compat/gnu/udf/stored-char-length.cbl
 
 WARN_CFLAGS = -W -Wall -Wwrite-strings
 
diff --git a/libgcobol/Makefile.in b/libgcobol/Makefile.in
index 3dbf310f81a7..864fd3cd163d 100644
--- a/libgcobol/Makefile.in
+++ b/libgcobol/Makefile.in
@@ -184,8 +184,8 @@ am__dirstamp = $(am__leading_dot)dirstamp
 @BUILD_LIBGCOBOL_TRUE@ intrinsic.lo io.lo libgcobol.lo \
 @BUILD_LIBGCOBOL_TRUE@ posix/shim/errno.lo \
 @BUILD_LIBGCOBOL_TRUE@ posix/shim/localtime.lo \
-@BUILD_LIBGCOBOL_TRUE@ posix/shim/stat.lo stringbin.lo \
-@BUILD_LIBGCOBOL_TRUE@ valconv.lo xmlparse.lo
+@BUILD_LIBGCOBOL_TRUE@ posix/shim/open.lo posix/shim/stat.lo \
+@BUILD_LIBGCOBOL_TRUE@ stringbin.lo valconv.lo xmlparse.lo
 libgcobol_la_OBJECTS = $(am_libgcobol_la_OBJECTS)
 @BUILD_LIBGCOBOL_TRUE@am_libgcobol_la_rpath = -rpath $(toolexeclibdir)
 AM_V_P = $(am__v_P_@AM_V@)
@@ -236,11 +236,13 @@ DATA = $(toolexeclib_DATA)
 am__nobase_libsubinclude_HEADERS_DIST = posix/cpy/posix-errno.cbl \
        posix/cpy/statbuf.cpy posix/udf/posix-exit.cbl \
        posix/udf/posix-localtime.cbl posix/udf/posix-mkdir.cbl \
-       posix/udf/posix-stat.cbl posix/udf/posix-unlink.cbl \
-       compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl \
-       compat/lib/gnu/CBL_ALLOC_MEM.cbl \
-       compat/lib/gnu/CBL_DELETE_FILE.cbl \
-       compat/lib/gnu/CBL_FREE_MEM.cbl
+       posix/udf/posix-open.cbl posix/udf/posix-stat.cbl \
+       posix/udf/posix-unlink.cbl \
+       compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl \
+       compat/gnu/lib/CBL_ALLOC_MEM.cbl \
+       compat/gnu/lib/CBL_DELETE_FILE.cbl \
+       compat/gnu/lib/CBL_FREE_MEM.cbl \
+       compat/gnu/udf/stored-char-length.cbl
 HEADERS = $(nobase_libsubinclude_HEADERS)
 am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
        $(LISP)config.h.in
@@ -335,6 +337,8 @@ PATH_SEPARATOR = @PATH_SEPARATOR@
 RANLIB = @RANLIB@
 SED = @SED@
 SET_MAKE = @SET_MAKE@
+
+# Standard autoconf-set variables.
 SHELL = @SHELL@
 SPEC_LIBGCOBOL_DEPS = @SPEC_LIBGCOBOL_DEPS@
 STRIP = @STRIP@
@@ -404,6 +408,7 @@ toolexeclibdir = @toolexeclibdir@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
+version := $(shell @get_gcc_base_ver@ $(srcdir)/../gcc/BASE-VER)
 AUTOMAKE_OPTIONS = 1.8 foreign subdir-objects
 ACLOCAL_AMFLAGS = -I .. -I ../config
 
@@ -413,7 +418,8 @@ gcc_version := $(shell @get_gcc_base_ver@ 
$(top_srcdir)/../gcc/BASE-VER)
 # Skip the whole process if we are not building libgcobol.
 @BUILD_LIBGCOBOL_TRUE@toolexeclib_LTLIBRARIES = libgcobol.la
 @BUILD_LIBGCOBOL_TRUE@toolexeclib_DATA = libgcobol.spec
-@BUILD_LIBGCOBOL_TRUE@libsubincludedir = 
$(libdir)/gcc/cobol/$(target_noncanonical)/$(gcc_version)
+@BUILD_LIBGCOBOL_TRUE@libsubdir := 
$(libdir)/gcc/$(target_noncanonical)/$(version)$(MULTISUBDIR)/cobol
+@BUILD_LIBGCOBOL_TRUE@libsubincludedir = $(libsubdir)
 @BUILD_LIBGCOBOL_TRUE@libgcobol_la_SOURCES = \
 @BUILD_LIBGCOBOL_TRUE@ charmaps.cc                             \
 @BUILD_LIBGCOBOL_TRUE@ constants.cc                            \
@@ -424,6 +430,7 @@ gcc_version := $(shell @get_gcc_base_ver@ 
$(top_srcdir)/../gcc/BASE-VER)
 @BUILD_LIBGCOBOL_TRUE@ libgcobol.cc                            \
 @BUILD_LIBGCOBOL_TRUE@ posix/shim/errno.cc                     \
 @BUILD_LIBGCOBOL_TRUE@ posix/shim/localtime.cc                 \
+@BUILD_LIBGCOBOL_TRUE@ posix/shim/open.cc                      \
 @BUILD_LIBGCOBOL_TRUE@ posix/shim/stat.cc                      \
 @BUILD_LIBGCOBOL_TRUE@ stringbin.cc                            \
 @BUILD_LIBGCOBOL_TRUE@ valconv.cc                              \
@@ -436,12 +443,14 @@ gcc_version := $(shell @get_gcc_base_ver@ 
$(top_srcdir)/../gcc/BASE-VER)
 @BUILD_LIBGCOBOL_TRUE@ posix/udf/posix-exit.cbl                \
 @BUILD_LIBGCOBOL_TRUE@ posix/udf/posix-localtime.cbl           \
 @BUILD_LIBGCOBOL_TRUE@ posix/udf/posix-mkdir.cbl               \
+@BUILD_LIBGCOBOL_TRUE@ posix/udf/posix-open.cbl                \
 @BUILD_LIBGCOBOL_TRUE@ posix/udf/posix-stat.cbl                \
 @BUILD_LIBGCOBOL_TRUE@ posix/udf/posix-unlink.cbl              \
-@BUILD_LIBGCOBOL_TRUE@ compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl \
-@BUILD_LIBGCOBOL_TRUE@ compat/lib/gnu/CBL_ALLOC_MEM.cbl        \
-@BUILD_LIBGCOBOL_TRUE@ compat/lib/gnu/CBL_DELETE_FILE.cbl      \
-@BUILD_LIBGCOBOL_TRUE@ compat/lib/gnu/CBL_FREE_MEM.cbl
+@BUILD_LIBGCOBOL_TRUE@ compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl \
+@BUILD_LIBGCOBOL_TRUE@ compat/gnu/lib/CBL_ALLOC_MEM.cbl        \
+@BUILD_LIBGCOBOL_TRUE@ compat/gnu/lib/CBL_DELETE_FILE.cbl      \
+@BUILD_LIBGCOBOL_TRUE@ compat/gnu/lib/CBL_FREE_MEM.cbl         \
+@BUILD_LIBGCOBOL_TRUE@ compat/gnu/udf/stored-char-length.cbl
 
 @BUILD_LIBGCOBOL_TRUE@WARN_CFLAGS = -W -Wall -Wwrite-strings
 @BUILD_LIBGCOBOL_TRUE@AM_CPPFLAGS = -I. -I posix/shim \
@@ -558,6 +567,8 @@ posix/shim/errno.lo: posix/shim/$(am__dirstamp) \
        posix/shim/$(DEPDIR)/$(am__dirstamp)
 posix/shim/localtime.lo: posix/shim/$(am__dirstamp) \
        posix/shim/$(DEPDIR)/$(am__dirstamp)
+posix/shim/open.lo: posix/shim/$(am__dirstamp) \
+       posix/shim/$(DEPDIR)/$(am__dirstamp)
 posix/shim/stat.lo: posix/shim/$(am__dirstamp) \
        posix/shim/$(DEPDIR)/$(am__dirstamp)
 
@@ -584,6 +595,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlparse.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@posix/shim/$(DEPDIR)/errno.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@posix/shim/$(DEPDIR)/localtime.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@posix/shim/$(DEPDIR)/open.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@posix/shim/$(DEPDIR)/stat.Plo@am__quote@
 
 .cc.o:
diff --git a/libgcobol/compat/README.md b/libgcobol/compat/README.md
index 15f5a0e4731c..8872c713e281 100644
--- a/libgcobol/compat/README.md
+++ b/libgcobol/compat/README.md
@@ -15,7 +15,7 @@ Some of the functions defined here require runtime support 
from libgcobol.
 At the time of this writing, the functions of greatest concern are
 those that are defined by Rocket Software (formerly MicroFocus) and
 emulated by GnuCOBOL. Those are implemented in
-`gcc/cobol/compat/lib/gnu`.  Any calls they would otherwise make to
+`gcc/cobol/compat/gnu/lib`.  Any calls they would otherwise make to
 the C library are effected through COBOL POSIX bindings supplied by
 `gcc/cobol/posix/udf`.
 
diff --git a/libgcobol/compat/lib/gnu/CBL_ALLOC_MEM.cbl 
b/libgcobol/compat/gnu/lib/CBL_ALLOC_MEM.cbl
similarity index 100%
rename from libgcobol/compat/lib/gnu/CBL_ALLOC_MEM.cbl
rename to libgcobol/compat/gnu/lib/CBL_ALLOC_MEM.cbl
diff --git a/libgcobol/compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl 
b/libgcobol/compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl
similarity index 100%
rename from libgcobol/compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl
rename to libgcobol/compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl
diff --git a/libgcobol/compat/lib/gnu/CBL_DELETE_FILE.cbl 
b/libgcobol/compat/gnu/lib/CBL_DELETE_FILE.cbl
similarity index 100%
rename from libgcobol/compat/lib/gnu/CBL_DELETE_FILE.cbl
rename to libgcobol/compat/gnu/lib/CBL_DELETE_FILE.cbl
diff --git a/libgcobol/compat/lib/gnu/CBL_FREE_MEM.cbl 
b/libgcobol/compat/gnu/lib/CBL_FREE_MEM.cbl
similarity index 100%
rename from libgcobol/compat/lib/gnu/CBL_FREE_MEM.cbl
rename to libgcobol/compat/gnu/lib/CBL_FREE_MEM.cbl
diff --git a/libgcobol/compat/gnu/udf/stored-char-length.cbl 
b/libgcobol/compat/gnu/udf/stored-char-length.cbl
new file mode 100644
index 000000000000..2bd07f93c0b0
--- /dev/null
+++ b/libgcobol/compat/gnu/udf/stored-char-length.cbl
@@ -0,0 +1,21 @@
+        >> PUSH source format
+        >>SOURCE format is fixed
+
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+      *  This function is in the public domain.
+      *  Contributed by James K. Lowden of Cobolworx in August 2024
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+        Identification Division.
+        Function-ID. STORED-CHAR-LENGTH.
+        Data Division.
+        Linkage Section.
+        01 Candidate PIC X Any Length.
+        77 Output-Value    PIC 9(8) COMP-5.
+        
+        Procedure Division using Candidate RETURNING Output-Value.
+          Move Function Length( Function Trim(Candidate) )
+            to Output-Value. 
+        End Function STORED-CHAR-LENGTH.
+
+        >> POP source format
\ No newline at end of file
diff --git a/libgcobol/posix/cpy/psx-open.cpy b/libgcobol/posix/cpy/psx-open.cpy
new file mode 100644
index 000000000000..6e5526cf219e
--- /dev/null
+++ b/libgcobol/posix/cpy/psx-open.cpy
@@ -0,0 +1,59 @@
+        >> PUSH source format
+        >>SOURCE format is fixed
+
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+      *  This file is in the public domain.
+      *  Contributed by James K. Lowden of Cobolworx in November 2025.
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+
+      * >>DEFINE O_ACCMODE AS 3
+
+        >>DEFINE O_APPEND      AS     1024
+      * >>DEFINE O_ASYNC                   not used by open(2)
+        >>DEFINE O_CLOEXEC     AS   524288
+        >>DEFINE O_CREAT       AS       64
+        >>DEFINE O_DIRECT      AS    16384 
+        >>DEFINE O_DIRECTORY   AS    65536
+        >>DEFINE O_DSYNC       AS     4096
+        >>DEFINE O_EXCL        AS      128
+        >>DEFINE O_LARGEFILE   AS    32768
+        >>DEFINE O_NOATIME     AS   262144
+        >>DEFINE O_NOCTTY      AS      256
+        >>DEFINE O_NOFOLLOW    AS   131072
+        >>DEFINE O_NONBLOCK    AS     2048
+        >>DEFINE O_PATH        AS  2097152
+        >>DEFINE O_RDONLY      AS        0
+        >>DEFINE O_RDWR        AS        2
+        >>DEFINE O_SYNC        AS  1052672
+        >>DEFINE O_TMPFILE     AS  4194304 + O_DIRECTORY
+        >>DEFINE O_TRUNC       AS      512
+        >>DEFINE O_WRONLY      AS        1
+
+
+      * >>DEFINE S_IFBLK  AS 24576
+      * >>DEFINE S_IFCHR  AS  8192
+      * >>DEFINE S_IFDIR  AS 16384
+      * >>DEFINE S_IFIFO  AS  4096
+      * >>DEFINE S_IFLNK  AS 40960
+      * >>DEFINE S_IFMT   AS 61440
+      * >>DEFINE S_IFREG  AS 32768
+      * >>DEFINE S_IFSOCK AS 49152
+        
+        >>DEFINE S_IRGRP  AS    32
+        >>DEFINE S_IROTH  AS     4
+        >>DEFINE S_IRUSR  AS   256
+        >>DEFINE S_IRWXG  AS    56
+        >>DEFINE S_IRWXO  AS     7
+        >>DEFINE S_IRWXU  AS   448
+        >>DEFINE S_ISGID  AS  1024
+        >>DEFINE S_ISUID  AS  2048
+        >>DEFINE S_ISVTX  AS   512
+        >>DEFINE S_IWGRP  AS    16
+        >>DEFINE S_IWOTH  AS     2
+        >>DEFINE S_IWUSR  AS   128
+        >>DEFINE S_IXGRP  AS     8
+        >>DEFINE S_IXOTH  AS     1
+        >>DEFINE S_IXUSR  AS    64
+
+        >> POP source format
+
diff --git a/libgcobol/posix/shim/open.cc b/libgcobol/posix/shim/open.cc
new file mode 100644
index 000000000000..7207ac951bbe
--- /dev/null
+++ b/libgcobol/posix/shim/open.cc
@@ -0,0 +1,87 @@
+#include <assert.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <map>
+
+#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
+
+extern "C" {
+
+#include "stat.h"
+
+int
+posix_opent(const char *pathname, int cbl_flags, int cbl_mode) {
+
+  static const std::map<int, int> flag_bits {
+    { cbl::PSX_O_RDONLY, O_RDONLY },
+    { cbl::PSX_O_WRONLY, O_WRONLY },
+    { cbl::PSX_O_RDWR, O_RDWR }, 
+    { cbl::PSX_O_CREAT, O_CREAT },
+    { cbl::PSX_O_EXCL, O_EXCL }, 
+    { cbl::PSX_O_NOCTTY, O_NOCTTY }, 
+    { cbl::PSX_O_TRUNC, O_TRUNC },
+    { cbl::PSX_O_APPEND, O_APPEND }, 
+    { cbl::PSX_O_NONBLOCK, O_NONBLOCK },
+    { cbl::PSX_O_DSYNC, O_DSYNC },
+    { cbl::PSX_O_DIRECT, O_DIRECT }, 
+    { cbl::PSX_O_LARGEFILE, O_LARGEFILE }, 
+    { cbl::PSX_O_DIRECTORY, O_DIRECTORY }, 
+    { cbl::PSX_O_NOFOLLOW, O_NOFOLLOW }, 
+    { cbl::PSX_O_NOATIME, O_NOATIME }, 
+    { cbl::PSX_O_CLOEXEC, O_CLOEXEC }, 
+    { cbl::PSX_O_SYNC, O_SYNC }, 
+    { cbl::PSX_O_PATH, O_PATH }, 
+    { cbl::PSX_O_TMPFILE, O_TMPFILE }, 
+  };    
+
+  static const std::map<int, int> mode_bits {
+    { cbl::PSX_S_IXOTH, S_IXOTH }, 
+    { cbl::PSX_S_IWOTH, S_IWOTH }, 
+    { cbl::PSX_S_IROTH, S_IROTH }, 
+    { cbl::PSX_S_IRWXO, S_IRWXO }, 
+    { cbl::PSX_S_IXGRP, S_IXGRP }, 
+    { cbl::PSX_S_IWGRP, S_IWGRP }, 
+    { cbl::PSX_S_IRGRP, S_IRGRP }, 
+    { cbl::PSX_S_IRWXG, S_IRWXG }, 
+    { cbl::PSX_S_IXUSR, S_IXUSR }, 
+    { cbl::PSX_S_IWUSR, S_IWUSR }, 
+    { cbl::PSX_S_IRUSR, S_IRUSR }, 
+    { cbl::PSX_S_IRWXU, S_IRWXU }, 
+    { cbl::PSX_S_ISVTX, S_ISVTX }, 
+    { cbl::PSX_S_ISGID, S_ISGID }, 
+    { cbl::PSX_S_ISUID, S_ISUID }, 
+  };
+  
+  int flags = 0;
+  mode_t mode = 0;
+  
+  for( auto elem : flag_bits ) {
+    int cbl_bit = elem.first;
+    int std_bit = elem.second;
+    
+    if( cbl_bit == (cbl_bit & cbl_flags) ) {
+      flags |= std_bit;
+    }
+  }
+
+  for( auto elem : mode_bits ) {
+    int cbl_bit = elem.first;
+    int std_bit = elem.second;
+    
+    if( cbl_bit == (cbl_bit & cbl_mode) ) {
+      mode |= std_bit;
+    }
+  }
+
+  int erc = open(pathname, flags, mode);
+
+  return erc;
+}
+
+} // extern "C"
diff --git a/libgcobol/posix/shim/stat.h b/libgcobol/posix/shim/stat.h
index 66f103aa9db5..7236c096dbaf 100644
--- a/libgcobol/posix/shim/stat.h
+++ b/libgcobol/posix/shim/stat.h
@@ -40,3 +40,47 @@ struct posix_stat_t {
   cbl::time_t    psx_mtime;      /* Time of last modification */
   cbl::time_t    psx_ctime;      /* Time of last status change */
 };
+
+namespace cbl {
+
+  enum flags_t {
+    PSX_O_RDONLY    =        0,
+    PSX_O_WRONLY    =        1,
+    PSX_O_RDWR      =        2,
+    PSX_O_CREAT     =       64,
+    PSX_O_EXCL      =      128,
+    PSX_O_NOCTTY    =      256,
+    PSX_O_TRUNC     =      512,
+    PSX_O_APPEND    =     1024,
+    PSX_O_NONBLOCK  =     2048,
+    PSX_O_DSYNC     =     4096,
+    PSX_O_DIRECT    =    16384 ,
+    PSX_O_LARGEFILE =    32768,
+    PSX_O_DIRECTORY =    65536,
+    PSX_O_NOFOLLOW  =   131072,
+    PSX_O_NOATIME   =   262144,
+    PSX_O_CLOEXEC   =   524288,
+    PSX_O_SYNC      =  1052672,
+    PSX_O_PATH      =  2097152,
+    PSX_O_TMPFILE   =  4194304 + PSX_O_DIRECTORY,
+  };
+
+  enum open_mode_t {
+    PSX_S_IXOTH =    1,
+    PSX_S_IWOTH =    2,
+    PSX_S_IROTH =    4,
+    PSX_S_IRWXO =    7,
+    PSX_S_IXGRP =    8,
+    PSX_S_IWGRP =   16,
+    PSX_S_IRGRP =   32,
+    PSX_S_IRWXG =   56,
+    PSX_S_IXUSR =   64,
+    PSX_S_IWUSR =  128,
+    PSX_S_IRUSR =  256,
+    PSX_S_IRWXU =  448,
+    PSX_S_ISVTX =  512,
+    PSX_S_ISGID = 1024,
+    PSX_S_ISUID = 2048,
+  };
+
+};
diff --git a/libgcobol/posix/udf/posix-lseek.cbl 
b/libgcobol/posix/udf/posix-lseek.cbl
new file mode 100644
index 000000000000..ec007a92802d
--- /dev/null
+++ b/libgcobol/posix/udf/posix-lseek.cbl
@@ -0,0 +1,25 @@
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+      *  This function is in the public domain.
+      *  Contributed by James K. Lowden of COBOLworx November 2025.
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   
+      *  unsigned long  lseek( int  fd,  unsigned long  offset,  int  whence)
+        Identification Division.
+        Function-ID. posix-lseek.
+        Data Division.
+        Linkage Section.
+          77 Return-Value Binary-Long.
+          01 Lk-fd PIC 9(8) Usage COMP.
+          01 Lk-offset Binary-Long.
+          01 Lk-whence Binary-Long.
+        Procedure Division using
+             By Value Lk-fd,
+             By Value Lk-offset,
+             By Value Lk-whence
+             Returning Return-Value.
+          Call "lseek" using
+             By Value Lk-fd,
+             By Value Lk-offset,
+             By Value Lk-whence
+             Returning Return-Value.
+          Goback.
+        End Function posix-lseek.
diff --git a/libgcobol/posix/udf/posix-open.cbl 
b/libgcobol/posix/udf/posix-open.cbl
new file mode 100644
index 000000000000..efbeeee4b257
--- /dev/null
+++ b/libgcobol/posix/udf/posix-open.cbl
@@ -0,0 +1,53 @@
+       >>PUSH SOURCE FORMAT
+       >>SOURCE FIXED
+      * int open(const char *pathname, int flags);
+        Identification Division.
+        Function-ID. posix-open.
+
+        Environment Division.
+        Configuration Section.
+          Source-Computer. Sesame-Cookie
+        >>IF DEBUGGING-MODE is Defined
+          With Debugging Mode
+        >>END-IF
+          .
+        
+        Data Division.
+        Working-Storage Section.
+          77 Ws-pathname PIC X(8192).
+          77 Ws-mode-ptr Pointer.
+          77 Ws-mode     PIC 9(8) Value 0.
+        Linkage Section.
+          77 Return-Value Binary-Long.
+          01 Lk-pathname PIC X ANY LENGTH.
+          01 Lk-flags    PIC 9(8).
+          01 Lk-mode     PIC 9(8).
+
+        Procedure Division using
+             By Reference Lk-pathname,
+             By Reference Lk-flags,
+             By Reference Optional Lk-mode 
+             Returning Return-Value.
+
+          Move Lk-pathname To Ws-pathname.
+          Inspect Ws-pathname 
+                  Replacing Trailing Space By Low-Value
+
+      D   Display 'posix-open: Ws-pathname ', Ws-pathname.
+      D   Perform Show-Flags.
+
+          Set ws-mode-ptr to Address Of Lk-mode.
+
+          If ws-mode-ptr > 0 Then *> O_CREAT requires mode
+            Move Lk-mode to Ws-mode.
+            
+          Call "posix_open" using Ws-pathname, Lk-flags, Ws-mode, 
+                              Returning Return-Value.
+          Goback.
+
+          Show-Flags Section.
+
+            Display 'Flags: ', Function Hex-Of(Lk-flags).
+
+        End Function posix-open.
+        >> POP SOURCE FORMAT
diff --git a/libgcobol/posix/udf/posix-read.cbl 
b/libgcobol/posix/udf/posix-read.cbl
new file mode 100644
index 000000000000..2c057331da85
--- /dev/null
+++ b/libgcobol/posix/udf/posix-read.cbl
@@ -0,0 +1,26 @@
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+      *  This function is in the public domain.
+      *  Contributed by James K. Lowden of COBOLworx November 2025.
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   
+      *  long  read( int  fd,  void *  buf,  unsigned long  count)
+        Identification Division.
+        Function-ID. posix-read.
+        Data Division.
+        Linkage Section.
+          77 Return-Value Binary-Long.
+          01 Lk-fd PIC 9(8) Usage COMP.
+          01 Lk-buf PIC X ANY LENGTH.
+          01 Lk-count PIC 9(8) Usage COMP.
+        Procedure Division using
+             By Value Lk-fd,
+             By Reference Lk-buf,
+             By Value Lk-count
+             Returning Return-Value.
+
+          Call "read" using
+             By Value Lk-fd,
+             By Reference Lk-buf,
+             By Value Lk-count
+             Returning Return-Value.
+          Goback.
+        End Function posix-read.
diff --git a/libgcobol/posix/udf/posix-write.cbl 
b/libgcobol/posix/udf/posix-write.cbl
new file mode 100644
index 000000000000..e5513402c113
--- /dev/null
+++ b/libgcobol/posix/udf/posix-write.cbl
@@ -0,0 +1,26 @@
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+      *  This function is in the public domain.
+      *  Contributed by James K. Lowden of COBOLworx November 2025.
+      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *   
+      *  long  write( int  fd, const void *  buf,  unsigned long  count)
+        Identification Division.
+        Function-ID. posix-write.
+        Data Division.
+        Linkage Section.
+          77 Return-Value Binary-Long.
+          01 Lk-fd PIC 9(8) Usage COMP.
+          01 Lk-buf PIC X ANY LENGTH.
+          01 Lk-count PIC 9(8) Usage COMP.
+        Procedure Division using
+             By Value Lk-fd,
+             By Reference Lk-buf,
+             By Value Lk-count
+             Returning Return-Value.
+
+          Call "write" using
+             By Value Lk-fd,
+             By Reference Lk-buf,
+             By Value Lk-count
+             Returning Return-Value.
+          Goback.
+        End Function posix-write.
diff --git a/libgcobol/xmlparse.cc b/libgcobol/xmlparse.cc
index 19524307d245..e54245415817 100644
--- a/libgcobol/xmlparse.cc
+++ b/libgcobol/xmlparse.cc
@@ -663,7 +663,7 @@ static class context_t {
   const int priority;
  public:
   xmlParserCtxt * ctxt;
-  context_t() : ctxt(nullptr), priority(LOG_INFO) {
+  context_t() : priority(LOG_INFO), ctxt(nullptr) {
     const int option = LOG_PERROR, facility = LOG_USER;
 #if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
     /* Declared in errno.h, when available.  */

Reply via email to