]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Correct libgcobol install directory and add components.
authorJames K. Lowden <jklowden@cobolworx.com>
Mon, 17 Nov 2025 23:17:00 +0000 (18:17 -0500)
committerJames K. Lowden <jklowden@cobolworx.com>
Mon, 17 Nov 2025 23:25:50 +0000 (18:25 -0500)
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.

17 files changed:
gcc/cobol/Make-lang.in
libgcobol/Makefile.am
libgcobol/Makefile.in
libgcobol/compat/README.md
libgcobol/compat/gnu/lib/CBL_ALLOC_MEM.cbl [moved from libgcobol/compat/lib/gnu/CBL_ALLOC_MEM.cbl with 100% similarity]
libgcobol/compat/gnu/lib/CBL_CHECK_FILE_EXIST.cbl [moved from libgcobol/compat/lib/gnu/CBL_CHECK_FILE_EXIST.cbl with 100% similarity]
libgcobol/compat/gnu/lib/CBL_DELETE_FILE.cbl [moved from libgcobol/compat/lib/gnu/CBL_DELETE_FILE.cbl with 100% similarity]
libgcobol/compat/gnu/lib/CBL_FREE_MEM.cbl [moved from libgcobol/compat/lib/gnu/CBL_FREE_MEM.cbl with 100% similarity]
libgcobol/compat/gnu/udf/stored-char-length.cbl [new file with mode: 0644]
libgcobol/posix/cpy/psx-open.cpy [new file with mode: 0644]
libgcobol/posix/shim/open.cc [new file with mode: 0644]
libgcobol/posix/shim/stat.h
libgcobol/posix/udf/posix-lseek.cbl [new file with mode: 0644]
libgcobol/posix/udf/posix-open.cbl [new file with mode: 0644]
libgcobol/posix/udf/posix-read.cbl [new file with mode: 0644]
libgcobol/posix/udf/posix-write.cbl [new file with mode: 0644]
libgcobol/xmlparse.cc

index 9f28752f165ee6cd9d8e01bef05162cac3b02c45..5fced594d648e12d1d64497fa54b9b58c2791e1d 100644 (file)
@@ -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)
index c6772a701d6ee51178b2130d31779fe0c043f91f..53d168747e7ec92c819fff679112db0731c6d96b 100644 (file)
 
 # 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
 
index 3dbf310f81a7c4cd831f34792f6c4add81567ec9..864fd3cd163dcc5b5e7aabb9a82915fe2b4b6da3 100644 (file)
@@ -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:
index 15f5a0e4731c5e717df0c61106d47358e34a7253..8872c713e28149de781674669b1182caabcc6a30 100644 (file)
@@ -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/gnu/udf/stored-char-length.cbl b/libgcobol/compat/gnu/udf/stored-char-length.cbl
new file mode 100644 (file)
index 0000000..2bd07f9
--- /dev/null
@@ -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 (file)
index 0000000..6e5526c
--- /dev/null
@@ -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 (file)
index 0000000..7207ac9
--- /dev/null
@@ -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"
index 66f103aa9db55aa668357547cea1cba424b36fac..7236c096dbaf78078756690a3f100b0e26de82d5 100644 (file)
@@ -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 (file)
index 0000000..ec007a9
--- /dev/null
@@ -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 (file)
index 0000000..efbeeee
--- /dev/null
@@ -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 (file)
index 0000000..2c05733
--- /dev/null
@@ -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 (file)
index 0000000..e551340
--- /dev/null
@@ -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.
index 19524307d24539bde168ec7fe7ae0bd9b5214176..e54245415817b0129a5391f83ada2cfc8cc2846a 100644 (file)
@@ -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.  */