From b314391144e95fe8504de5bfef96872da327e58b Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 00:48:03 -0800 Subject: [PATCH 01/52] Removed XDR configuration options We are removing XDR from the library, so the configuration options are being removed and the library's version of XDR will always be used. Removes: Autotools: --enable-hdf4-xdr CMake: HDF4_BUILD_XDR_LIB --- .github/workflows/autotools.yml | 22 ------- .github/workflows/hdfeos2.yml | 2 +- .github/workflows/intel-auto.yml | 1 - .github/workflows/main-auto.yml | 7 +-- .github/workflows/main-cmake.yml | 8 --- .github/workflows/ppc64.yml | 2 +- CMakeLists.txt | 40 ++---------- CMakePresets.json | 1 - config/cmake/FindXDR.cmake | 47 -------------- config/cmake/h4config.h.in | 6 -- config/cmake/hdf4-config.cmake.in | 1 - config/cmake/scripts/HDF4options.cmake | 4 -- config/commence.am | 4 +- configure.ac | 86 -------------------------- mfhdf/Makefile.am | 6 -- mfhdf/dumper/CMakeLists.txt | 4 +- mfhdf/hdfimport/CMakeLists.txt | 4 +- mfhdf/hdiff/CMakeLists.txt | 4 +- mfhdf/hrepack/CMakeLists.txt | 8 +-- mfhdf/libsrc/CMakeLists.txt | 12 ++-- mfhdf/libsrc/local_nc.h | 27 +------- mfhdf/ncdump/CMakeLists.txt | 8 +-- mfhdf/ncgen/CMakeLists.txt | 4 +- mfhdf/nctest/CMakeLists.txt | 2 +- mfhdf/test/CMakeTests.cmake | 66 ++++++++++---------- mfhdf/test/Makefile.am | 2 - mfhdf/xdr/xdrtest.c | 6 +- release_notes/INSTALL | 9 --- release_notes/INSTALL_CMake.txt | 3 - release_notes/RELEASE.txt | 11 ++++ 30 files changed, 75 insertions(+), 332 deletions(-) delete mode 100644 config/cmake/FindXDR.cmake diff --git a/.github/workflows/autotools.yml b/.github/workflows/autotools.yml index c98abc3422..0105e7bb43 100644 --- a/.github/workflows/autotools.yml +++ b/.github/workflows/autotools.yml @@ -11,29 +11,10 @@ permissions: # in parallel. We just have one job, but the matrix items defined below will # run in parallel. jobs: - call-workflow-xdr-autotools: - name: "Autotools XDR Workflows" - uses: ./.github/workflows/main-auto.yml - with: - xdr: enable - netcdf: enable - shared: enable - build_mode: "production" - - call-system-xdr-autotools: - name: "Autotools System XDR Workflows" - uses: ./.github/workflows/main-auto.yml - with: - xdr: disable - netcdf: enable - shared: enable - build_mode: "production" - call-debug-netcdf-autotools: name: "Autotools Debug NetCDF Workflows" uses: ./.github/workflows/main-auto.yml with: - xdr: enable netcdf: enable shared: enable build_mode: "debug" @@ -42,7 +23,6 @@ jobs: name: "Autotools Release NetCDF Workflows" uses: ./.github/workflows/main-auto.yml with: - xdr: enable netcdf: enable shared: enable build_mode: "production" @@ -52,7 +32,6 @@ jobs: uses: ./.github/workflows/main-auto.yml with: netcdf: disable - xdr: enable shared: disable build_mode: "debug" @@ -61,7 +40,6 @@ jobs: uses: ./.github/workflows/main-auto.yml with: netcdf: disable - xdr: enable shared: disable build_mode: "production" diff --git a/.github/workflows/hdfeos2.yml b/.github/workflows/hdfeos2.yml index 0418899580..3a3983008a 100644 --- a/.github/workflows/hdfeos2.yml +++ b/.github/workflows/hdfeos2.yml @@ -16,7 +16,7 @@ jobs: - name: Install HDF4 run: | ./autogen.sh - ./configure --prefix=/usr/local --enable-shared --enable-hdf4-xdr -disable-fortran --disable-netcdf + ./configure --prefix=/usr/local --enable-shared --disable-fortran --disable-netcdf make sudo make install - name: Install HDF-EOS2 diff --git a/.github/workflows/intel-auto.yml b/.github/workflows/intel-auto.yml index ecf0573356..5e43f2961f 100644 --- a/.github/workflows/intel-auto.yml +++ b/.github/workflows/intel-auto.yml @@ -60,7 +60,6 @@ jobs: --enable-build-mode=${{ inputs.build_mode }} \ --enable-netcdf \ --enable-shared \ - --enable-hdf4-xdr \ --disable-fortran # BUILD diff --git a/.github/workflows/main-auto.yml b/.github/workflows/main-auto.yml index b721c8cebe..1ca6ec81dc 100644 --- a/.github/workflows/main-auto.yml +++ b/.github/workflows/main-auto.yml @@ -16,10 +16,6 @@ on: description: "netcdf enable/disable" required: true type: string - xdr: - description: "xdr enable/disable(system)" - required: true - type: string permissions: contents: read @@ -33,7 +29,7 @@ jobs: # Linux (Ubuntu) w/ gcc + Autotools # Autotools_build_and_test: - name: "GCC-${{ inputs.build_mode }}-NC=${{ inputs.netcdf }}d-XDR=${{ inputs.xdr }}d" + name: "GCC-${{ inputs.build_mode }}-NC=${{ inputs.netcdf }}d" # Don't run the action if the commit message says to skip CI if: "!contains(github.event.head_commit.message, 'skip-ci')" @@ -64,7 +60,6 @@ jobs: cd "${{ runner.workspace }}/build" $GITHUB_WORKSPACE/configure \ --enable-build-mode=${{ inputs.build_mode }} \ - --${{ inputs.xdr }}-hdf4-xdr \ --${{ inputs.netcdf }}-netcdf \ --disable-fortran \ --${{ inputs.shared }}-java \ diff --git a/.github/workflows/main-cmake.yml b/.github/workflows/main-cmake.yml index 5c1ab9a2b4..c408539f01 100644 --- a/.github/workflows/main-cmake.yml +++ b/.github/workflows/main-cmake.yml @@ -52,7 +52,6 @@ jobs: - name: "Windows MSVC" os: windows-2022 toolchain: "" - xdr: ON fortran: OFF java: ON docs: OFF @@ -70,7 +69,6 @@ jobs: # so it's not critical - name: "Ubuntu gcc" os: ubuntu-latest - xdr: ON fortran: OFF java: ON docs: ON @@ -90,7 +88,6 @@ jobs: # but that seems unnecessary - name: "MacOS Clang" os: macos-13 - xdr: ON fortran: OFF java: ON docs: OFF @@ -107,7 +104,6 @@ jobs: # - name: "Ubuntu mingw CMake" os: ubuntu-latest - xdr: ON fortran: OFF java: OFF docs: OFF @@ -125,7 +121,6 @@ jobs: - name: "Windows static MSVC CMake" os: windows-2022 toolchain: "" - xdr: ON fortran: OFF java: OFF docs: OFF @@ -143,7 +138,6 @@ jobs: # so it's not critical - name: "Ubuntu static gcc CMake" os: ubuntu-latest - xdr: ON fortran: OFF java: OFF docs: OFF @@ -162,7 +156,6 @@ jobs: # but that seems unnecessary - name: "MacOS static Clang CMake" os: macos-13 - xdr: ON fortran: OFF java: OFF docs: OFF @@ -243,7 +236,6 @@ jobs: -DBUILD_SHARED_LIBS:BOOL=${{ inputs.shared }} \ -DHDF4_BUILD_EXAMPLES=ON \ -DBUILD_JPEG_WITH_PIC:BOOL=ON \ - -DHDF4_BUILD_XDR_LIB:BOOL=${{ matrix.xdr }} \ -DHDF4_ENABLE_NETCDF:BOOL=${{ inputs.netcdf }} \ -DHDF4_BUILD_FORTRAN=${{ matrix.fortran }} \ -DHDF4_BUILD_JAVA=${{ env.useJava }} \ diff --git a/.github/workflows/ppc64.yml b/.github/workflows/ppc64.yml index 589a0cf1cd..e6529598ff 100644 --- a/.github/workflows/ppc64.yml +++ b/.github/workflows/ppc64.yml @@ -41,7 +41,7 @@ jobs: run: | ./autogen.sh ./configure --prefix=/usr/local \ - --enable-shared --enable-hdf4-xdr \ + --enable-shared \ --disable-fortran --disable-netcdf make sudo make install diff --git a/CMakeLists.txt b/CMakeLists.txt index 01b8608d07..9a188a6f01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -481,46 +481,18 @@ if (HDF4_ENABLE_NETCDF) set (${HDF_PREFIX}_BUILD_NETCDF 1) endif () -#----------------------------------------------------------------------------- -# Option to build HDF4 xdr Library -#----------------------------------------------------------------------------- -option (HDF4_BUILD_XDR_LIB "Build HDF4 XDR Library" OFF) -if (WIN32 OR MINGW OR APPLE) - set (HDF4_BUILD_XDR_LIB ON CACHE BOOL "Build HDF4 XDR Library" FORCE) -else () - if (NOT HDF4_BUILD_XDR_LIB) - include (FindXDR) - if (XDR_FOUND) - set (CMAKE_REQUIRED_LIBRARIES "${XDR_LIBRARIES}" ) - message (STATUS "HDF4 XDR Library found: ${XDR_LIBRARIES}") - set (LINK_LIBS ${LINK_LIBS} ${XDR_LIBRARIES}) - set (LINK_SHARED_LIBS ${LINK_SHARED_LIBS} ${XDR_LIBRARIES}) - include_directories(${XDR_INCLUDE_DIRS}) - else () - set (HDF4_BUILD_XDR_LIB ON CACHE BOOL "Build HDF4 XDR Library" FORCE) - message (STATUS "HDF4 XDR Library will be built") - endif () - endif () -endif () - -if (HDF4_BUILD_XDR_LIB) - set (H4_NO_SYS_XDR_INC 1) - add_subdirectory (mfhdf/xdr) -endif () - #----------------------------------------------------------------------------- # Add the HDF4 Library Target to the build #----------------------------------------------------------------------------- add_subdirectory (hdf/src) add_subdirectory (mfhdf/libsrc) +add_subdirectory (mfhdf/xdr) -if (HDF4_BUILD_XDR_LIB) - if (NOT ONLY_SHARED_LIBS) - add_dependencies (${HDF4_MF_LIB_TARGET} ${HDF4_MF_XDR_LIB_TARGET}) - endif () - if (BUILD_SHARED_LIBS) - add_dependencies (${HDF4_MF_LIBSH_TARGET} ${HDF4_MF_XDR_LIBSH_TARGET}) - endif () +if (NOT ONLY_SHARED_LIBS) + add_dependencies (${HDF4_MF_LIB_TARGET} ${HDF4_MF_XDR_LIB_TARGET}) +endif () +if (BUILD_SHARED_LIBS) + add_dependencies (${HDF4_MF_LIBSH_TARGET} ${HDF4_MF_XDR_LIBSH_TARGET}) endif () #----------------------------------------------------------------------------- diff --git a/CMakePresets.json b/CMakePresets.json index 8ba7801e77..6eb58959b5 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -69,7 +69,6 @@ "inherits": ["ci-StdCompression", "ci-StdExamples"], "cacheVariables": { "HDF_PACKAGE_NAMESPACE": {"type": "STRING", "value": "hdf4::"}, - "HDF4_BUILD_XDR_LIB": "ON", "HDF4_BUILD_GENERATORS": "ON", "HDF4_ENABLE_ALL_WARNINGS": "ON", "HDF4_MINGW_STATIC_GCC_LIBS": "ON" diff --git a/config/cmake/FindXDR.cmake b/config/cmake/FindXDR.cmake deleted file mode 100644 index ded9ba13a7..0000000000 --- a/config/cmake/FindXDR.cmake +++ /dev/null @@ -1,47 +0,0 @@ -# Try to find the XDR library and set some required variables -# -# Once run this will define: -# -# XDR_FOUND = system has XDR lib -# -# XDR_LIBRARIES = full path to the libraries, if required -# - -include(CheckIncludeFile) -include(CheckCSourceCompiles) -include(CheckFunctionExists) -include(CheckTypeSize) -include(CheckLibraryExists) - -## First try to find the required header files (rpc/types.h, rpc/xdr.h) -find_path(XDR_INCLUDE_DIR NAMES rpc/types.h PATHS "/usr/include" "/usr/include/tirpc") - -#check for the XDR functions: their interface and the libraries they're hidden in. - ## Now let's see if we need an extra lib to compile it - set(XDR_INT_FOUND) - CHECK_FUNCTION_EXISTS(xdr_int XDR_INT_FOUND) - if (NOT XDR_INT_FOUND) - foreach(lib nsl rpc tirpc) - ## Try to find the corresponding lib - message(STATUS "Try to find the library ${lib}.") - set(XDR_INT_LIBRARY) - find_library(XDR_INT_LIBRARY ${lib}) - - if (XDR_INT_LIBRARY) - message(STATUS "Found library ${lib}. Check for symbol.") - CHECK_LIBRARY_EXISTS(${XDR_INT_LIBRARY} xdr_int "" XDR_INT_SYMBOL_FOUND) - endif() - if (XDR_INT_SYMBOL_FOUND) - set(XDR_LIBRARIES ${XDR_INT_LIBRARY}) - set(XDR_INCLUDE_DIRS ${XDR_INCLUDE_DIR}) - set(XDR_INT_FOUND TRUE) - break() - endif() - endforeach() - endif() - - if(NOT XDR_INT_FOUND) - message(STATUS "Could not locate xdr symbols.") - else() - set(XDR_FOUND TRUE) - endif() diff --git a/config/cmake/h4config.h.in b/config/cmake/h4config.h.in index afe8127835..adac72820a 100644 --- a/config/cmake/h4config.h.in +++ b/config/cmake/h4config.h.in @@ -86,9 +86,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine H4_HAVE_RESOLV_H @H4_HAVE_RESOLV_H@ -/* Define to 1 if you have the system XDR library. */ -#cmakedefine H4_HAVE_RPC @H4_HAVE_RPC@ - /* Define to 1 if you have the header file. */ #cmakedefine H4_HAVE_STDDEF_H @H4_HAVE_STDDEF_H@ @@ -159,9 +156,6 @@ /* Define to 1 if your C compiler doesn't accept -c and -o together. */ #cmakedefine H4_NO_MINUS_C_MINUS_O @H4_NO_MINUS_C_MINUS_O@ -/* Not using system xdr */ -#cmakedefine H4_NO_SYS_XDR_INC @H4_NO_SYS_XDR_INC@ - /* Name of package */ #define H4_PACKAGE "@HDF4_PACKAGE@" diff --git a/config/cmake/hdf4-config.cmake.in b/config/cmake/hdf4-config.cmake.in index 40f14b55ae..bd6fa1ae0d 100644 --- a/config/cmake/hdf4-config.cmake.in +++ b/config/cmake/hdf4-config.cmake.in @@ -18,7 +18,6 @@ set (${HDF4_PACKAGE_NAME}_VALID_COMPONENTS #----------------------------------------------------------------------------- set (${HDF4_PACKAGE_NAME}_BUILD_FORTRAN @HDF4_BUILD_FORTRAN@) set (${HDF4_PACKAGE_NAME}_BUILD_JAVA @HDF4_BUILD_JAVA@) -set (${HDF4_PACKAGE_NAME}_BUILD_XDR_LIB @HDF4_BUILD_XDR_LIB@) set (${HDF4_PACKAGE_NAME}_BUILD_TOOLS @HDF4_BUILD_TOOLS@) set (${HDF4_PACKAGE_NAME}_BUILD_UTILS @HDF4_BUILD_UTILS@) set (${HDF4_PACKAGE_NAME}_ENABLE_JPEG_LIB_SUPPORT @HDF4_ENABLE_JPEG_LIB_SUPPORT@) diff --git a/config/cmake/scripts/HDF4options.cmake b/config/cmake/scripts/HDF4options.cmake index 3191f4ae18..e5948bfb23 100755 --- a/config/cmake/scripts/HDF4options.cmake +++ b/config/cmake/scripts/HDF4options.cmake @@ -33,10 +33,6 @@ set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF4_BUILD_FORTRAN:BOOL=OFF") #### java disabled #### set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF4_BUILD_JAVA:BOOL=OFF") -############################################################################################# -#### hdf4 xdr enabled #### -#set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF4_BUILD_XDR_LIB:BOOL=ON") - ############################################################################################# ### change install prefix (default use INSTALLDIR value) set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DCMAKE_INSTALL_PREFIX:PATH=${INSTALLDIR}") diff --git a/config/commence.am b/config/commence.am index d946ebe98e..abad8606d5 100644 --- a/config/commence.am +++ b/config/commence.am @@ -27,9 +27,7 @@ LIBMFHDF = $(top_builddir)/mfhdf/libsrc/libmfhdf.la H4CC = ${DESTDIR}$(bindir)/h4cc H4FC = ${DESTDIR}$(bindir)/h4fc -if HDF_BUILD_XDR - XDR_ADD = -R$(abs_top_builddir)/mfhdf/xdr/.libs -endif +XDR_ADD = -R$(abs_top_builddir)/mfhdf/xdr/.libs if HDF_BUILD_SHARED AM_LDFLAGS = -R$(abs_top_builddir)/mfhdf/libsrc/.libs -R$(abs_top_builddir)/hdf/src/.libs $(XDR_ADD) diff --git a/configure.ac b/configure.ac index a5f9544677..eb5e831eac 100644 --- a/configure.ac +++ b/configure.ac @@ -836,92 +836,6 @@ AC_SUBST([SZIP_HAS_ENCODER]) AM_CONDITIONAL([BUILD_SHARED_SZIP_CONDITIONAL], [test "X$USE_COMP_SZIP" = "Xyes" && test "X$LL_PATH" != "X"]) -## ---------------------------------------------------------------------- -## Is XDR support present? The TRY_LINK info was gotten from the -## mfhdf/libsrc/local_nc.c file. -AC_MSG_CHECKING([for xdr library support]) - -AC_ARG_ENABLE([hdf4-xdr], - [AS_HELP_STRING([--enable-hdf4-xdr], - [Build xdr library from code in HDF4 source. - Not supported for 64 bit mode. [default="no"]])], - [enableval="yes"],[enableval="no"]) - -case "$enableval" in - yes) - BUILD_XDR="yes" - AC_MSG_RESULT([using HDF4 XDR]); - ;; - no) - BUILD_XDR="no" - AC_MSG_RESULT([using system XDR]); - ;; -esac - - -## Check headers and add libraries for XDR if the HDF4 XDR library is not used. -if test "X$BUILD_XDR" != "Xyes"; then - ## For Solaris systems, add the -nsl for XDR support - ## - ## The SunRPC of the glibc has been replaced by a TI-RPC (Transport Independent RPC) library for IPv6 support - ## ====================================================================== - ## Checks for header files - ## ====================================================================== - HAVE_RPC="yes" - HAVE_OLDRPC="yes" - HAVE_TIRPC="yes" - ## save current settings - SYSCPPFLAGS="$CPPFLAGS" - SYSCFLAGS="$CFLAGS" - case "$host" in - *-solaris*) - LIBS="$LIBS -lnsl" - ;; - *-pc-cygwin* | *-linux*) - AC_CHECK_HEADER([rpc/rpc.h],[:], [unset HAVE_OLDRPC]) - AC_CHECK_HEADER([tirpc/netconfig.h],[:], [unset HAVE_TIRPC]) - if test -z "$HAVE_OLDRPC" ; then - LIBS="$LIBS -ltirpc" - CFLAGS="$SYSCFLAGS -I/usr/include/tirpc" - CPPFLAGS="$SYSCPPFLAGS -I/usr/include/tirpc" - if test -z "$HAVE_TIRPC" ; then - CFLAGS="$SYSCFLAGS" - CPPFLAGS="$SYSCPPFLAGS" - AC_MSG_ERROR([couldn't find rpc headers]) - fi - else - HAVE_TIRPC="" - fi - ;; - *) ;; - esac - - ## ---------------------------------------------------------------------- - ## We're trying to link against the rpc library when building on Cygwin, - ## but we need to make sure that it is present on the system. Do that here, - ## The SunRPC of the glibc has been replaced by a TI-RPC (Transport Independent RPC) library for IPv6 support - case "$host" in - *-pc-cygwin* | *-linux*) - if test -n "$HAVE_TIRPC"; then - AC_CHECK_LIB([tirpc], [xdr_opaque],[:], [unset HAVE_RPC]) - if test -z "$HAVE_RPC"; then - AC_MSG_ERROR([couldn't find rpc library]) - fi - fi - ;; - esac - - AC_LINK_IFELSE([AC_LANG_PROGRAM([[ - #include - #include ]], [[xdr_int]])],[BUILD_XDR="no"],[BUILD_XDR="yes"]) -fi - -if test "X$BUILD_XDR" != "Xno"; then - AC_DEFINE([NO_SYS_XDR_INC], [1], [Not using system xdr]) -fi - -AM_CONDITIONAL([HDF_BUILD_XDR], [test "X$BUILD_XDR" = "Xyes"]) - ## ====================================================================== ## Set POSIX level ## ====================================================================== diff --git a/mfhdf/Makefile.am b/mfhdf/Makefile.am index 8b61a8c851..e04c336d62 100644 --- a/mfhdf/Makefile.am +++ b/mfhdf/Makefile.am @@ -1,14 +1,8 @@ include $(top_srcdir)/config/commence.am -if HDF_BUILD_XDR XDR_DIR = xdr export XDRLIB = $(abs_top_builddir)/mfhdf/xdr/libxdr.la export XDRINC = -I$(abs_top_srcdir)/mfhdf/xdr -else -XDR_DIR = -XDRLIB = -XDRINC = -endif if HDF_BUILD_FORTRAN FORTRAN_DIR = fortran diff --git a/mfhdf/dumper/CMakeLists.txt b/mfhdf/dumper/CMakeLists.txt index d125f53a38..75a8332dff 100644 --- a/mfhdf/dumper/CMakeLists.txt +++ b/mfhdf/dumper/CMakeLists.txt @@ -16,7 +16,7 @@ set (hdp_SRCS if (NOT ONLY_SHARED_LIBS) add_executable (hdp ${hdp_SRCS}) - target_include_directories(hdp PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hdp PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hdp STATIC) target_link_libraries (hdp PRIVATE ${HDF4_MF_LIB_TARGET}) set_target_properties (hdp PROPERTIES COMPILE_DEFINITIONS "HDF") @@ -26,7 +26,7 @@ endif () if (BUILD_SHARED_LIBS) add_executable (hdp-shared ${hdp_SRCS}) - target_include_directories(hdp-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hdp-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hdp-shared SHARED) target_link_libraries (hdp-shared PRIVATE ${HDF4_MF_LIBSH_TARGET}) set_target_properties (hdp-shared PROPERTIES COMPILE_DEFINITIONS "HDF") diff --git a/mfhdf/hdfimport/CMakeLists.txt b/mfhdf/hdfimport/CMakeLists.txt index c97cf997fe..bc8411edd5 100644 --- a/mfhdf/hdfimport/CMakeLists.txt +++ b/mfhdf/hdfimport/CMakeLists.txt @@ -11,7 +11,7 @@ set (hdfimport_SRCS if (NOT ONLY_SHARED_LIBS) add_executable (hdfimport ${hdfimport_SRCS}) - target_include_directories(hdfimport PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hdfimport PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hdfimport STATIC) target_link_libraries (hdfimport PRIVATE ${HDF4_MF_LIB_TARGET}) set_target_properties (hdfimport PROPERTIES COMPILE_DEFINITIONS "HDF") @@ -22,7 +22,7 @@ endif () if (BUILD_SHARED_LIBS) add_executable (hdfimport-shared ${hdfimport_SRCS}) - target_include_directories(hdfimport-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hdfimport-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hdfimport-shared SHARED) target_link_libraries (hdfimport-shared PRIVATE ${HDF4_MF_LIBSH_TARGET}) set_target_properties (hdfimport-shared PROPERTIES COMPILE_DEFINITIONS "HDF") diff --git a/mfhdf/hdiff/CMakeLists.txt b/mfhdf/hdiff/CMakeLists.txt index a2e77e64b2..70a4db2901 100644 --- a/mfhdf/hdiff/CMakeLists.txt +++ b/mfhdf/hdiff/CMakeLists.txt @@ -23,7 +23,7 @@ set (hdiff_SRCS if (NOT ONLY_SHARED_LIBS) add_executable(hdiff ${hdiff_SRCS}) - target_include_directories(hdiff PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hdiff PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hdiff STATIC) target_link_libraries(hdiff PRIVATE ${HDF4_MF_LIB_TARGET} ${HDF4_SRC_LIB_TARGET} ${LINK_LIBS}) set_global_variable (HDF4_UTILS_TO_EXPORT "${HDF4_UTILS_TO_EXPORT};hdiff") @@ -33,7 +33,7 @@ endif () if (BUILD_SHARED_LIBS) add_executable(hdiff-shared ${hdiff_SRCS}) - target_include_directories(hdiff-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hdiff-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hdiff-shared SHARED) target_link_libraries(hdiff-shared PRIVATE ${HDF4_MF_LIBSH_TARGET} ${HDF4_SRC_LIBSH_TARGET} ${LINK_LIBS}) set_global_variable (HDF4_UTILS_TO_EXPORT "${HDF4_UTILS_TO_EXPORT};hdiff-shared") diff --git a/mfhdf/hrepack/CMakeLists.txt b/mfhdf/hrepack/CMakeLists.txt index 1f24341605..5c9ff9cccb 100644 --- a/mfhdf/hrepack/CMakeLists.txt +++ b/mfhdf/hrepack/CMakeLists.txt @@ -21,14 +21,14 @@ set (hrepack_SRCS if (NOT ONLY_SHARED_LIBS) add_executable (hrepack ${hrepack_SRCS}) - target_include_directories(hrepack PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hrepack PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hrepack STATIC) target_link_libraries (hrepack PRIVATE ${HDF4_MF_LIB_TARGET} ${LINK_COMP_LIBS}) set_target_properties (hrepack PROPERTIES COMPILE_DEFINITIONS "HDF") set_global_variable (HDF4_UTILS_TO_EXPORT "${HDF4_UTILS_TO_EXPORT};hrepack") add_executable (hrepack_check ${HDF4_MFHDF_HREPACK_SOURCE_DIR}/hrepack_check.c) - target_include_directories(hrepack_check PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hrepack_check PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hrepack_check STATIC) target_link_libraries (hrepack_check PRIVATE ${HDF4_MF_LIB_TARGET}) set_target_properties (hrepack_check PROPERTIES COMPILE_DEFINITIONS "HDF") @@ -38,14 +38,14 @@ endif () if (BUILD_SHARED_LIBS) add_executable (hrepack-shared ${hrepack_SRCS}) - target_include_directories(hrepack-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hrepack-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hrepack-shared SHARED) target_link_libraries (hrepack-shared PRIVATE ${HDF4_MF_LIBSH_TARGET} ${LINK_COMP_LIBS}) set_target_properties (hrepack-shared PROPERTIES COMPILE_DEFINITIONS "HDF") set_global_variable (HDF4_UTILS_TO_EXPORT "${HDF4_UTILS_TO_EXPORT};hrepack-shared") add_executable (hrepack_check-shared ${HDF4_MFHDF_HREPACK_SOURCE_DIR}/hrepack_check.c) - target_include_directories(hrepack_check-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(hrepack_check-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (hrepack_check-shared SHARED) target_link_libraries (hrepack_check-shared PRIVATE ${HDF4_MF_LIBSH_TARGET}) set_target_properties (hrepack_check-shared PROPERTIES COMPILE_DEFINITIONS "HDF") diff --git a/mfhdf/libsrc/CMakeLists.txt b/mfhdf/libsrc/CMakeLists.txt index 46b4ec4043..8caabe0527 100644 --- a/mfhdf/libsrc/CMakeLists.txt +++ b/mfhdf/libsrc/CMakeLists.txt @@ -59,7 +59,7 @@ endif () if (NOT ONLY_SHARED_LIBS) add_library (${HDF4_MF_LIB_TARGET} STATIC ${HDF4_MFHDF_LIBSRC_CSRCS} ${HDF4_MFHDF_LIBSRC_CHDRS}) target_include_directories (${HDF4_MF_LIB_TARGET} - PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>" + PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}" INTERFACE "$/include>" ) target_compile_options(${HDF4_MF_LIB_TARGET} PRIVATE "${HDF4_CMAKE_C_FLAGS}") @@ -69,9 +69,7 @@ if (NOT ONLY_SHARED_LIBS) ${HDF_EXTRA_FLAGS} ) TARGET_C_PROPERTIES (${HDF4_MF_LIB_TARGET} STATIC) - if (HDF4_BUILD_XDR_LIB) - target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC ${HDF4_MF_XDR_LIB_TARGET}) - endif () + target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC ${HDF4_MF_XDR_LIB_TARGET}) target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC ${HDF4_SRC_LIB_TARGET}) set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_LIB_TARGET}") H4_SET_LIB_OPTIONS (${HDF4_MF_LIB_TARGET} ${HDF4_MF_LIB_NAME} STATIC) @@ -86,7 +84,7 @@ endif () if (BUILD_SHARED_LIBS) add_library (${HDF4_MF_LIBSH_TARGET} SHARED ${HDF4_MFHDF_LIBSRC_CSRCS} ${HDF4_MFHDF_LIBSRC_CHDRS}) target_include_directories (${HDF4_MF_LIBSH_TARGET} - PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>" + PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}" INTERFACE "$/include>" ) target_compile_options(${HDF4_MF_LIBSH_TARGET} PRIVATE "${HDF4_CMAKE_C_FLAGS}") @@ -96,9 +94,7 @@ if (BUILD_SHARED_LIBS) ${HDF_EXTRA_FLAGS} ) TARGET_C_PROPERTIES (${HDF4_MF_LIBSH_TARGET} SHARED) - if (HDF4_BUILD_XDR_LIB) - target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC ${HDF4_MF_XDR_LIBSH_TARGET}) - endif () + target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC ${HDF4_MF_XDR_LIBSH_TARGET}) target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC ${HDF4_SRC_LIBSH_TARGET}) set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_LIBSH_TARGET}") H4_SET_LIB_OPTIONS (${HDF4_MF_LIBSH_TARGET} ${HDF4_MF_LIB_NAME} SHARED) diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index 94004b8f97..e7fa2c4f42 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -30,34 +30,9 @@ #define FILENAME_MAX 255 #endif -/* Do we have system XDR files */ -#ifndef H4_NO_SYS_XDR_INC - -#ifdef __CYGWIN__ -#ifndef __u_char_defined -typedef unsigned char u_char; -#define __u_char_defined -#endif -#ifndef __u_short_defined -typedef unsigned short u_short; -#define __u_short_defined -#endif -#ifndef __u_int_defined -typedef unsigned int u_int; -#define __u_int_defined -#endif -#ifndef __u_long_defined -typedef unsigned long u_long; -#define __u_long_defined -#endif -#endif /* __CYGWIN__ */ - -#include -#include -#else /* H4_NO_SYS_XDR_INC */ +/* Local XDR files */ #include "types.h" #include "xdr.h" -#endif /* H4_NO_SYS_XDR_INC */ #ifdef H4_HAVE_NETCDF #include "netcdf.h" /* needed for defs of nc_type, ncvoid, ... */ diff --git a/mfhdf/ncdump/CMakeLists.txt b/mfhdf/ncdump/CMakeLists.txt index d9e6154851..695ee86fff 100644 --- a/mfhdf/ncdump/CMakeLists.txt +++ b/mfhdf/ncdump/CMakeLists.txt @@ -1,9 +1,7 @@ cmake_minimum_required (VERSION 3.12) project (HDF4_MFHDF_NCDUMP C) -if (HDF4_BUILD_XDR_LIB) - INCLUDE_DIRECTORIES (${HDF4_MFHDF_XDR_DIR}) -endif () +INCLUDE_DIRECTORIES (${HDF4_MFHDF_XDR_DIR}) set (ncdump_SRCS ${HDF4_MFHDF_NCDUMP_SOURCE_DIR}/dumplib.c @@ -14,7 +12,7 @@ set (ncdump_SRCS if (NOT ONLY_SHARED_LIBS) add_executable (ncdump ${ncdump_SRCS}) - target_include_directories (ncdump PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories (ncdump PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (ncdump STATIC) target_link_libraries (ncdump PRIVATE ${HDF4_MF_LIB_TARGET}) set_target_properties (ncdump PROPERTIES COMPILE_DEFINITIONS "HDF") @@ -24,7 +22,7 @@ endif () if (BUILD_SHARED_LIBS) add_executable (ncdump-shared ${ncdump_SRCS}) - target_include_directories (ncdump-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories (ncdump-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (ncdump-shared SHARED) target_link_libraries (ncdump-shared PRIVATE ${HDF4_MF_LIBSH_TARGET}) set_target_properties (ncdump-shared PROPERTIES COMPILE_DEFINITIONS "HDF") diff --git a/mfhdf/ncgen/CMakeLists.txt b/mfhdf/ncgen/CMakeLists.txt index 2b3b235936..16b26ce124 100644 --- a/mfhdf/ncgen/CMakeLists.txt +++ b/mfhdf/ncgen/CMakeLists.txt @@ -22,7 +22,7 @@ set (ncgen_SRCS if (NOT ONLY_SHARED_LIBS) add_executable (ncgen ${ncgen_SRCS}) - target_include_directories(ncgen PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(ncgen PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (ncgen STATIC) target_link_libraries (ncgen PRIVATE ${HDF4_MF_LIB_TARGET}) set_target_properties (ncgen PROPERTIES COMPILE_DEFINITIONS "HDF") @@ -32,7 +32,7 @@ endif () if (BUILD_SHARED_LIBS) add_executable (ncgen-shared ${ncgen_SRCS}) - target_include_directories(ncgen-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") + target_include_directories(ncgen-shared PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_UTIL_DIR};${HDF4_MFHDF_XDR_DIR}") TARGET_C_PROPERTIES (ncgen-shared SHARED) target_link_libraries (ncgen-shared PRIVATE ${HDF4_MF_LIBSH_TARGET}) set_target_properties (ncgen-shared PROPERTIES COMPILE_DEFINITIONS "HDF") diff --git a/mfhdf/nctest/CMakeLists.txt b/mfhdf/nctest/CMakeLists.txt index fd2d804e95..b85ea8b0b2 100644 --- a/mfhdf/nctest/CMakeLists.txt +++ b/mfhdf/nctest/CMakeLists.txt @@ -25,7 +25,7 @@ set (nctest_SRCS ) add_executable (nctest ${nctest_SRCS}) -target_include_directories(nctest PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};$<$:${HDF4_MFHDF_XDR_DIR}>") +target_include_directories(nctest PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}") if (NOT BUILD_SHARED_LIBS) TARGET_C_PROPERTIES (nctest STATIC) target_link_libraries (nctest PRIVATE ${HDF4_MF_LIB_TARGET}) diff --git a/mfhdf/test/CMakeTests.cmake b/mfhdf/test/CMakeTests.cmake index 78e00cb556..cd4c7ceda8 100644 --- a/mfhdf/test/CMakeTests.cmake +++ b/mfhdf/test/CMakeTests.cmake @@ -132,41 +132,39 @@ set_tests_properties (MFHDF_TEST-hdfnctest PROPERTIES ) #-- Adding test for xdrtest -if (HDF4_BUILD_XDR_LIB) - add_executable (xdrtest ${HDF4_MFHDF_XDR_DIR}/xdrtest.c) - if (NOT BUILD_SHARED_LIBS) - TARGET_C_PROPERTIES (xdrtest STATIC) - target_link_libraries (xdrtest PRIVATE ${HDF4_MF_XDR_LIB_TARGET}) - else () - TARGET_C_PROPERTIES (xdrtest SHARED) - target_link_libraries (xdrtest PRIVATE ${HDF4_MF_XDR_LIBSH_TARGET}) - endif () - if (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") - target_compile_options(xdrtest PRIVATE "-Wno-incompatible-function-pointer-types") - endif () +add_executable (xdrtest ${HDF4_MFHDF_XDR_DIR}/xdrtest.c) +if (NOT BUILD_SHARED_LIBS) + TARGET_C_PROPERTIES (xdrtest STATIC) + target_link_libraries (xdrtest PRIVATE ${HDF4_MF_XDR_LIB_TARGET}) +else () + TARGET_C_PROPERTIES (xdrtest SHARED) + target_link_libraries (xdrtest PRIVATE ${HDF4_MF_XDR_LIBSH_TARGET}) +endif () +if (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") + target_compile_options(xdrtest PRIVATE "-Wno-incompatible-function-pointer-types") +endif () - if (MSVC_VERSION LESS 1900) - HDFTEST_COPY_FILE("${HDF4_MFHDF_XDR_DIR}/xdrtest.out" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") - else () - HDFTEST_COPY_FILE("${HDF4_MFHDF_XDR_DIR}/xdrtest.cyg" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") - endif () - add_custom_target(xdrtest_files ALL COMMENT "Copying files needed by xdrtest tests" DEPENDS ${xdrtest_files_list}) +if (MSVC_VERSION LESS 1900) + HDFTEST_COPY_FILE("${HDF4_MFHDF_XDR_DIR}/xdrtest.out" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") +else () + HDFTEST_COPY_FILE("${HDF4_MFHDF_XDR_DIR}/xdrtest.cyg" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") +endif () +add_custom_target(xdrtest_files ALL COMMENT "Copying files needed by xdrtest tests" DEPENDS ${xdrtest_files_list}) - if (HDF4_ENABLE_USING_MEMCHECKER) - add_test (NAME MFHDF_TEST-xdrtest COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $) - else () - add_test ( - NAME MFHDF_TEST-xdrtest - COMMAND "${CMAKE_COMMAND}" - -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}" - -D "TEST_PROGRAM=$" - -D "TEST_ARGS:STRING=" - -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/TEST" - -D "TEST_OUTPUT=xdrtest.tst" - -D "TEST_EXPECT=0" - -D "TEST_REFERENCE=xdrtest.out" - -P "${HDF_RESOURCES_DIR}/runTest.cmake" +if (HDF4_ENABLE_USING_MEMCHECKER) + add_test (NAME MFHDF_TEST-xdrtest COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $) +else () + add_test ( + NAME MFHDF_TEST-xdrtest + COMMAND "${CMAKE_COMMAND}" + -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}" + -D "TEST_PROGRAM=$" + -D "TEST_ARGS:STRING=" + -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/TEST" + -D "TEST_OUTPUT=xdrtest.tst" + -D "TEST_EXPECT=0" + -D "TEST_REFERENCE=xdrtest.out" + -P "${HDF_RESOURCES_DIR}/runTest.cmake" ) - endif () - set_tests_properties (MFHDF_TEST-xdrtest PROPERTIES DEPENDS hdfnctest LABELS ${PROJECT_NAME}) endif () +set_tests_properties (MFHDF_TEST-xdrtest PROPERTIES DEPENDS hdfnctest LABELS ${PROJECT_NAME}) diff --git a/mfhdf/test/Makefile.am b/mfhdf/test/Makefile.am index 4c96916b7c..1e790d98bc 100644 --- a/mfhdf/test/Makefile.am +++ b/mfhdf/test/Makefile.am @@ -11,9 +11,7 @@ test_INCLUDES=-I$(top_srcdir)/hdf/src \ DEFINES=-DHDF AM_CPPFLAGS=$(test_INCLUDES) $(XDRINC) $(DEFINES) -if HDF_BUILD_XDR XDRLIB = $(top_builddir)/mfhdf/xdr/libxdr.la -endif ############################################################################# ## Testing ## diff --git a/mfhdf/xdr/xdrtest.c b/mfhdf/xdr/xdrtest.c index b707b4f0e0..379a954435 100644 --- a/mfhdf/xdr/xdrtest.c +++ b/mfhdf/xdr/xdrtest.c @@ -25,13 +25,9 @@ } \ } -#ifndef H4_NO_SYS_XDR_INC -#include -#include -#else +/* Local XDR files */ #include "types.h" #include "xdr.h" -#endif #define TESTFILE "test.xdr" /* if this is NOT defined, then the program just reads the file */ diff --git a/release_notes/INSTALL b/release_notes/INSTALL index 787a892d57..f31bd68541 100644 --- a/release_notes/INSTALL +++ b/release_notes/INSTALL @@ -87,18 +87,9 @@ To Configure: 4) Use the configure command in the top level HDF4 directory hdf-X.Y.Z: - Note: On macOS platforms version 10.13 or newer, XDR functions from the - system libraries do not work with HDF4. It is therefore necessary - to build the internal HDF4 XDR library, using --enable-hdf4-xdr for - autotools configure, or adding the corresponding CMake option: - set (ADD_BUILD_OPTIONS "${ADD_BUILD_OPTIONS} -DHDF4_BUILD_XDR_LIB:BOOL=ON") - to HDF4options.cmake. The options may also be used but are not required - on Linux platforms. - ./configure --with-zlib=/path_to_ZLIB_install_directory --with-jpeg=/path_to_JPEG_install_directory [--with-szlib=/path_to_SZIP_install_directory] - [--enable-hdf4-xdr] --prefix=/path_to_HDF4_install_directory * Please note that when the szlib option is not used, the Szip diff --git a/release_notes/INSTALL_CMake.txt b/release_notes/INSTALL_CMake.txt index d49b77e764..f5426a7020 100644 --- a/release_notes/INSTALL_CMake.txt +++ b/release_notes/INSTALL_CMake.txt @@ -687,9 +687,6 @@ HDF4_BUILD_EXAMPLES "Build HDF4 Library Examples" OFF HDF4_BUILD_FORTRAN "Build FORTRAN support" OFF HDF4_BUILD_TOOLS "Build HDF4 Tools" ON HDF4_BUILD_UTILS "Build HDF4 Utilities" OFF -HDF4_BUILD_XDR_LIB "Build HDF4 XDR Library" OFF -if (WIN32 OR MINGW OR APPLE) - HDF4_BUILD_XDR_LIB "Build HDF4 XDR Library" ON HDF4_ENABLE_NETCDF "Build HDF4 versions of NetCDF-3 APIS" ON HDF4_BUILD_JAVA "Build Java HDF Library" OFF HDF4_BUILD_NETCDF_TOOLS "Build HDF4 versions of ncdump and ncgen" ON diff --git a/release_notes/RELEASE.txt b/release_notes/RELEASE.txt index 9300354a0c..5bff03a034 100644 --- a/release_notes/RELEASE.txt +++ b/release_notes/RELEASE.txt @@ -38,6 +38,17 @@ New features and changes ======================== Configuration: ------------- + - Removed XDR configuration options + + We now only support building HDF4 with the XDR implementation packaged + with the HDF4 source. This is the first step of completely removing + XDR from the HDF4 library (to be replaced with a simplified I/O layer). + + The following options have been removed: + + Autotools: --enable-hdf4-xdr + CMake: HDF4_BUILD_XDR_LIB + - Incorporated HDF4 examples repository into HDF4 library. The HDF4Examples folder is equivalent to the repository hdf4-examples. From b30b0d9e713a3aa38da99e93ffc100f099c26c45 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 00:52:11 -0800 Subject: [PATCH 02/52] Remove mfhdf/xdr/byteordr.c This provided implementations of htons, etc. if a platform didn't have them. It's never compiled. --- mfhdf/xdr/byteordr.c | 71 -------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 mfhdf/xdr/byteordr.c diff --git a/mfhdf/xdr/byteordr.c b/mfhdf/xdr/byteordr.c deleted file mode 100644 index d9a8a6cc12..0000000000 --- a/mfhdf/xdr/byteordr.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Example: Use the standard library version instead, if you have one. - */ - -/* switch the order of the bytes in a long integer */ -long -ntohl(long i_in) -{ - long i_out; - unsigned char *inptr, *outptr; - - inptr = (unsigned char *)&i_in; - outptr = (unsigned char *)&i_out; - - outptr[3] = inptr[0]; - outptr[2] = inptr[1]; - outptr[1] = inptr[2]; - outptr[0] = inptr[3]; - - return (i_out); -} - -/* switch the order of the bytes in a long integer */ -long -htonl(long i_in) -{ - long i_out; - unsigned char *inptr, *outptr; - - inptr = (unsigned char *)&i_in; - outptr = (unsigned char *)&i_out; - - outptr[3] = inptr[0]; - outptr[2] = inptr[1]; - outptr[1] = inptr[2]; - outptr[0] = inptr[3]; - - return (i_out); -} - -/* switch the order of the bytes in a short integer */ -short -ntohs(short i_in) -{ - short i_out; - unsigned char *inptr, *outptr; - - inptr = (unsigned char *)&i_in; - outptr = (unsigned char *)&i_out; - - outptr[1] = inptr[0]; - outptr[0] = inptr[1]; - - return (i_out); -} - -/* switch the order of the bytes in a short integer */ -short -htons(short i_in) -{ - short i_out; - unsigned char *inptr, *outptr; - - inptr = (unsigned char *)&i_in; - outptr = (unsigned char *)&i_out; - - outptr[1] = inptr[0]; - outptr[0] = inptr[1]; - - return (i_out); -} From 5d7c1d5239f4c1944bdddbe246fe4bfb4101fa94 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 00:56:35 -0800 Subject: [PATCH 03/52] Remove mfhdf/xdr/xdrtest.opt This appears to be an old VMS file and is not referenced in the test code --- mfhdf/xdr/xdrtest.opt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 mfhdf/xdr/xdrtest.opt diff --git a/mfhdf/xdr/xdrtest.opt b/mfhdf/xdr/xdrtest.opt deleted file mode 100644 index d2ce3564ed..0000000000 --- a/mfhdf/xdr/xdrtest.opt +++ /dev/null @@ -1 +0,0 @@ -sys$library:vaxcrtl.exe/share From 17a429bc9604730d79f36731621f576390860b69 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 03:25:56 -0800 Subject: [PATCH 04/52] Incorporated XDR into the mfhdf library We no longer build a separate XDR library as all the XDR functionality has been moved to mfhdf/libsrc and is built with the mfhdf library. Because of this, we no longer distribute a separate XDR library with either build system. We also no longer distribute the XDR types.h and xdr.h headers. --- CMakeLists.txt | 13 --- config/commence.am | 4 +- configure.ac | 1 - mfhdf/Makefile.am | 8 +- mfhdf/libsrc/CMakeLists.txt | 12 ++- mfhdf/libsrc/Makefile.am | 6 +- mfhdf/{xdr => libsrc}/types.h | 0 mfhdf/{xdr => libsrc}/xdr.c | 0 mfhdf/{xdr => libsrc}/xdr.h | 0 mfhdf/{xdr/NOTICE.h => libsrc/xdr_NOTICE.h} | 0 mfhdf/{xdr/README => libsrc/xdr_README} | 0 mfhdf/{xdr => libsrc}/xdrarray.c | 0 mfhdf/{xdr => libsrc}/xdrfloat.c | 0 mfhdf/{xdr => libsrc}/xdrstdio.c | 0 mfhdf/test/CMakeLists.txt | 14 +++ mfhdf/test/CMakeTests.cmake | 17 +--- mfhdf/test/Makefile.am | 17 ++-- mfhdf/{xdr => test}/test_xdr.sav | Bin .../{xdr/testout.sav => test/xdr_testout.sav} | 0 mfhdf/{xdr => test}/xdrtest.c | 0 mfhdf/{xdr => test}/xdrtest.cyg | 0 mfhdf/{xdr => test}/xdrtest.out | 0 mfhdf/xdr/CMakeLists.txt | 92 ------------------ mfhdf/xdr/Makefile.am | 24 ----- release_notes/RELEASE.txt | 13 ++- 25 files changed, 49 insertions(+), 172 deletions(-) rename mfhdf/{xdr => libsrc}/types.h (100%) rename mfhdf/{xdr => libsrc}/xdr.c (100%) rename mfhdf/{xdr => libsrc}/xdr.h (100%) rename mfhdf/{xdr/NOTICE.h => libsrc/xdr_NOTICE.h} (100%) rename mfhdf/{xdr/README => libsrc/xdr_README} (100%) rename mfhdf/{xdr => libsrc}/xdrarray.c (100%) rename mfhdf/{xdr => libsrc}/xdrfloat.c (100%) rename mfhdf/{xdr => libsrc}/xdrstdio.c (100%) rename mfhdf/{xdr => test}/test_xdr.sav (100%) rename mfhdf/{xdr/testout.sav => test/xdr_testout.sav} (100%) rename mfhdf/{xdr => test}/xdrtest.c (100%) rename mfhdf/{xdr => test}/xdrtest.cyg (100%) rename mfhdf/{xdr => test}/xdrtest.out (100%) delete mode 100644 mfhdf/xdr/CMakeLists.txt delete mode 100644 mfhdf/xdr/Makefile.am diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a188a6f01..6a5722d715 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,7 +152,6 @@ set (HDF4_SRC_LIB_CORENAME "hdf") set (HDF4_SRC_FCSTUB_LIB_CORENAME "hdf_fcstub") set (HDF4_SRC_FORTRAN_LIB_CORENAME "hdf_fortran") set (HDF4_MF_LIB_CORENAME "mfhdf") -set (HDF4_MF_XDR_LIB_CORENAME "xdr") set (HDF4_HDF_TEST_LIB_CORENAME "hdf_test") set (HDF4_HDF_TEST_FCSTUB_LIB_CORENAME "hdf_test_fcstub") set (HDF4_MF_FCSTUB_LIB_CORENAME "mfhdf_fcstub") @@ -170,7 +169,6 @@ set (HDF4_SRC_LIB_NAME "${HDF4_EXTERNAL_LIB_PREFIX}${HDF4_SRC_LIB_COREN set (HDF4_SRC_FCSTUB_LIB_NAME "${HDF4_EXTERNAL_LIB_PREFIX}${HDF4_SRC_FCSTUB_LIB_CORENAME}") set (HDF4_SRC_FORTRAN_LIB_NAME "${HDF4_EXTERNAL_LIB_PREFIX}${HDF4_SRC_FORTRAN_LIB_CORENAME}") set (HDF4_MF_LIB_NAME "${HDF4_EXTERNAL_LIB_PREFIX}${HDF4_MF_LIB_CORENAME}") -set (HDF4_MF_XDR_LIB_NAME "${HDF4_EXTERNAL_LIB_PREFIX}${HDF4_MF_XDR_LIB_CORENAME}") set (HDF4_HDF_TEST_LIB_NAME "${HDF4_EXTERNAL_LIB_PREFIX}${HDF4_HDF_TEST_LIB_CORENAME}") set (HDF4_HDF_TEST_FCSTUB_LIB_NAME "${HDF4_EXTERNAL_LIB_PREFIX}${HDF4_HDF_TEST_FCSTUB_LIB_CORENAME}") set (HDF4_MF_FCSTUB_LIB_NAME "${HDF4_EXTERNAL_LIB_PREFIX}${HDF4_MF_FCSTUB_LIB_CORENAME}") @@ -188,7 +186,6 @@ set (HDF4_SRC_LIB_TARGET "${HDF4_SRC_LIB_CORENAME}-static") set (HDF4_SRC_FCSTUB_LIB_TARGET "${HDF4_SRC_FCSTUB_LIB_CORENAME}-static") set (HDF4_SRC_FORTRAN_LIB_TARGET "${HDF4_SRC_FORTRAN_LIB_CORENAME}-static") set (HDF4_MF_LIB_TARGET "${HDF4_MF_LIB_CORENAME}-static") -set (HDF4_MF_XDR_LIB_TARGET "${HDF4_MF_XDR_LIB_CORENAME}-static") set (HDF4_HDF_TEST_LIB_TARGET "${HDF4_HDF_TEST_LIB_CORENAME}-static") set (HDF4_HDF_TEST_FCSTUB_LIB_TARGET "${HDF4_HDF_TEST_FCSTUB_LIB_CORENAME}-static") set (HDF4_MF_FCSTUB_LIB_TARGET "${HDF4_MF_FCSTUB_LIB_CORENAME}-static") @@ -202,7 +199,6 @@ set (HDF4_SRC_LIBSH_TARGET "${HDF4_SRC_LIB_CORENAME}-shared") set (HDF4_SRC_FCSTUB_LIBSH_TARGET "${HDF4_SRC_FCSTUB_LIB_CORENAME}-shared") set (HDF4_SRC_FORTRAN_LIBSH_TARGET "${HDF4_SRC_FORTRAN_LIB_CORENAME}-shared") set (HDF4_MF_LIBSH_TARGET "${HDF4_MF_LIB_CORENAME}-shared") -set (HDF4_MF_XDR_LIBSH_TARGET "${HDF4_MF_XDR_LIB_CORENAME}-shared") set (HDF4_MF_FCSTUB_LIBSH_TARGET "${HDF4_MF_FCSTUB_LIB_CORENAME}-shared") set (HDF4_MF_FORTRAN_LIBSH_TARGET "${HDF4_MF_FORTRAN_LIB_CORENAME}-shared") set (HDF4_TOOLS_LIBSH_TARGET "${HDF4_TOOLS_LIB_CORENAME}-shared") @@ -218,7 +214,6 @@ set (HDF4_MFHDFSOURCE_DIR ${HDF4_SOURCE_DIR}/mfhdf/libsrc) set (HDF4_MFHDF_TEST_DIR ${HDF4_SOURCE_DIR}/mfhdf/test) set (HDF4_MFHDF_UTIL_DIR ${HDF4_SOURCE_DIR}/mfhdf/util) set (HDF4_MFHDF_FORTRAN_DIR ${HDF4_SOURCE_DIR}/mfhdf/fortran) -set (HDF4_MFHDF_XDR_DIR ${HDF4_SOURCE_DIR}/mfhdf/xdr) set (HDF4_JAVA_JNI_SRC_DIR ${HDF4_SOURCE_DIR}/java/src/jni) set (HDF4_JAVA_HDF_SRC_DIR ${HDF4_SOURCE_DIR}/java/src/hdf) set (HDF4_JAVA_TEST_SRC_DIR ${HDF4_SOURCE_DIR}/java/test) @@ -486,14 +481,6 @@ endif () #----------------------------------------------------------------------------- add_subdirectory (hdf/src) add_subdirectory (mfhdf/libsrc) -add_subdirectory (mfhdf/xdr) - -if (NOT ONLY_SHARED_LIBS) - add_dependencies (${HDF4_MF_LIB_TARGET} ${HDF4_MF_XDR_LIB_TARGET}) -endif () -if (BUILD_SHARED_LIBS) - add_dependencies (${HDF4_MF_LIBSH_TARGET} ${HDF4_MF_XDR_LIBSH_TARGET}) -endif () #----------------------------------------------------------------------------- # Option to build documentation diff --git a/config/commence.am b/config/commence.am index abad8606d5..1185d9f23d 100644 --- a/config/commence.am +++ b/config/commence.am @@ -27,10 +27,8 @@ LIBMFHDF = $(top_builddir)/mfhdf/libsrc/libmfhdf.la H4CC = ${DESTDIR}$(bindir)/h4cc H4FC = ${DESTDIR}$(bindir)/h4fc -XDR_ADD = -R$(abs_top_builddir)/mfhdf/xdr/.libs - if HDF_BUILD_SHARED - AM_LDFLAGS = -R$(abs_top_builddir)/mfhdf/libsrc/.libs -R$(abs_top_builddir)/hdf/src/.libs $(XDR_ADD) + AM_LDFLAGS = -R$(abs_top_builddir)/mfhdf/libsrc/.libs -R$(abs_top_builddir)/hdf/src/.libs endif ACLOCAL_AMFLAGS = "-I m4" diff --git a/configure.ac b/configure.ac index eb5e831eac..978009727b 100644 --- a/configure.ac +++ b/configure.ac @@ -1193,7 +1193,6 @@ AC_CONFIG_FILES([Makefile mfhdf/nctest/Makefile mfhdf/test/Makefile mfhdf/test/testmfhdf.sh - mfhdf/xdr/Makefile java/Makefile java/src/Makefile java/src/jni/Makefile diff --git a/mfhdf/Makefile.am b/mfhdf/Makefile.am index e04c336d62..3e37caca3a 100644 --- a/mfhdf/Makefile.am +++ b/mfhdf/Makefile.am @@ -1,9 +1,5 @@ include $(top_srcdir)/config/commence.am -XDR_DIR = xdr -export XDRLIB = $(abs_top_builddir)/mfhdf/xdr/libxdr.la -export XDRINC = -I$(abs_top_srcdir)/mfhdf/xdr - if HDF_BUILD_FORTRAN FORTRAN_DIR = fortran else @@ -17,9 +13,9 @@ NETCDF_DIRS = nctest endif # src folder in root Makefile, build other folders now -SUBDIRS = $(XDR_DIR) libsrc $(FORTRAN_DIR) test $(NETCDF_DIRS) dumper hdfimport hdiff hrepack +SUBDIRS = libsrc $(FORTRAN_DIR) test $(NETCDF_DIRS) dumper hdfimport hdiff hrepack -DIST_SUBDIRS = xdr libsrc fortran test $(NETCDF_DIRS) dumper hdfimport hdiff hrepack examples +DIST_SUBDIRS = libsrc fortran test $(NETCDF_DIRS) dumper hdfimport hdiff hrepack examples installcheck-local: @(cd examples && $(MAKE) $(AM_MAKEFLAGS) $@) || exit 1; diff --git a/mfhdf/libsrc/CMakeLists.txt b/mfhdf/libsrc/CMakeLists.txt index 8caabe0527..a0783fc583 100644 --- a/mfhdf/libsrc/CMakeLists.txt +++ b/mfhdf/libsrc/CMakeLists.txt @@ -32,6 +32,10 @@ set (HDF4_MFHDF_LIBSRC_CSRCS ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/string.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/var.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrposix.c + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdr.c + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrarray.c + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrfloat.c + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrstdio.c ) set (HDF4_MFHDF_LIBSRC_INSTALL_CHDRS @@ -46,6 +50,8 @@ set (HDF4_MFHDF_LIBSRC_CHDRS ${HDF4_MFHDF_LIBSRC_INSTALL_CHDRS} ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/error.h ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/mfprivate.h + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/types.h + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdr.h ) if (HDF4_ENABLE_NETCDF) @@ -59,7 +65,7 @@ endif () if (NOT ONLY_SHARED_LIBS) add_library (${HDF4_MF_LIB_TARGET} STATIC ${HDF4_MFHDF_LIBSRC_CSRCS} ${HDF4_MFHDF_LIBSRC_CHDRS}) target_include_directories (${HDF4_MF_LIB_TARGET} - PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}" + PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR}" INTERFACE "$/include>" ) target_compile_options(${HDF4_MF_LIB_TARGET} PRIVATE "${HDF4_CMAKE_C_FLAGS}") @@ -69,7 +75,6 @@ if (NOT ONLY_SHARED_LIBS) ${HDF_EXTRA_FLAGS} ) TARGET_C_PROPERTIES (${HDF4_MF_LIB_TARGET} STATIC) - target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC ${HDF4_MF_XDR_LIB_TARGET}) target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC ${HDF4_SRC_LIB_TARGET}) set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_LIB_TARGET}") H4_SET_LIB_OPTIONS (${HDF4_MF_LIB_TARGET} ${HDF4_MF_LIB_NAME} STATIC) @@ -84,7 +89,7 @@ endif () if (BUILD_SHARED_LIBS) add_library (${HDF4_MF_LIBSH_TARGET} SHARED ${HDF4_MFHDF_LIBSRC_CSRCS} ${HDF4_MFHDF_LIBSRC_CHDRS}) target_include_directories (${HDF4_MF_LIBSH_TARGET} - PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR};${HDF4_MFHDF_XDR_DIR}" + PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDFSOURCE_DIR}" INTERFACE "$/include>" ) target_compile_options(${HDF4_MF_LIBSH_TARGET} PRIVATE "${HDF4_CMAKE_C_FLAGS}") @@ -94,7 +99,6 @@ if (BUILD_SHARED_LIBS) ${HDF_EXTRA_FLAGS} ) TARGET_C_PROPERTIES (${HDF4_MF_LIBSH_TARGET} SHARED) - target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC ${HDF4_MF_XDR_LIBSH_TARGET}) target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC ${HDF4_SRC_LIBSH_TARGET}) set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_LIBSH_TARGET}") H4_SET_LIB_OPTIONS (${HDF4_MF_LIBSH_TARGET} ${HDF4_MF_LIB_NAME} SHARED) diff --git a/mfhdf/libsrc/Makefile.am b/mfhdf/libsrc/Makefile.am index 24d24f8321..bad33fc488 100644 --- a/mfhdf/libsrc/Makefile.am +++ b/mfhdf/libsrc/Makefile.am @@ -8,7 +8,7 @@ include $(top_srcdir)/config/commence.am lib_INCLUDES = -I$(top_srcdir)/hdf/src \ -I$(top_srcdir)/mfhdf/libsrc DEFINES = -DHDF -AM_CPPFLAGS = $(lib_INCLUDES) $(XDRINC) $(DEFINES) +AM_CPPFLAGS = $(lib_INCLUDES) $(DEFINES) ############################################################################# ## Library to build ## @@ -19,7 +19,7 @@ lib_LTLIBRARIES = libmfhdf.la ## Information for building the "libmfhdf.la" library CSOURCES = array.c attr.c cdf.c dim.c file.c hdfsds.c iarray.c error.c \ globdef.c mfsd.c mfdatainfo.c nssdc.c putget.c putgetg.c \ - sharray.c string.c var.c xdrposix.c + sharray.c string.c var.c xdrposix.c xdr.c xdrfloat.c xdrstdio.c xdrarray.c if HDF_BUILD_NETCDF FSOURCES = $(top_builddir)/mfhdf/fortran/jackets.c $(top_srcdir)/mfhdf/fortran/mfsdf.c $(top_srcdir)/mfhdf/fortran/mfsdff.f @@ -33,7 +33,7 @@ else libmfhdf_la_SOURCES = $(CSOURCES) endif -libmfhdf_la_LIBADD = $(XDRLIB) $(top_builddir)/hdf/src/libdf.la +libmfhdf_la_LIBADD = $(top_builddir)/hdf/src/libdf.la if HDF_BUILD_NETCDF include_HEADERS = hdf2netcdf.h local_nc.h mfhdf.h netcdf.h mfhdfi.h mfdatainfo.h diff --git a/mfhdf/xdr/types.h b/mfhdf/libsrc/types.h similarity index 100% rename from mfhdf/xdr/types.h rename to mfhdf/libsrc/types.h diff --git a/mfhdf/xdr/xdr.c b/mfhdf/libsrc/xdr.c similarity index 100% rename from mfhdf/xdr/xdr.c rename to mfhdf/libsrc/xdr.c diff --git a/mfhdf/xdr/xdr.h b/mfhdf/libsrc/xdr.h similarity index 100% rename from mfhdf/xdr/xdr.h rename to mfhdf/libsrc/xdr.h diff --git a/mfhdf/xdr/NOTICE.h b/mfhdf/libsrc/xdr_NOTICE.h similarity index 100% rename from mfhdf/xdr/NOTICE.h rename to mfhdf/libsrc/xdr_NOTICE.h diff --git a/mfhdf/xdr/README b/mfhdf/libsrc/xdr_README similarity index 100% rename from mfhdf/xdr/README rename to mfhdf/libsrc/xdr_README diff --git a/mfhdf/xdr/xdrarray.c b/mfhdf/libsrc/xdrarray.c similarity index 100% rename from mfhdf/xdr/xdrarray.c rename to mfhdf/libsrc/xdrarray.c diff --git a/mfhdf/xdr/xdrfloat.c b/mfhdf/libsrc/xdrfloat.c similarity index 100% rename from mfhdf/xdr/xdrfloat.c rename to mfhdf/libsrc/xdrfloat.c diff --git a/mfhdf/xdr/xdrstdio.c b/mfhdf/libsrc/xdrstdio.c similarity index 100% rename from mfhdf/xdr/xdrstdio.c rename to mfhdf/libsrc/xdrstdio.c diff --git a/mfhdf/test/CMakeLists.txt b/mfhdf/test/CMakeLists.txt index 93ccf66228..48b511354b 100644 --- a/mfhdf/test/CMakeLists.txt +++ b/mfhdf/test/CMakeLists.txt @@ -47,6 +47,20 @@ else () endif () set_target_properties (cdftest PROPERTIES FOLDER test COMPILE_DEFINITIONS "HDF") +#-- Adding test for xdrtest +add_executable (xdrtest xdrtest.c) +target_include_directories(xdrtest PRIVATE "${HDF4_MFHDFSOURCE_DIR}") +if (NOT BUILD_SHARED_LIBS) + TARGET_C_PROPERTIES (xdrtest STATIC) + target_link_libraries (xdrtest PRIVATE ${HDF4_MF_LIB_TARGET}) +else () + TARGET_C_PROPERTIES (xdrtest SHARED) + target_link_libraries (xdrtest PRIVATE ${HDF4_MF_LIBSH_TARGET}) +endif () +if (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") + target_compile_options(xdrtest PRIVATE "-Wno-incompatible-function-pointer-types") +endif () + #-- Adding test for hdfnctest set (hdfnctest_SRCS ${HDF4_MFHDF_TEST_SOURCE_DIR}/hdfnctest.c diff --git a/mfhdf/test/CMakeTests.cmake b/mfhdf/test/CMakeTests.cmake index cd4c7ceda8..b82bd756f6 100644 --- a/mfhdf/test/CMakeTests.cmake +++ b/mfhdf/test/CMakeTests.cmake @@ -131,23 +131,10 @@ set_tests_properties (MFHDF_TEST-hdfnctest PROPERTIES LABELS ${PROJECT_NAME} ) -#-- Adding test for xdrtest -add_executable (xdrtest ${HDF4_MFHDF_XDR_DIR}/xdrtest.c) -if (NOT BUILD_SHARED_LIBS) - TARGET_C_PROPERTIES (xdrtest STATIC) - target_link_libraries (xdrtest PRIVATE ${HDF4_MF_XDR_LIB_TARGET}) -else () - TARGET_C_PROPERTIES (xdrtest SHARED) - target_link_libraries (xdrtest PRIVATE ${HDF4_MF_XDR_LIBSH_TARGET}) -endif () -if (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") - target_compile_options(xdrtest PRIVATE "-Wno-incompatible-function-pointer-types") -endif () - if (MSVC_VERSION LESS 1900) - HDFTEST_COPY_FILE("${HDF4_MFHDF_XDR_DIR}/xdrtest.out" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") + HDFTEST_COPY_FILE("${HDF4_MFHDF_TEST_DIR}/xdrtest.out" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") else () - HDFTEST_COPY_FILE("${HDF4_MFHDF_XDR_DIR}/xdrtest.cyg" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") + HDFTEST_COPY_FILE("${HDF4_MFHDF_TEST_DIR}/xdrtest.cyg" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") endif () add_custom_target(xdrtest_files ALL COMMENT "Copying files needed by xdrtest tests" DEPENDS ${xdrtest_files_list}) diff --git a/mfhdf/test/Makefile.am b/mfhdf/test/Makefile.am index 1e790d98bc..c2740d0a8f 100644 --- a/mfhdf/test/Makefile.am +++ b/mfhdf/test/Makefile.am @@ -9,31 +9,32 @@ test_INCLUDES=-I$(top_srcdir)/hdf/src \ -I$(top_srcdir)/mfhdf/libsrc \ -I$(top_builddir)/mfhdf/libsrc DEFINES=-DHDF -AM_CPPFLAGS=$(test_INCLUDES) $(XDRINC) $(DEFINES) - -XDRLIB = $(top_builddir)/mfhdf/xdr/libxdr.la +AM_CPPFLAGS=$(test_INCLUDES) $(DEFINES) ############################################################################# ## Testing ## ############################################################################# -TEST_PROG = cdftest hdfnctest hdftest +TEST_PROG = cdftest hdfnctest hdftest xdrtest TEST_SCRIPT = testmfhdf.sh -check_PROGRAMS = cdftest hdfnctest hdftest +check_PROGRAMS = cdftest hdfnctest hdftest xdrtest check_SCRIPTS = testmfhdf.sh cdftest_SOURCES = cdftest.c -cdftest_LDADD = $(LIBMFHDF) $(LIBHDF) $(XDRLIB) @LIBS@ +cdftest_LDADD = $(LIBMFHDF) $(LIBHDF) @LIBS@ hdfnctest_SOURCES = hdfnctest.c tutils.c tncvargetfill.c tunlim.c \ tncunlim.c -hdfnctest_LDADD = $(LIBMFHDF) $(LIBHDF) $(XDRLIB) @LIBS@ +hdfnctest_LDADD = $(LIBMFHDF) $(LIBHDF) @LIBS@ hdftest_SOURCES = hdftest.c tutils.c tchunk.c tcomp.c tcoordvar.c \ tdim.c temptySDSs.c tattributes.c texternal.c tfile.c \ tmixed_apis.c tnetcdf.c trank0.c tsd.c tsdsprops.c \ tszip.c tattdatainfo.c tdatainfo.c tdatasizes.c -hdftest_LDADD = $(LIBMFHDF) $(LIBHDF) $(XDRLIB) @LIBS@ +hdftest_LDADD = $(LIBMFHDF) $(LIBHDF) @LIBS@ + +xdrtest_SOURCES = xdrtest.c +xdrtest_LDADD = $(LIBMFHDF) $(LIBHDF) @LIBS@ ############################################################################# ## And the cleanup ## diff --git a/mfhdf/xdr/test_xdr.sav b/mfhdf/test/test_xdr.sav similarity index 100% rename from mfhdf/xdr/test_xdr.sav rename to mfhdf/test/test_xdr.sav diff --git a/mfhdf/xdr/testout.sav b/mfhdf/test/xdr_testout.sav similarity index 100% rename from mfhdf/xdr/testout.sav rename to mfhdf/test/xdr_testout.sav diff --git a/mfhdf/xdr/xdrtest.c b/mfhdf/test/xdrtest.c similarity index 100% rename from mfhdf/xdr/xdrtest.c rename to mfhdf/test/xdrtest.c diff --git a/mfhdf/xdr/xdrtest.cyg b/mfhdf/test/xdrtest.cyg similarity index 100% rename from mfhdf/xdr/xdrtest.cyg rename to mfhdf/test/xdrtest.cyg diff --git a/mfhdf/xdr/xdrtest.out b/mfhdf/test/xdrtest.out similarity index 100% rename from mfhdf/xdr/xdrtest.out rename to mfhdf/test/xdrtest.out diff --git a/mfhdf/xdr/CMakeLists.txt b/mfhdf/xdr/CMakeLists.txt deleted file mode 100644 index e4dff12dec..0000000000 --- a/mfhdf/xdr/CMakeLists.txt +++ /dev/null @@ -1,92 +0,0 @@ -cmake_minimum_required (VERSION 3.12) -project (HDF4_MFHDF_XDR C) - -set (HDF4_MFHDF_XDR_SRCS - ${HDF4_MFHDF_XDR_SOURCE_DIR}/xdr.c - ${HDF4_MFHDF_XDR_SOURCE_DIR}/xdrfloat.c - ${HDF4_MFHDF_XDR_SOURCE_DIR}/xdrstdio.c - ${HDF4_MFHDF_XDR_SOURCE_DIR}/xdrarray.c -) - -set (HDF4_MFHDF_XDR_HDRS - ${HDF4_MFHDF_XDR_SOURCE_DIR}/xdr.h - ${HDF4_MFHDF_XDR_SOURCE_DIR}/types.h -) - -if (NOT ONLY_SHARED_LIBS) - add_library (${HDF4_MF_XDR_LIB_TARGET} STATIC ${HDF4_MFHDF_XDR_SRCS} ${HDF4_MFHDF_XDR_HDRS}) - target_include_directories(${HDF4_MF_XDR_LIB_TARGET} PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDF_XDR_SOURCE_DIR}") - target_compile_options(${HDF4_MF_XDR_LIB_TARGET} PRIVATE "${HDF4_CMAKE_C_FLAGS}") - target_compile_definitions(${HDF4_MF_XDR_LIB_TARGET} - PUBLIC - ${HDF_EXTRA_C_FLAGS} - ${HDF_EXTRA_FLAGS} - ) - target_link_libraries (${HDF4_MF_XDR_LIB_TARGET} PUBLIC "$<$,$>:ws2_32.lib>") - TARGET_C_PROPERTIES (${HDF4_MF_XDR_LIB_TARGET} STATIC) - set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_XDR_LIB_TARGET}") - H4_SET_LIB_OPTIONS (${HDF4_MF_XDR_LIB_TARGET} ${HDF4_MF_XDR_LIB_NAME} STATIC) - set_target_properties (${HDF4_MF_XDR_LIB_TARGET} PROPERTIES - FOLDER libraries - COMPILE_DEFINITIONS "HDF" - INTERFACE_INCLUDE_DIRECTORIES "$/include>" - ) - set (install_targets ${HDF4_MF_XDR_LIB_TARGET}) -endif () - -if (BUILD_SHARED_LIBS) - add_library (${HDF4_MF_XDR_LIBSH_TARGET} SHARED ${HDF4_MFHDF_XDR_SRCS} ${HDF4_MFHDF_XDR_HDRS}) - target_include_directories(${HDF4_MF_XDR_LIBSH_TARGET} PRIVATE "${HDF4_HDFSOURCE_DIR};${HDF4_MFHDF_XDR_SOURCE_DIR}") - target_compile_options(${HDF4_MF_XDR_LIBSH_TARGET} PRIVATE "${HDF4_CMAKE_C_FLAGS}") - target_compile_definitions(${HDF4_MF_XDR_LIBSH_TARGET} - PUBLIC - ${HDF_EXTRA_C_FLAGS} - ${HDF_EXTRA_FLAGS} - ) - target_link_libraries (${HDF4_MF_XDR_LIBSH_TARGET} PUBLIC "$<$,$>:ws2_32.lib>") - TARGET_C_PROPERTIES (${HDF4_MF_XDR_LIBSH_TARGET} SHARED) - set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_XDR_LIBSH_TARGET}") - H4_SET_LIB_OPTIONS (${HDF4_MF_XDR_LIBSH_TARGET} ${HDF4_MF_XDR_LIB_NAME} SHARED) - set_target_properties (${HDF4_MF_XDR_LIBSH_TARGET} PROPERTIES - FOLDER libraries - COMPILE_DEFINITIONS "HDF;H4_BUILT_AS_DYNAMIC_LIB" - INTERFACE_INCLUDE_DIRECTORIES "$/include>" - INTERFACE_COMPILE_DEFINITIONS H4_BUILT_AS_DYNAMIC_LIB=1 - ) - set (install_targets ${install_targets} ${HDF4_MF_XDR_LIBSH_TARGET}) -endif () - -#----------------------------------------------------------------------------- -# Add file(s) to CMake Install -#----------------------------------------------------------------------------- -install ( - FILES - ${HDF4_MFHDF_XDR_SOURCE_DIR}/xdr.h - ${HDF4_MFHDF_XDR_SOURCE_DIR}/types.h - DESTINATION - ${HDF4_INSTALL_INCLUDE_DIR} - COMPONENT - headers -) - -#----------------------------------------------------------------------------- -# Add library to CMake Install : Installs lib and cmake config info -#----------------------------------------------------------------------------- -if (BUILD_SHARED_LIBS) - INSTALL_TARGET_PDB (${HDF4_MF_XDR_LIBSH_TARGET} ${HDF4_INSTALL_BIN_DIR} libraries) -endif () -if (NOT ONLY_SHARED_LIBS) - INSTALL_TARGET_PDB (${HDF4_MF_XDR_LIB_TARGET} ${HDF4_INSTALL_LIB_DIR} libraries) -endif () - -install ( - TARGETS - ${install_targets} - EXPORT - ${HDF4_EXPORTED_TARGETS} - LIBRARY DESTINATION ${HDF4_INSTALL_LIB_DIR} COMPONENT libraries - ARCHIVE DESTINATION ${HDF4_INSTALL_LIB_DIR} COMPONENT libraries - RUNTIME DESTINATION ${HDF4_INSTALL_BIN_DIR} COMPONENT libraries - FRAMEWORK DESTINATION ${HDF4_INSTALL_FWRK_DIR} COMPONENT libraries - INCLUDES DESTINATION include -) diff --git a/mfhdf/xdr/Makefile.am b/mfhdf/xdr/Makefile.am deleted file mode 100644 index 1d1e52d2e9..0000000000 --- a/mfhdf/xdr/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -## Makefile.am -## Run automake to generate a Makefile.in from this file. -# -# XDR Library Makefile(.in) -# - -include $(top_srcdir)/config/commence.am - -## Setup the different includes and preprocessor #defines we need. -AM_CPPFLAGS=-I$(srcdir) -I$(top_srcdir)/hdf/src - -# XDR Library -lib_LTLIBRARIES = libxdr.la -libxdr_la_SOURCES = xdr.c xdrfloat.c xdrstdio.c xdrarray.c -include_HEADERS = xdr.h types.h - -LDADD = ./libxdr.la - -# Test program. Link using libxdr.la -check_PROGRAMS = xdrtest -TEST_PROG = xdrtest -xdrtest_SOURCES = xdrtest.c - -include $(top_srcdir)/config/conclude.am diff --git a/release_notes/RELEASE.txt b/release_notes/RELEASE.txt index 5bff03a034..060881615e 100644 --- a/release_notes/RELEASE.txt +++ b/release_notes/RELEASE.txt @@ -38,17 +38,24 @@ New features and changes ======================== Configuration: ------------- - - Removed XDR configuration options + - XDR changes We now only support building HDF4 with the XDR implementation packaged - with the HDF4 source. This is the first step of completely removing - XDR from the HDF4 library (to be replaced with a simplified I/O layer). + with the HDF4 source, which is always built with the mfhdf library. The following options have been removed: Autotools: --enable-hdf4-xdr CMake: HDF4_BUILD_XDR_LIB + The following header files are no longer deployed: + + types.h, xdr.h + + The XDR functionality has been incorporated into the mfhdf library, + so a separate XDR library is no longer distributed with either build + system. + - Incorporated HDF4 examples repository into HDF4 library. The HDF4Examples folder is equivalent to the repository hdf4-examples. From 21c1a28d899d3c126ef2ffc6794135fb04eedc09 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 04:21:05 -0800 Subject: [PATCH 05/52] Removed unused XDR functions --- mfhdf/libsrc/CMakeLists.txt | 4 +- mfhdf/libsrc/Makefile.am | 6 +- mfhdf/libsrc/xdr.c | 510 +++++------------------------------- mfhdf/libsrc/xdr.h | 96 ------- mfhdf/libsrc/xdrarray.c | 149 ----------- mfhdf/libsrc/xdrfloat.c | 111 -------- 6 files changed, 76 insertions(+), 800 deletions(-) delete mode 100644 mfhdf/libsrc/xdrarray.c delete mode 100644 mfhdf/libsrc/xdrfloat.c diff --git a/mfhdf/libsrc/CMakeLists.txt b/mfhdf/libsrc/CMakeLists.txt index a0783fc583..8fb5d64ab9 100644 --- a/mfhdf/libsrc/CMakeLists.txt +++ b/mfhdf/libsrc/CMakeLists.txt @@ -31,10 +31,8 @@ set (HDF4_MFHDF_LIBSRC_CSRCS ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/sharray.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/string.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/var.c - ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrposix.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdr.c - ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrarray.c - ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrfloat.c + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrposix.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrstdio.c ) diff --git a/mfhdf/libsrc/Makefile.am b/mfhdf/libsrc/Makefile.am index bad33fc488..d36195fca8 100644 --- a/mfhdf/libsrc/Makefile.am +++ b/mfhdf/libsrc/Makefile.am @@ -17,9 +17,9 @@ AM_CPPFLAGS = $(lib_INCLUDES) $(DEFINES) lib_LTLIBRARIES = libmfhdf.la ## Information for building the "libmfhdf.la" library -CSOURCES = array.c attr.c cdf.c dim.c file.c hdfsds.c iarray.c error.c \ - globdef.c mfsd.c mfdatainfo.c nssdc.c putget.c putgetg.c \ - sharray.c string.c var.c xdrposix.c xdr.c xdrfloat.c xdrstdio.c xdrarray.c +CSOURCES = array.c attr.c cdf.c dim.c file.c hdfsds.c iarray.c error.c \ + globdef.c mfsd.c mfdatainfo.c nssdc.c putget.c putgetg.c \ + sharray.c string.c var.c xdr.c xdrposix.c xdrstdio.c if HDF_BUILD_NETCDF FSOURCES = $(top_builddir)/mfhdf/fortran/jackets.c $(top_srcdir)/mfhdf/fortran/mfsdf.c $(top_srcdir)/mfhdf/fortran/mfsdff.f diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index af24f480c4..e966aa6552 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -75,16 +75,6 @@ xdr_free(xdrproc_t proc, void *objp) (*proc)(&x, objp); } -/* - * XDR nothing - */ -bool_t -xdr_void(void) -{ - - return TRUE; -} - /* * XDR integers */ @@ -177,62 +167,6 @@ xdr_u_long(XDR *xdrs, u_long *ulp) return (FALSE); } -/* - * XDR 32-bit integers - */ -bool_t -xdr_int32_t(XDR *xdrs, int32_t *int32_p) -{ - long l; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - l = (long)*int32_p; - return (XDR_PUTLONG(xdrs, &l)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, &l)) { - return (FALSE); - } - *int32_p = (int32_t)l; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - -/* - * XDR unsigned 32-bit integers - */ -bool_t -xdr_uint32_t(XDR *xdrs, uint32_t *uint32_p) -{ - u_long l; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - l = (u_long)*uint32_p; - return (XDR_PUTLONG(xdrs, (long *)&l)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, (long *)&l)) { - return (FALSE); - } - *uint32_p = (uint32_t)l; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - /* * XDR short integers */ @@ -289,178 +223,6 @@ xdr_u_short(XDR *xdrs, u_short *usp) return (FALSE); } -/* - * XDR 16-bit integers - */ -bool_t -xdr_int16_t(XDR *xdrs, int16_t *int16_p) -{ - long l; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - l = (long)*int16_p; - return (XDR_PUTLONG(xdrs, &l)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, &l)) { - return (FALSE); - } - *int16_p = (int16_t)l; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - -/* - * XDR unsigned 16-bit integers - */ -bool_t -xdr_uint16_t(XDR *xdrs, uint16_t *uint16_p) -{ - u_long l; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - l = (u_long)*uint16_p; - return (XDR_PUTLONG(xdrs, (long *)&l)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, (long *)&l)) { - return (FALSE); - } - *uint16_p = (uint16_t)l; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - -/* - * XDR 8-bit integers - */ -bool_t -xdr_int8_t(XDR *xdrs, int8_t *int8_p) -{ - long l; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - l = (long)*int8_p; - return (XDR_PUTLONG(xdrs, &l)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, &l)) { - return (FALSE); - } - *int8_p = (int8_t)l; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - -/* - * XDR unsigned 8-bit integers - */ -bool_t -xdr_uint8_t(XDR *xdrs, uint8_t *uint8_p) -{ - u_long l; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - l = (u_long)*uint8_p; - return (XDR_PUTLONG(xdrs, (long *)&l)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, (long *)&l)) { - return (FALSE); - } - *uint8_p = (uint8_t)l; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - -/* - * XDR a char - */ -bool_t -xdr_char(XDR *xdrs, char *cp) -{ - int i; - - i = (*cp); - if (!xdr_int(xdrs, &i)) { - return (FALSE); - } - *cp = i; - return (TRUE); -} - -/* - * XDR an unsigned char - */ -bool_t -xdr_u_char(XDR *xdrs, u_char *cp) -{ - u_int u; - - u = (*cp); - if (!xdr_u_int(xdrs, &u)) { - return (FALSE); - } - *cp = u; - return (TRUE); -} - -/* - * XDR booleans - */ -bool_t -xdr_bool(XDR *xdrs, bool_t *bp) -{ - long lb; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - lb = *bp ? XDR_TRUE : XDR_FALSE; - return (XDR_PUTLONG(xdrs, &lb)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, &lb)) { - return (FALSE); - } - *bp = (lb == XDR_FALSE) ? FALSE : TRUE; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - /* * XDR enumerations */ @@ -598,161 +360,105 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) return (FALSE); } -/* - * Implemented here due to commonality of the object. - */ bool_t -xdr_netobj(XDR *xdrs, struct netobj *np) +xdr_float(XDR *xdrs, float *fp) { + switch (xdrs->x_op) { - return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ)); -} - -/* - * XDR a descriminated union - * Support routine for discriminated unions. - * You create an array of xdrdiscrim structures, terminated with - * an entry with a null procedure pointer. The routine gets - * the discriminant value and then searches the array of xdrdiscrims - * looking for that value. It calls the procedure given in the xdrdiscrim - * to handle the discriminant. If there is no specific routine a default - * routine may be called. - * If there is no specific or default routine an error is returned. - */ -/* dscmp - enum to decide which arm to work on */ -/* unp - the union itself */ -/* choices - [value, xdr proc] for each arm */ -/* dfault - default xdr routine */ -bool_t -xdr_union(XDR *xdrs, enum_t *dscmp, char *unp, const struct xdr_discrim *choices, xdrproc_t dfault) -{ - enum_t dscm; + case XDR_ENCODE: + return (XDR_PUTINT32(xdrs, (int32_t *)fp)); - /* - * we deal with the discriminator; it's an enum - */ - if (!xdr_enum(xdrs, dscmp)) { - return (FALSE); - } - dscm = *dscmp; + case XDR_DECODE: + return (XDR_GETINT32(xdrs, (int32_t *)fp)); - /* - * search choices for a value that matches the discriminator. - * if we find one, execute the xdr routine for that value. - */ - for (; choices->proc != NULL_xdrproc_t; choices++) { - if (choices->value == dscm) - return ((*(choices->proc))(xdrs, unp)); + case XDR_FREE: + return (TRUE); } - - /* - * no match - execute the default xdr routine if there is one - */ - return ((dfault == NULL_xdrproc_t) ? FALSE : (*dfault)(xdrs, unp)); + return (FALSE); } -/* - * Non-portable xdr primitives. - * Care should be taken when moving these routines to new architectures. - */ - -/* - * XDR null terminated ASCII strings - * xdr_string deals with "C strings" - arrays of bytes that are - * terminated by a NULL character. The parameter cpp references a - * pointer to storage; If the pointer is null, then the necessary - * storage is allocated. The last parameter is the max allowed length - * of the string as specified by a protocol. - */ bool_t -xdr_string(XDR *xdrs, char **cpp, u_int maxsize) +xdr_double(XDR *xdrs, double *dp) { - char *sp = *cpp; /* sp is the actual string pointer */ - u_int size; - u_int nodesize; - bool_t ret, allocated = FALSE; + int32_t *i32p; + bool_t rv; - /* - * first deal with the length since xdr strings are counted-strings - */ - switch (xdrs->x_op) { - case XDR_FREE: - if (sp == NULL) { - return (TRUE); /* already free */ - } - /* FALLTHROUGH */ - case XDR_ENCODE: - if (sp == NULL) - return FALSE; - size = strlen(sp); - break; - case XDR_DECODE: - break; - } - if (!xdr_u_int(xdrs, &size)) { - return (FALSE); - } - if (size > maxsize) { - return (FALSE); - } - nodesize = size + 1; - if (nodesize == 0) { - /* This means an overflow. It a bug in the caller which - * provided a too large maxsize but nevertheless catch it - * here. - */ + if (!dp) return FALSE; - } - /* - * now deal with the actual bytes - */ switch (xdrs->x_op) { + case XDR_ENCODE: + i32p = (int32_t *)(void *)dp; +#ifdef H4_WORDS_BIGENDIAN + rv = XDR_PUTINT32(xdrs, i32p); + if (!rv) + return (rv); + rv = XDR_PUTINT32(xdrs, i32p + 1); +#else + rv = XDR_PUTINT32(xdrs, i32p + 1); + if (!rv) + return (rv); + rv = XDR_PUTINT32(xdrs, i32p); +#endif + return rv; + break; case XDR_DECODE: - if (sp == NULL) { - *cpp = sp = calloc(1, nodesize); - allocated = TRUE; - } - if (sp == NULL) { - fprintf(stderr, "xdr_string: out of memory\n"); - return (FALSE); - } - sp[size] = 0; - /* FALLTHROUGH */ - - case XDR_ENCODE: - ret = xdr_opaque(xdrs, sp, size); - if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) { - if (allocated == TRUE) { - free(sp); - *cpp = NULL; - } - } - return (ret); + i32p = (int32_t *)(void *)dp; +#ifdef H4_WORDS_BIGENDIAN + rv = XDR_GETINT32(xdrs, i32p); + if (!rv) + return (rv); + rv = XDR_GETINT32(xdrs, i32p + 1); +#else + rv = XDR_GETINT32(xdrs, i32p + 1); + if (!rv) + return (rv); + rv = XDR_GETINT32(xdrs, i32p); +#endif + return (rv); + break; case XDR_FREE: - free(sp); - *cpp = NULL; - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); + return TRUE; + } /* switch xdrs->x_op */ + + return FALSE; } -#define RPC_MAXDATASIZE 9000 /* - * Wrapper for xdr_string that can be called directly from - * routines like clnt_call + * xdr_vector(): + * + * XDR a fixed length array. Unlike variable-length arrays, + * the storage of fixed length arrays is static and unfreeable. + * > basep: base of the array + * > size: size of the array + * > elemsize: size of each element + * > xdr_elem: routine to XDR each element */ bool_t -xdr_wrapstring(XDR *xdrs, char **cpp) +xdr_vector(XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_elem) { - return xdr_string(xdrs, cpp, RPC_MAXDATASIZE); + u_int i; + char *elptr; + + elptr = basep; + for (i = 0; i < nelem; i++) { + if (!(*xdr_elem)(xdrs, elptr)) { + return (FALSE); + } + elptr += elemsize; + } + return (TRUE); } /* - * NOTE: xdr_hyper(), xdr_u_hyper(), xdr_longlong_t(), and xdr_u_longlong_t() + * Non-portable xdr primitives. + * Care should be taken when moving these routines to new architectures. + */ + +/* + * NOTE: xdr_longlong_t() and xdr_u_longlong_t() * are in the "non-portable" section because they require that a `long long' * be a 64-bit type. * @@ -816,75 +522,3 @@ xdr_uint64_t(XDR *xdrs, uint64_t *ullp) /* NOTREACHED */ return (FALSE); } - -/* - * XDR hypers - */ -bool_t -xdr_hyper(XDR *xdrs, longlong_t *llp) -{ - /* - * Don't bother open-coding this; it's a fair amount of code. Just - * call xdr_int64_t(). - */ - return (xdr_int64_t(xdrs, (int64_t *)llp)); -} - -/* - * XDR unsigned hypers - */ -bool_t -xdr_u_hyper(XDR *xdrs, u_longlong_t *ullp) -{ - /* - * Don't bother open-coding this; it's a fair amount of code. Just - * call xdr_uint64_t(). - */ - return (xdr_uint64_t(xdrs, (uint64_t *)ullp)); -} - -/* - * XDR longlong_t's - */ -bool_t -xdr_longlong_t(XDR *xdrs, longlong_t *llp) -{ - - /* - * Don't bother open-coding this; it's a fair amount of code. Just - * call xdr_int64_t(). - */ - return (xdr_int64_t(xdrs, (int64_t *)llp)); -} - -/* - * XDR u_longlong_t's - */ -bool_t -xdr_u_longlong_t(XDR *xdrs, u_longlong_t *ullp) -{ - - /* - * Don't bother open-coding this; it's a fair amount of code. Just - * call xdr_uint64_t(). - */ - return (xdr_uint64_t(xdrs, (uint64_t *)ullp)); -} - -/* - * XDR quad_t - */ -bool_t -xdr_quad_t(XDR *xdrs, int64_t *llp) -{ - return (xdr_int64_t(xdrs, (int64_t *)llp)); -} - -/* - * XDR u_quad_t - */ -bool_t -xdr_u_quad_t(XDR *xdrs, uint64_t *ullp) -{ - return (xdr_uint64_t(xdrs, (uint64_t *)ullp)); -} diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index d7d80b0123..f351dd4586 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -86,7 +86,6 @@ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; * This is the number of bytes per unit of external data. */ #define BYTES_PER_XDR_UNIT (4) -#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) * BYTES_PER_XDR_UNIT) /* * The XDR handle. @@ -183,130 +182,35 @@ xdr_putint32(XDR *xdrs, int32_t *ip) #define XDR_PUTBYTES(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) #define xdr_putbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) -#define XDR_GETPOS(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) #define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) - -#define XDR_SETPOS(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) #define xdr_setpos(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) - -#define XDR_INLINE(xdrs, len) (*(xdrs)->x_ops->x_inline)(xdrs, len) #define xdr_inline(xdrs, len) (*(xdrs)->x_ops->x_inline)(xdrs, len) -#define XDR_DESTROY(xdrs) \ - if ((xdrs)->x_ops->x_destroy) \ - (*(xdrs)->x_ops->x_destroy)(xdrs) #define xdr_destroy(xdrs) \ if ((xdrs)->x_ops->x_destroy) \ (*(xdrs)->x_ops->x_destroy)(xdrs) -/* - * Support struct for discriminated unions. - * You create an array of xdrdiscrim structures, terminated with - * an entry with a null procedure pointer. The xdr_union routine gets - * the discriminant value and then searches the array of structures - * for a matching value. If a match is found the associated xdr routine - * is called to handle that part of the union. If there is - * no match, then a default routine may be called. - * If there is no match and no default routine it is an error. - */ -#define NULL_xdrproc_t ((xdrproc_t)0) -struct xdr_discrim { - int value; - xdrproc_t proc; -}; - -/* - * In-line routines for fast encode/decode of primitive data types. - * Caveat emptor: these use single memory cycles to get the - * data from the underlying buffer, and will fail to operate - * properly if the data is not aligned. The standard way to use these - * is to say: - * if ((buf = XDR_INLINE(xdrs, count)) == NULL) - * return (FALSE); - * <<< macro calls >>> - * where ``count'' is the number of bytes of data occupied - * by the primitive data types. - * - * N.B. and frozen for all time: each data type here uses 4 bytes - * of external representation. - */ -#define IXDR_GET_INT32(buf) ((int32_t)ntohl((uint32_t) * (buf)++)) -#define IXDR_PUT_INT32(buf, v) (*(buf)++ = (int32_t)htonl((uint32_t)v)) -#define IXDR_GET_U_INT32(buf) ((uint32_t)IXDR_GET_INT32(buf)) -#define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32((buf), ((int32_t)(v))) - -#define IXDR_GET_LONG(buf) ((long)ntohl((uint32_t) * (buf)++)) -#define IXDR_PUT_LONG(buf, v) (*(buf)++ = (int32_t)htonl((uint32_t)v)) - -#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf)) -#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf)) -#define IXDR_GET_U_LONG(buf) ((u_long)IXDR_GET_LONG(buf)) -#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf)) -#define IXDR_GET_U_SHORT(buf) ((u_short)IXDR_GET_LONG(buf)) - -#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), (v)) -#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), (v)) -#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), (v)) -#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), (v)) -#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), (v)) - /* * These are the "generic" xdr routines. */ #ifdef __cplusplus extern "C" { #endif -XDRLIBAPI bool_t xdr_void(void); XDRLIBAPI bool_t xdr_int(XDR *, int *); XDRLIBAPI bool_t xdr_u_int(XDR *, u_int *); XDRLIBAPI bool_t xdr_long(XDR *, long *); XDRLIBAPI bool_t xdr_u_long(XDR *, u_long *); XDRLIBAPI bool_t xdr_short(XDR *, short *); XDRLIBAPI bool_t xdr_u_short(XDR *, u_short *); -XDRLIBAPI bool_t xdr_int8_t(XDR *, int8_t *); -XDRLIBAPI bool_t xdr_uint8_t(XDR *, uint8_t *); -XDRLIBAPI bool_t xdr_int16_t(XDR *, int16_t *); -XDRLIBAPI bool_t xdr_uint16_t(XDR *, uint16_t *); -XDRLIBAPI bool_t xdr_int32_t(XDR *, int32_t *); -XDRLIBAPI bool_t xdr_uint32_t(XDR *, uint32_t *); XDRLIBAPI bool_t xdr_int64_t(XDR *, int64_t *); XDRLIBAPI bool_t xdr_uint64_t(XDR *, uint64_t *); -XDRLIBAPI bool_t xdr_quad_t(XDR *, int64_t *); -XDRLIBAPI bool_t xdr_u_quad_t(XDR *, uint64_t *); -XDRLIBAPI bool_t xdr_bool(XDR *, bool_t *); XDRLIBAPI bool_t xdr_enum(XDR *, enum_t *); -XDRLIBAPI bool_t xdr_array(XDR *, char **, u_int *, u_int, u_int, xdrproc_t); XDRLIBAPI bool_t xdr_bytes(XDR *, char **, u_int *, u_int); XDRLIBAPI bool_t xdr_opaque(XDR *, char *, u_int); -XDRLIBAPI bool_t xdr_string(XDR *, char **, u_int); -XDRLIBAPI bool_t xdr_union(XDR *, enum_t *, char *, const struct xdr_discrim *, xdrproc_t); -XDRLIBAPI bool_t xdr_char(XDR *, char *); -XDRLIBAPI bool_t xdr_u_char(XDR *, u_char *); XDRLIBAPI bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t); XDRLIBAPI bool_t xdr_float(XDR *, float *); XDRLIBAPI bool_t xdr_double(XDR *, double *); -XDRLIBAPI bool_t xdr_quadruple(XDR *, long double *); -XDRLIBAPI bool_t xdr_reference(XDR *, char **, u_int, xdrproc_t); -XDRLIBAPI bool_t xdr_pointer(XDR *, char **, u_int, xdrproc_t); -XDRLIBAPI bool_t xdr_wrapstring(XDR *, char **); XDRLIBAPI void xdr_free(xdrproc_t, void *); -XDRLIBAPI bool_t xdr_hyper(XDR *, quad_t *); -XDRLIBAPI bool_t xdr_u_hyper(XDR *, u_quad_t *); -XDRLIBAPI bool_t xdr_longlong_t(XDR *, quad_t *); -XDRLIBAPI bool_t xdr_u_longlong_t(XDR *, u_quad_t *); -XDRLIBAPI u_long xdr_sizeof(xdrproc_t, void *); - -/* - * Common opaque bytes objects used by many rpc protocols; - * declared here due to commonality. - */ -#define MAX_NETOBJ_SZ 1024 -struct netobj { - u_int n_len; - char *n_bytes; -}; -typedef struct netobj netobj; -XDRLIBAPI bool_t xdr_netobj(XDR *, struct netobj *); /* * These are the public routines for the various implementations of diff --git a/mfhdf/libsrc/xdrarray.c b/mfhdf/libsrc/xdrarray.c deleted file mode 100644 index b4bc239e43..0000000000 --- a/mfhdf/libsrc/xdrarray.c +++ /dev/null @@ -1,149 +0,0 @@ - -/* - * Copyright (c) 2009, Sun Microsystems, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of Sun Microsystems, Inc. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * xdr_array.c, Generic XDR routines impelmentation. - * - * Copyright (C) 1984, Sun Microsystems, Inc. - * - * These are the "non-trivial" xdr primitives used to serialize and de-serialize - * arrays. See xdr.h for more info on the interface to xdr. - */ -#if !defined(lint) && defined(SCCSIDS) -static char sccsid[] = "@(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro"; -#endif - -#include "h4config.h" - -#include -#include /* for memset() */ -#include /* for UINT_MAX */ - -#include "types.h" -#include "xdr.h" - -#define LASTUNSIGNED ((u_int)0 - 1) - -/* - * XDR an array of arbitrary elements - * *addrp is a pointer to the array, *sizep is the number of elements. - * If addrp is NULL (*sizep * elsize) bytes are allocated. - * elsize is the size (in bytes) of each element, and elproc is the - * xdr procedure to call to handle each element of the array. - */ -/* addrp - array pointer */ -/* sizep - number of elements */ -/* maxsize - max numberof elements */ -/* elsize - size in bytes of each element */ -/* elproc - xdr routine to handle each element */ -bool_t -xdr_array(XDR *xdrs, char **addrp, u_int *sizep, u_int maxsize, u_int elsize, xdrproc_t elproc) -{ - u_int i; - char *target = *addrp; - u_int c; /* the actual element count */ - bool_t stat = TRUE; - u_int nodesize; - - /* like strings, arrays are really counted arrays */ - if (!xdr_u_int(xdrs, sizep)) { - return (FALSE); - } - c = *sizep; - if ((c > maxsize || UINT_MAX / elsize < c) && (xdrs->x_op != XDR_FREE)) { - return (FALSE); - } - nodesize = c * elsize; - - /* - * if we are deserializing, we may need to allocate an array. - * We also save time by checking for a null array if we are freeing. - */ - if (target == NULL) - switch (xdrs->x_op) { - case XDR_ENCODE: - break; /* keep gcc happy */ - case XDR_DECODE: - if (c == 0) - return (TRUE); - *addrp = target = calloc(1, nodesize); - if (target == NULL) { - (void)fprintf(stderr, "xdr_array: out of memory\n"); - return (FALSE); - } - (void)memset(target, 0, nodesize); - break; - - case XDR_FREE: - return (TRUE); - } - - /* - * now we xdr each element of array - */ - for (i = 0; (i < c) && stat; i++) { - stat = (*elproc)(xdrs, target); - target += elsize; - } - - /* - * the array may need freeing - */ - if (xdrs->x_op == XDR_FREE) { - free(*addrp); - *addrp = NULL; - } - return (stat); -} - -/* - * xdr_vector(): - * - * XDR a fixed length array. Unlike variable-length arrays, - * the storage of fixed length arrays is static and unfreeable. - * > basep: base of the array - * > size: size of the array - * > elemsize: size of each element - * > xdr_elem: routine to XDR each element - */ -bool_t -xdr_vector(XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_elem) -{ - u_int i; - char *elptr; - - elptr = basep; - for (i = 0; i < nelem; i++) { - if (!(*xdr_elem)(xdrs, elptr)) { - return (FALSE); - } - elptr += elemsize; - } - return (TRUE); -} diff --git a/mfhdf/libsrc/xdrfloat.c b/mfhdf/libsrc/xdrfloat.c deleted file mode 100644 index 80d57b7b3f..0000000000 --- a/mfhdf/libsrc/xdrfloat.c +++ /dev/null @@ -1,111 +0,0 @@ - -/* - * Copyright (c) 2009, Sun Microsystems, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of Sun Microsystems, Inc. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * xdr_float.c, Generic XDR routines implementation. - * - * Copyright (C) 1984, Sun Microsystems, Inc. - * - * These are the "floating point" xdr routines used to (de)serialize - * most common data items. See xdr.h for more info on the interface to - * xdr. - */ - -#include "h4config.h" - -#include - -#include "types.h" -#include "xdr.h" - -bool_t -xdr_float(XDR *xdrs, float *fp) -{ - switch (xdrs->x_op) { - - case XDR_ENCODE: - return (XDR_PUTINT32(xdrs, (int32_t *)fp)); - - case XDR_DECODE: - return (XDR_GETINT32(xdrs, (int32_t *)fp)); - - case XDR_FREE: - return (TRUE); - } - return (FALSE); -} - -bool_t -xdr_double(XDR *xdrs, double *dp) -{ - int32_t *i32p; - bool_t rv; - - if (!dp) - return FALSE; - - switch (xdrs->x_op) { - case XDR_ENCODE: - i32p = (int32_t *)(void *)dp; -#ifdef H4_WORDS_BIGENDIAN - rv = XDR_PUTINT32(xdrs, i32p); - if (!rv) - return (rv); - rv = XDR_PUTINT32(xdrs, i32p + 1); -#else - rv = XDR_PUTINT32(xdrs, i32p + 1); - if (!rv) - return (rv); - rv = XDR_PUTINT32(xdrs, i32p); -#endif - return rv; - break; - - case XDR_DECODE: - i32p = (int32_t *)(void *)dp; -#ifdef H4_WORDS_BIGENDIAN - rv = XDR_GETINT32(xdrs, i32p); - if (!rv) - return (rv); - rv = XDR_GETINT32(xdrs, i32p + 1); -#else - rv = XDR_GETINT32(xdrs, i32p + 1); - if (!rv) - return (rv); - rv = XDR_GETINT32(xdrs, i32p); -#endif - return (rv); - break; - - case XDR_FREE: - return TRUE; - } /* switch xdrs->x_op */ - - return FALSE; -} From ee9ecef9b538da49cdcfc930171594f25a7e3556 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 04:52:09 -0800 Subject: [PATCH 06/52] Removed unused things from XDR struct --- mfhdf/libsrc/xdr.h | 3 --- mfhdf/libsrc/xdrposix.c | 4 ---- mfhdf/libsrc/xdrstdio.c | 5 +---- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index f351dd4586..3147b578ce 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -112,10 +112,7 @@ typedef struct __rpc_xdr { /* Control */ bool_t (*x_control)(struct __rpc_xdr *, int, void *); } * x_ops; - char *x_public; /* users' data */ void *x_private; /* pointer to private data */ - char *x_base; /* private used for position info */ - u_int x_handy; /* extra private word */ } XDR; /*                                                                                diff --git a/mfhdf/libsrc/xdrposix.c b/mfhdf/libsrc/xdrposix.c index df412d4ce2..daa76bb1bb 100644 --- a/mfhdf/libsrc/xdrposix.c +++ b/mfhdf/libsrc/xdrposix.c @@ -231,7 +231,6 @@ static struct xdr_ops xdrposix_ops = { xdrposix_setpos, /* set offset in the stream */ xdrposix_inline, /* prime stream for inline macros */ xdrposix_destroy, /* destroy stream */ - NULL, /* no xdr_control function defined */ #if defined(__sun) && defined(_LP64) /* Solaris 64-bit (arch=v9 and arch=amd64) differentiates between * 32-bit integers and 64-bit longs via two extra callbacks for @@ -277,9 +276,6 @@ xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) xdrs->x_op = op; xdrs->x_ops = &xdrposix_ops; xdrs->x_private = (char *)biop; - /* unused */ - xdrs->x_handy = 0; - xdrs->x_base = 0; if (biop == NULL) return -1; diff --git a/mfhdf/libsrc/xdrstdio.c b/mfhdf/libsrc/xdrstdio.c index ae91ba9788..c67a1dea10 100644 --- a/mfhdf/libsrc/xdrstdio.c +++ b/mfhdf/libsrc/xdrstdio.c @@ -74,8 +74,7 @@ static const struct xdr_ops xdrstdio_ops = { xdrstdio_getpos, /* get offset in the stream */ xdrstdio_setpos, /* set offset in the stream */ xdrstdio_inline, /* prime stream for inline macros */ - xdrstdio_destroy, /* destroy stream */ - NULL /* control */ + xdrstdio_destroy /* destroy stream */ }; /* @@ -89,8 +88,6 @@ xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_op op) xdrs->x_op = op; xdrs->x_ops = &xdrstdio_ops; xdrs->x_private = file; - xdrs->x_handy = 0; - xdrs->x_base = 0; } /* From afeded4e4dd0c714a3098d717cba2dac8a568806 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 04:54:50 -0800 Subject: [PATCH 07/52] Remove XDRDEBUG code --- mfhdf/libsrc/xdrposix.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/mfhdf/libsrc/xdrposix.c b/mfhdf/libsrc/xdrposix.c index daa76bb1bb..ae235090ea 100644 --- a/mfhdf/libsrc/xdrposix.c +++ b/mfhdf/libsrc/xdrposix.c @@ -269,10 +269,6 @@ static int xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) { biobuf *biop = new_biobuf(fd, fmode); -#ifdef XDRDEBUG - fprintf(stderr, "xdrposix_create(): xdrs=%p, fd=%d, fmode=%d, op=%d\n", xdrs, fd, fmode, (int)op); - fprintf(stderr, "xdrposix_create(): after new_biobuf(), biop=%p\n", biop); -#endif xdrs->x_op = op; xdrs->x_ops = &xdrposix_ops; xdrs->x_private = (char *)biop; @@ -283,9 +279,6 @@ xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) if ((biop->mode & O_WRONLY) || (biop->mode & O_CREAT)) return 0; -#ifdef XDRDEBUG - fprintf(stderr, "xdrposix_create(): before rdbuf()\n"); -#endif /* else, read the first bufferful */ return rdbuf(biop); } @@ -474,9 +467,6 @@ NCxdrfile_create(XDR *xdrs, const char *path, int ncmode) int fd; enum xdr_op op; -#ifdef XDRDEBUG - fprintf(stderr, "NCxdrfile_create(): XDR=%p, path=%s, ncmode=%d\n", xdrs, path, ncmode); -#endif switch (ncmode & 0x0f) { case NC_NOCLOBBER: fmode = O_RDWR | O_CREAT | O_EXCL; @@ -501,9 +491,6 @@ NCxdrfile_create(XDR *xdrs, const char *path, int ncmode) #endif fd = open(path, fmode, 0666); -#ifdef XDRDEBUG - fprintf(stderr, "NCxdrfile_create(): fmode=%d, fd=%d\n", fmode, fd); -#endif if (fd == -1) { nc_serror("filename \"%s\"", path); return -1; @@ -516,13 +503,8 @@ NCxdrfile_create(XDR *xdrs, const char *path, int ncmode) op = XDR_DECODE; } -#ifdef XDRDEBUG - fprintf(stderr, "NCxdrfile_create(): before xdrposix_create()\n"); -#endif if (xdrposix_create(xdrs, fd, fmode, op) < 0) return -1; -#ifdef XDRDEBUG - fprintf(stderr, "NCxdrfile_create(): after xdrposix_create()\n"); -#endif - return fd; + else + return fd; } From 746d7a80ff07d17652f40c6e3579efe1892ca3b1 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 11:13:14 -0800 Subject: [PATCH 08/52] Remove control and inline fields from XDR struct --- mfhdf/libsrc/xdr.h | 5 ----- mfhdf/libsrc/xdrposix.c | 1 - mfhdf/libsrc/xdrstdio.c | 19 ------------------- 3 files changed, 25 deletions(-) diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 3147b578ce..911bbdb93e 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -105,12 +105,8 @@ typedef struct __rpc_xdr { /* Get or seek within the stream (offsets from beginning of stream). */ u_int (*x_getpostn)(struct __rpc_xdr *); bool_t (*x_setpostn)(struct __rpc_xdr *, u_int); - /* Returns a pointer to the next n bytes in the stream. */ - int32_t *(*x_inline)(struct __rpc_xdr *, u_int); /* Free the stream. */ void (*x_destroy)(struct __rpc_xdr *); - /* Control */ - bool_t (*x_control)(struct __rpc_xdr *, int, void *); } * x_ops; void *x_private; /* pointer to private data */ } XDR; @@ -181,7 +177,6 @@ xdr_putint32(XDR *xdrs, int32_t *ip) #define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) #define xdr_setpos(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) -#define xdr_inline(xdrs, len) (*(xdrs)->x_ops->x_inline)(xdrs, len) #define xdr_destroy(xdrs) \ if ((xdrs)->x_ops->x_destroy) \ diff --git a/mfhdf/libsrc/xdrposix.c b/mfhdf/libsrc/xdrposix.c index ae235090ea..eb2b898086 100644 --- a/mfhdf/libsrc/xdrposix.c +++ b/mfhdf/libsrc/xdrposix.c @@ -229,7 +229,6 @@ static struct xdr_ops xdrposix_ops = { xdrposix_putbytes, /* serialize counted bytes */ xdrposix_getpos, /* get offset in the stream */ xdrposix_setpos, /* set offset in the stream */ - xdrposix_inline, /* prime stream for inline macros */ xdrposix_destroy, /* destroy stream */ #if defined(__sun) && defined(_LP64) /* Solaris 64-bit (arch=v9 and arch=amd64) differentiates between diff --git a/mfhdf/libsrc/xdrstdio.c b/mfhdf/libsrc/xdrstdio.c index c67a1dea10..82c652ccf0 100644 --- a/mfhdf/libsrc/xdrstdio.c +++ b/mfhdf/libsrc/xdrstdio.c @@ -61,7 +61,6 @@ static bool_t xdrstdio_getbytes(XDR *, char *, u_int); static bool_t xdrstdio_putbytes(XDR *, const char *, u_int); static u_int xdrstdio_getpos(XDR *); static bool_t xdrstdio_setpos(XDR *, u_int); -static int32_t *xdrstdio_inline(XDR *, u_int); /* * Ops vector for stdio type XDR @@ -73,7 +72,6 @@ static const struct xdr_ops xdrstdio_ops = { xdrstdio_putbytes, /* serialize counted bytes */ xdrstdio_getpos, /* get offset in the stream */ xdrstdio_setpos, /* set offset in the stream */ - xdrstdio_inline, /* prime stream for inline macros */ xdrstdio_destroy /* destroy stream */ }; @@ -158,20 +156,3 @@ xdrstdio_setpos(XDR *xdrs, u_int pos) return ((fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ? FALSE : TRUE); } - -static int32_t * -xdrstdio_inline(XDR *xdrs, u_int len) -{ - (void)xdrs; - (void)len; - /* - * Must do some work to implement this: must insure - * enough data in the underlying stdio buffer, - * that the buffer is aligned so that we can indirect through a - * long *, and stuff this pointer in xdrs->x_buf. Doing - * a fread or fwrite to a scratch buffer would defeat - * most of the gains to be had here and require storage - * management on this buffer, so we don't do this. - */ - return (NULL); -} From ef3bec36f657d680defa23f6e48fa5a2f035eec0 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 11:23:08 -0800 Subject: [PATCH 09/52] Moved types.h content to xdr.h --- mfhdf/libsrc/CMakeLists.txt | 1 - mfhdf/libsrc/local_nc.h | 1 - mfhdf/libsrc/types.h | 88 ------------------------------------- mfhdf/libsrc/xdr.c | 1 - mfhdf/libsrc/xdr.h | 39 ++++++++++++++++ mfhdf/libsrc/xdrstdio.c | 1 - mfhdf/test/xdrtest.c | 4 +- 7 files changed, 42 insertions(+), 93 deletions(-) delete mode 100644 mfhdf/libsrc/types.h diff --git a/mfhdf/libsrc/CMakeLists.txt b/mfhdf/libsrc/CMakeLists.txt index 8fb5d64ab9..2fdac31c6c 100644 --- a/mfhdf/libsrc/CMakeLists.txt +++ b/mfhdf/libsrc/CMakeLists.txt @@ -48,7 +48,6 @@ set (HDF4_MFHDF_LIBSRC_CHDRS ${HDF4_MFHDF_LIBSRC_INSTALL_CHDRS} ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/error.h ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/mfprivate.h - ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/types.h ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdr.h ) diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index e7fa2c4f42..dbb29b0c18 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -31,7 +31,6 @@ #endif /* Local XDR files */ -#include "types.h" #include "xdr.h" #ifdef H4_HAVE_NETCDF diff --git a/mfhdf/libsrc/types.h b/mfhdf/libsrc/types.h deleted file mode 100644 index a9b03d0ca1..0000000000 --- a/mfhdf/libsrc/types.h +++ /dev/null @@ -1,88 +0,0 @@ -/* $NetBSD: types.h,v 1.13 2000/06/13 01:02:44 thorpej Exp $ */ - -/* - * Copyright (c) 2009, Sun Microsystems, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of Sun Microsystems, Inc. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * from: @(#)types.h 1.18 87/07/24 SMI - * from: @(#)types.h 2.3 88/08/15 4.0 RPCSRC - * $FreeBSD: src/include/rpc/types.h,v 1.10.6.1 2003/12/18 00:59:50 peter Exp $ - */ -/* - * Rpc additions to - */ -#ifndef H4_XDR_TYPES_H -#define H4_XDR_TYPES_H - -#include "h4config.h" - -#include -#include -#include -#include - -#ifdef H4_HAVE_SYS_TIME_H -#include -#endif - -#ifdef H4_HAVE_SYS_TYPES_H -#include -#endif - -#ifndef u_char -typedef unsigned char u_char; -#endif -#ifndef u_short -typedef uint16_t u_short; -#endif -#ifndef u_int -typedef uint32_t u_int; -#endif -#ifndef u_long -typedef unsigned long u_long; -#endif -#ifndef u_quad_t -typedef uint64_t u_quad_t; -#endif -#ifndef quad_t -typedef int64_t quad_t; -#endif -#ifndef caddr_t -typedef char *caddr_t; -#endif - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -typedef int32_t bool_t; - -/* Define the enumerated type in the wire protocol. */ -typedef int32_t enum_t; - -#endif /* H4_XDR_TYPES_H */ diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index e966aa6552..0583b0502c 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -44,7 +44,6 @@ static char sccsid[] = "@(#)xdr.c 1.35 87/08/12"; #include #include -#include "types.h" #include "xdr.h" typedef quad_t longlong_t; /* ANSI long long type */ diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 911bbdb93e..47247e4b6e 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -43,8 +43,47 @@ #include "H4api_adpt.h" +#include +#include #include +#ifdef H4_HAVE_SYS_TYPES_H +#include +#endif + +#ifndef u_char +typedef unsigned char u_char; +#endif +#ifndef u_short +typedef uint16_t u_short; +#endif +#ifndef u_int +typedef uint32_t u_int; +#endif +#ifndef u_long +typedef unsigned long u_long; +#endif +#ifndef u_quad_t +typedef uint64_t u_quad_t; +#endif +#ifndef quad_t +typedef int64_t quad_t; +#endif +#ifndef caddr_t +typedef char *caddr_t; +#endif + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif +typedef int32_t bool_t; + +/* Define the enumerated type in the wire protocol. */ +typedef int32_t enum_t; + /* * XDR provides a conventional way for converting between C data * types and an external bit-string representation. Library supplied diff --git a/mfhdf/libsrc/xdrstdio.c b/mfhdf/libsrc/xdrstdio.c index 82c652ccf0..4785aa9629 100644 --- a/mfhdf/libsrc/xdrstdio.c +++ b/mfhdf/libsrc/xdrstdio.c @@ -51,7 +51,6 @@ #endif #endif -#include "types.h" #include "xdr.h" static void xdrstdio_destroy(XDR *); diff --git a/mfhdf/test/xdrtest.c b/mfhdf/test/xdrtest.c index 379a954435..3ba18dde9c 100644 --- a/mfhdf/test/xdrtest.c +++ b/mfhdf/test/xdrtest.c @@ -5,6 +5,9 @@ #include "h4config.h" +#include +#include + /* * This program tests only the xdr library functionality required by netCDF. * 'xdr_vector' is not used by the netCDF, it is used here for convenience. @@ -26,7 +29,6 @@ } /* Local XDR files */ -#include "types.h" #include "xdr.h" #define TESTFILE "test.xdr" From 0ed84f96e1671cbb8e4edf2fce56f7604b593cf8 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 11:33:24 -0800 Subject: [PATCH 10/52] Removed unused XDR header cruft --- mfhdf/libsrc/local_nc.h | 1 - mfhdf/libsrc/xdr.c | 13 ------------- mfhdf/libsrc/xdr.h | 18 ------------------ mfhdf/test/xdrtest.c | 14 +++----------- 4 files changed, 3 insertions(+), 43 deletions(-) diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index dbb29b0c18..42b7bd915f 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -30,7 +30,6 @@ #define FILENAME_MAX 255 #endif -/* Local XDR files */ #include "xdr.h" #ifdef H4_HAVE_NETCDF diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 0583b0502c..ef0defe69a 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -35,9 +35,6 @@ * most common data items. See xdr.h for more info on the interface to * xdr. */ -#if !defined(lint) && defined(SCCSIDS) -static char sccsid[] = "@(#)xdr.c 1.35 87/08/12"; -#endif #include "h4config.h" @@ -46,16 +43,6 @@ static char sccsid[] = "@(#)xdr.c 1.35 87/08/12"; #include "xdr.h" -typedef quad_t longlong_t; /* ANSI long long type */ -typedef u_quad_t u_longlong_t; /* ANSI unsigned long long type */ - -/* - * constants specific to the xdr "protocol" - */ -#define XDR_FALSE ((long)0) -#define XDR_TRUE ((long)1) -#define LASTUNSIGNED ((u_int)0 - 1) - /* * for unit alignment */ diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 47247e4b6e..7392a5ce1d 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -1,5 +1,3 @@ -/* $NetBSD: xdr.h,v 1.19 2000/07/17 05:00:45 matt Exp $ */ - /* * Copyright (c) 2009, Sun Microsystems, Inc. * All rights reserved. @@ -26,10 +24,6 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. - * - * from: @(#)xdr.h 1.19 87/04/22 SMI - * from: @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC - * $FreeBSD: src/include/rpc/xdr.h,v 1.23 2003/03/07 13:19:40 nectar Exp $ */ /* @@ -51,9 +45,6 @@ #include #endif -#ifndef u_char -typedef unsigned char u_char; -#endif #ifndef u_short typedef uint16_t u_short; #endif @@ -63,15 +54,6 @@ typedef uint32_t u_int; #ifndef u_long typedef unsigned long u_long; #endif -#ifndef u_quad_t -typedef uint64_t u_quad_t; -#endif -#ifndef quad_t -typedef int64_t quad_t; -#endif -#ifndef caddr_t -typedef char *caddr_t; -#endif #ifndef TRUE #define TRUE 1 diff --git a/mfhdf/test/xdrtest.c b/mfhdf/test/xdrtest.c index 3ba18dde9c..bbe0d71d49 100644 --- a/mfhdf/test/xdrtest.c +++ b/mfhdf/test/xdrtest.c @@ -13,14 +13,6 @@ * 'xdr_vector' is not used by the netCDF, it is used here for convenience. */ -#ifdef H4_HAVE_NETINET_IN_H -#include /* for htonl() */ -#else -#ifdef H4_HAVE_WINSOCK2_H -#include -#endif -#endif - #define xdr_assert(ex) \ { \ if (!(ex)) { \ @@ -28,18 +20,18 @@ } \ } -/* Local XDR files */ #include "xdr.h" #define TESTFILE "test.xdr" + /* if this is NOT defined, then the program just reads the file */ #define CREATE #ifdef __FreeBSD__ #define EPSILON .005 -#else /* __FreeBSD__ */ +#else #define EPSILON .0005 -#endif /* __FreeBSD__ */ +#endif int main(int ac, char *av[]) From 52d3243b9d8578d85415c26c3be705228e39c404 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 11:38:39 -0800 Subject: [PATCH 11/52] Removed xdr_enum, which was unused --- mfhdf/libsrc/xdr.c | 25 ------------------------- mfhdf/libsrc/xdr.h | 1 - mfhdf/test/xdrtest.c | 21 +-------------------- 3 files changed, 1 insertion(+), 46 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index ef0defe69a..91cb71bc8b 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -209,31 +209,6 @@ xdr_u_short(XDR *xdrs, u_short *usp) return (FALSE); } -/* - * XDR enumerations - */ -bool_t -xdr_enum(XDR *xdrs, enum_t *ep) -{ - enum sizecheck { SIZEVAL }; /* used to find the size of an enum */ - - /* - * enums are treated as ints - */ - if (sizeof(enum sizecheck) == sizeof(long)) { - return xdr_long(xdrs, (long *)(void *)ep); - } - else if (sizeof(enum sizecheck) == sizeof(int)) { - return xdr_int(xdrs, (int *)(void *)ep); - } - else if (sizeof(enum sizecheck) == sizeof(short)) { - return xdr_short(xdrs, (short *)(void *)ep); - } - else { - return FALSE; - } -} - /* * XDR opaque data * Allows the specification of a fixed size sequence of opaque bytes. diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 7392a5ce1d..6e6b166772 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -217,7 +217,6 @@ XDRLIBAPI bool_t xdr_short(XDR *, short *); XDRLIBAPI bool_t xdr_u_short(XDR *, u_short *); XDRLIBAPI bool_t xdr_int64_t(XDR *, int64_t *); XDRLIBAPI bool_t xdr_uint64_t(XDR *, uint64_t *); -XDRLIBAPI bool_t xdr_enum(XDR *, enum_t *); XDRLIBAPI bool_t xdr_bytes(XDR *, char **, u_int *, u_int); XDRLIBAPI bool_t xdr_opaque(XDR *, char *, u_int); XDRLIBAPI bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t); diff --git a/mfhdf/test/xdrtest.c b/mfhdf/test/xdrtest.c index bbe0d71d49..7f55ea29ae 100644 --- a/mfhdf/test/xdrtest.c +++ b/mfhdf/test/xdrtest.c @@ -64,7 +64,7 @@ main(int ac, char *av[]) 12556, }; - u_int poses[9]; + u_int poses[8]; int jj = 0; static char text[32] = {"Hiya sailor. New in town?"}; @@ -97,10 +97,6 @@ main(int ac, char *av[]) double *dp, got_ad[5]; - typedef enum { ZERO_E, ONE_E, TWO_E, THREE_E, FOUR_E } encount; - static encount encounts[5] = {ZERO_E, ONE_E, TWO_E, THREE_E, FOUR_E}; - encount *ep, got_ep[5]; - fname = TESTFILE; if (ac > 1) { fname = av[1]; @@ -168,12 +164,6 @@ main(int ac, char *av[]) xdr_assert(xdr_vector(xdrs, (char *)doubles, count, szof, (xdrproc_t)xdr_double)); poses[jj++] = xdr_getpos(xdrs); - /* again no setpos */ - szof = sizeof(encount); - count = sizeof(encounts) / sizeof(encount); - xdr_assert(xdr_vector(xdrs, (char *)encounts, count, szof, (xdrproc_t)xdr_enum)); - poses[jj++] = xdr_getpos(xdrs); - /* flush, rewind and reopen */ xdr_assert(fflush((FILE *)xdrs->x_private) != EOF); /* xdr_destroy(xdrs) */ @@ -281,15 +271,6 @@ main(int ac, char *av[]) } putchar('\n'); - szof = sizeof(encount); - count = sizeof(encounts) / sizeof(encount); - xdr_assert(xdr_vector(xdrs, (char *)got_ep, count, szof, (xdrproc_t)xdr_enum)); - printf("enums: "); - for (ii = 0, ep = got_ep; ii < (int)count; ii++, ep++) { - printf("%d ", (int)*ep); - xdr_assert(*ep == encounts[ii]); - } - putchar('\n'); xdr_assert(poses[jj++] = xdr_getpos(xdrs)); exit(EXIT_SUCCESS); From f48d11131d3cd1c9e3dbaffd81f240c14315e975 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 11:41:48 -0800 Subject: [PATCH 12/52] Remove xdr_short and xdr_u_short --- mfhdf/libsrc/xdr.c | 56 ---------------------------------------------- mfhdf/libsrc/xdr.h | 5 ----- 2 files changed, 61 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 91cb71bc8b..9cb4f2d5b3 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -153,62 +153,6 @@ xdr_u_long(XDR *xdrs, u_long *ulp) return (FALSE); } -/* - * XDR short integers - */ -bool_t -xdr_short(XDR *xdrs, short *sp) -{ - long l; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - l = (long)*sp; - return (XDR_PUTLONG(xdrs, &l)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, &l)) { - return (FALSE); - } - *sp = (short)l; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - -/* - * XDR unsigned short integers - */ -bool_t -xdr_u_short(XDR *xdrs, u_short *usp) -{ - u_long l; - - switch (xdrs->x_op) { - - case XDR_ENCODE: - l = (u_long)*usp; - return (XDR_PUTLONG(xdrs, (long *)&l)); - - case XDR_DECODE: - if (!XDR_GETLONG(xdrs, (long *)&l)) { - return (FALSE); - } - *usp = (u_short)l; - return (TRUE); - - case XDR_FREE: - return (TRUE); - } - /* NOTREACHED */ - return (FALSE); -} - /* * XDR opaque data * Allows the specification of a fixed size sequence of opaque bytes. diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 6e6b166772..71963516cb 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -45,9 +45,6 @@ #include #endif -#ifndef u_short -typedef uint16_t u_short; -#endif #ifndef u_int typedef uint32_t u_int; #endif @@ -213,8 +210,6 @@ XDRLIBAPI bool_t xdr_int(XDR *, int *); XDRLIBAPI bool_t xdr_u_int(XDR *, u_int *); XDRLIBAPI bool_t xdr_long(XDR *, long *); XDRLIBAPI bool_t xdr_u_long(XDR *, u_long *); -XDRLIBAPI bool_t xdr_short(XDR *, short *); -XDRLIBAPI bool_t xdr_u_short(XDR *, u_short *); XDRLIBAPI bool_t xdr_int64_t(XDR *, int64_t *); XDRLIBAPI bool_t xdr_uint64_t(XDR *, uint64_t *); XDRLIBAPI bool_t xdr_bytes(XDR *, char **, u_int *, u_int); From 2058ebd9a126c28087725202b6e852083824e0b0 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 12:08:14 -0800 Subject: [PATCH 13/52] Removed capital flavor of XDR macros Also, other misc cleanup --- mfhdf/libsrc/file.c | 11 ++-- mfhdf/libsrc/xdr.c | 132 ++++++++++++++++++++++---------------------- mfhdf/libsrc/xdr.h | 47 ++++++---------- 3 files changed, 88 insertions(+), 102 deletions(-) diff --git a/mfhdf/libsrc/file.c b/mfhdf/libsrc/file.c index d5b7707cc5..d2c93f46e0 100644 --- a/mfhdf/libsrc/file.c +++ b/mfhdf/libsrc/file.c @@ -701,9 +701,6 @@ NC_begins(NC *handle) * Copy nbytes bytes from source to target. * Streams target and source should be positioned before the call. * opaque I/O, no XDR conversion performed (or needed). - * The Macros XDR_GETBYTES and XDR_PUTBYTES may not be - * supported on your xdr implementation. If not, calls - * to xdr_opaque may be used. */ bool_t NC_dcpy(XDR *target, XDR *source, long nbytes) @@ -713,16 +710,16 @@ NC_dcpy(XDR *target, XDR *source, long nbytes) char buf[NC_DCP_BUFSIZE]; while (nbytes > sizeof(buf)) { - if (!XDR_GETBYTES(source, buf, sizeof(buf))) + if (!xdr_getbytes(source, buf, sizeof(buf))) goto err; - if (!XDR_PUTBYTES(target, buf, sizeof(buf))) + if (!xdr_putbytes(target, buf, sizeof(buf))) goto err; nbytes -= sizeof(buf); } /* we know nbytes <= sizeof(buf) at this point */ - if (!XDR_GETBYTES(source, buf, nbytes)) + if (!xdr_getbytes(source, buf, nbytes)) goto err; - if (!XDR_PUTBYTES(target, buf, nbytes)) + if (!xdr_putbytes(target, buf, nbytes)) goto err; return (TRUE); err: diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 9cb4f2d5b3..814fe0cee6 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -73,20 +73,20 @@ xdr_int(XDR *xdrs, int *ip) case XDR_ENCODE: l = (long)*ip; - return (XDR_PUTLONG(xdrs, &l)); + return (xdr_putlong(xdrs, &l)); case XDR_DECODE: - if (!XDR_GETLONG(xdrs, &l)) { - return (FALSE); + if (!xdr_getlong(xdrs, &l)) { + return FALSE; } *ip = (int)l; - return (TRUE); + return TRUE; case XDR_FREE: - return (TRUE); + return TRUE; } /* NOTREACHED */ - return (FALSE); + return FALSE; } /* @@ -101,20 +101,20 @@ xdr_u_int(XDR *xdrs, u_int *up) case XDR_ENCODE: l = (u_long)*up; - return (XDR_PUTLONG(xdrs, (long *)&l)); + return (xdr_putlong(xdrs, (long *)&l)); case XDR_DECODE: - if (!XDR_GETLONG(xdrs, (long *)&l)) { - return (FALSE); + if (!xdr_getlong(xdrs, (long *)&l)) { + return FALSE; } *up = (u_int)l; - return (TRUE); + return TRUE; case XDR_FREE: - return (TRUE); + return TRUE; } /* NOTREACHED */ - return (FALSE); + return FALSE; } /* @@ -125,14 +125,14 @@ xdr_long(XDR *xdrs, long *lp) { switch (xdrs->x_op) { case XDR_ENCODE: - return (XDR_PUTLONG(xdrs, lp)); + return (xdr_putlong(xdrs, lp)); case XDR_DECODE: - return (XDR_GETLONG(xdrs, lp)); + return (xdr_getlong(xdrs, lp)); case XDR_FREE: - return (TRUE); + return TRUE; } /* NOTREACHED */ - return (FALSE); + return FALSE; } /* @@ -143,14 +143,14 @@ xdr_u_long(XDR *xdrs, u_long *ulp) { switch (xdrs->x_op) { case XDR_ENCODE: - return (XDR_PUTLONG(xdrs, (long *)ulp)); + return (xdr_putlong(xdrs, (long *)ulp)); case XDR_DECODE: - return (XDR_GETLONG(xdrs, (long *)ulp)); + return (xdr_getlong(xdrs, (long *)ulp)); case XDR_FREE: - return (TRUE); + return TRUE; } /* NOTREACHED */ - return (FALSE); + return FALSE; } /* @@ -168,7 +168,7 @@ xdr_opaque(XDR *xdrs, char *cp, u_int cnt) * if no data we are done */ if (cnt == 0) - return (TRUE); + return TRUE; /* * round byte count to full xdr units @@ -178,28 +178,28 @@ xdr_opaque(XDR *xdrs, char *cp, u_int cnt) rndup = BYTES_PER_XDR_UNIT - rndup; if (xdrs->x_op == XDR_DECODE) { - if (!XDR_GETBYTES(xdrs, cp, cnt)) { - return (FALSE); + if (!xdr_getbytes(xdrs, cp, cnt)) { + return FALSE; } if (rndup == 0) - return (TRUE); - return (XDR_GETBYTES(xdrs, (char *)crud, rndup)); + return TRUE; + return (xdr_getbytes(xdrs, (char *)crud, rndup)); } if (xdrs->x_op == XDR_ENCODE) { - if (!XDR_PUTBYTES(xdrs, cp, cnt)) { - return (FALSE); + if (!xdr_putbytes(xdrs, cp, cnt)) { + return FALSE; } if (rndup == 0) - return (TRUE); - return (XDR_PUTBYTES(xdrs, xdr_zero, rndup)); + return TRUE; + return (xdr_putbytes(xdrs, xdr_zero, rndup)); } if (xdrs->x_op == XDR_FREE) { - return (TRUE); + return TRUE; } - return (FALSE); + return FALSE; } /* @@ -218,11 +218,11 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) * first deal with the length since xdr bytes are counted */ if (!xdr_u_int(xdrs, sizep)) { - return (FALSE); + return FALSE; } nodesize = *sizep; if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) { - return (FALSE); + return FALSE; } /* @@ -240,7 +240,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) } if (sp == NULL) { fprintf(stderr, "xdr_bytes: out of memory\n"); - return (FALSE); + return FALSE; } /* FALLTHROUGH */ @@ -259,10 +259,10 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) free(sp); *cpp = NULL; } - return (TRUE); + return TRUE; } /* NOTREACHED */ - return (FALSE); + return FALSE; } bool_t @@ -271,15 +271,15 @@ xdr_float(XDR *xdrs, float *fp) switch (xdrs->x_op) { case XDR_ENCODE: - return (XDR_PUTINT32(xdrs, (int32_t *)fp)); + return (xdr_putint32(xdrs, (int32_t *)fp)); case XDR_DECODE: - return (XDR_GETINT32(xdrs, (int32_t *)fp)); + return (xdr_getint32(xdrs, (int32_t *)fp)); case XDR_FREE: - return (TRUE); + return TRUE; } - return (FALSE); + return FALSE; } bool_t @@ -295,15 +295,15 @@ xdr_double(XDR *xdrs, double *dp) case XDR_ENCODE: i32p = (int32_t *)(void *)dp; #ifdef H4_WORDS_BIGENDIAN - rv = XDR_PUTINT32(xdrs, i32p); + rv = xdr_putint32(xdrs, i32p); if (!rv) return (rv); - rv = XDR_PUTINT32(xdrs, i32p + 1); + rv = xdr_putint32(xdrs, i32p + 1); #else - rv = XDR_PUTINT32(xdrs, i32p + 1); + rv = xdr_putint32(xdrs, i32p + 1); if (!rv) return (rv); - rv = XDR_PUTINT32(xdrs, i32p); + rv = xdr_putint32(xdrs, i32p); #endif return rv; break; @@ -311,15 +311,15 @@ xdr_double(XDR *xdrs, double *dp) case XDR_DECODE: i32p = (int32_t *)(void *)dp; #ifdef H4_WORDS_BIGENDIAN - rv = XDR_GETINT32(xdrs, i32p); + rv = xdr_getint32(xdrs, i32p); if (!rv) return (rv); - rv = XDR_GETINT32(xdrs, i32p + 1); + rv = xdr_getint32(xdrs, i32p + 1); #else - rv = XDR_GETINT32(xdrs, i32p + 1); + rv = xdr_getint32(xdrs, i32p + 1); if (!rv) return (rv); - rv = XDR_GETINT32(xdrs, i32p); + rv = xdr_getint32(xdrs, i32p); #endif return (rv); break; @@ -350,11 +350,11 @@ xdr_vector(XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_el elptr = basep; for (i = 0; i < nelem; i++) { if (!(*xdr_elem)(xdrs, elptr)) { - return (FALSE); + return FALSE; } elptr += elemsize; } - return (TRUE); + return TRUE; } /* @@ -382,21 +382,21 @@ xdr_int64_t(XDR *xdrs, int64_t *llp) case XDR_ENCODE: ul[0] = (u_long)((uint64_t)*llp >> 32) & 0xffffffff; ul[1] = (u_long)((uint64_t)*llp) & 0xffffffff; - if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE) + if (xdr_putlong(xdrs, (long *)&ul[0]) == FALSE) return (FALSE); - return (XDR_PUTLONG(xdrs, (long *)&ul[1])); + return (xdr_putlong(xdrs, (long *)&ul[1])); case XDR_DECODE: - if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE) + if (xdr_getlong(xdrs, (long *)&ul[0]) == FALSE) return (FALSE); - if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE) + if (xdr_getlong(xdrs, (long *)&ul[1]) == FALSE) return (FALSE); *llp = (int64_t)(((uint64_t)ul[0] << 32) | ((uint64_t)(ul[1]) & 0xffffffff)); - return (TRUE); + return TRUE; case XDR_FREE: - return (TRUE); + return TRUE; } /* NOTREACHED */ - return (FALSE); + return FALSE; } /* @@ -411,19 +411,19 @@ xdr_uint64_t(XDR *xdrs, uint64_t *ullp) case XDR_ENCODE: ul[0] = (u_long)(*ullp >> 32) & 0xffffffff; ul[1] = (u_long)(*ullp) & 0xffffffff; - if (XDR_PUTLONG(xdrs, (long *)&ul[0]) == FALSE) + if (xdr_putlong(xdrs, (long *)&ul[0]) == FALSE) return (FALSE); - return (XDR_PUTLONG(xdrs, (long *)&ul[1])); + return (xdr_putlong(xdrs, (long *)&ul[1])); case XDR_DECODE: - if (XDR_GETLONG(xdrs, (long *)&ul[0]) == FALSE) - return (FALSE); - if (XDR_GETLONG(xdrs, (long *)&ul[1]) == FALSE) - return (FALSE); + if (xdr_getlong(xdrs, (long *)&ul[0]) == FALSE) + return FALSE; + if (xdr_getlong(xdrs, (long *)&ul[1]) == FALSE) + return FALSE; *ullp = (uint64_t)(((uint64_t)ul[0] << 32) | ((uint64_t)(ul[1]) & 0xffffffff)); - return (TRUE); + return TRUE; case XDR_FREE: - return (TRUE); + return TRUE; } /* NOTREACHED */ - return (FALSE); + return FALSE; } diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 71963516cb..79bda5cfce 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -93,7 +93,7 @@ typedef int32_t enum_t; */ /* - * Xdr operations. XDR_ENCODE causes the type to be encoded into the + * XDR operations. XDR_ENCODE causes the type to be encoded into the * stream. XDR_DECODE causes the type to be extracted from the stream. * XDR_FREE can be used to release the space allocated by an XDR_DECODE * request. @@ -111,20 +111,20 @@ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; * an operations vector for the particular implementation (e.g. see xdr_mem.c), * and two private fields for the use of the particular implementation. */ -typedef struct __rpc_xdr { +typedef struct xinfo { enum xdr_op x_op; /* operation; fast additional param */ struct xdr_ops { /* Get/put long from underlying stream */ - bool_t (*x_getlong)(struct __rpc_xdr *, long *); - bool_t (*x_putlong)(struct __rpc_xdr *, const long *); + bool_t (*x_getlong)(struct xinfo *, long *); + bool_t (*x_putlong)(struct xinfo *, const long *); /* Get/put bytes. */ - bool_t (*x_getbytes)(struct __rpc_xdr *, char *, u_int); - bool_t (*x_putbytes)(struct __rpc_xdr *, const char *, u_int); + bool_t (*x_getbytes)(struct xinfo *, char *, u_int); + bool_t (*x_putbytes)(struct xinfo *, const char *, u_int); /* Get or seek within the stream (offsets from beginning of stream). */ - u_int (*x_getpostn)(struct __rpc_xdr *); - bool_t (*x_setpostn)(struct __rpc_xdr *, u_int); + u_int (*x_getpostn)(struct xinfo *); + bool_t (*x_setpostn)(struct xinfo *, u_int); /* Free the stream. */ - void (*x_destroy)(struct __rpc_xdr *); + void (*x_destroy)(struct xinfo *); } * x_ops; void *x_private; /* pointer to private data */ } XDR; @@ -158,24 +158,21 @@ typedef bool_t (*xdrproc_t)(XDR *, void *, ...); * u_int len; * u_int pos; */ -#define XDR_GETLONG(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp) #define xdr_getlong(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp) - -#define XDR_PUTLONG(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp) #define xdr_putlong(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp) -static __inline int +static inline int xdr_getint32(XDR *xdrs, int32_t *ip) { long l; if (!xdr_getlong(xdrs, &l)) - return (FALSE); + return FALSE; *ip = (int32_t)l; - return (TRUE); + return TRUE; } -static __inline int +static inline int xdr_putint32(XDR *xdrs, int32_t *ip) { long l; @@ -184,13 +181,7 @@ xdr_putint32(XDR *xdrs, int32_t *ip) return xdr_putlong(xdrs, &l); } -#define XDR_GETINT32(xdrs, int32p) xdr_getint32(xdrs, int32p) -#define XDR_PUTINT32(xdrs, int32p) xdr_putint32(xdrs, int32p) - -#define XDR_GETBYTES(xdrs, addr, len) (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) #define xdr_getbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) - -#define XDR_PUTBYTES(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) #define xdr_putbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) #define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) @@ -198,7 +189,7 @@ xdr_putint32(XDR *xdrs, int32_t *ip) #define xdr_destroy(xdrs) \ if ((xdrs)->x_ops->x_destroy) \ - (*(xdrs)->x_ops->x_destroy)(xdrs) + (*(xdrs)->x_ops->x_destroy)(xdrs) /* * These are the "generic" xdr routines. @@ -214,20 +205,18 @@ XDRLIBAPI bool_t xdr_int64_t(XDR *, int64_t *); XDRLIBAPI bool_t xdr_uint64_t(XDR *, uint64_t *); XDRLIBAPI bool_t xdr_bytes(XDR *, char **, u_int *, u_int); XDRLIBAPI bool_t xdr_opaque(XDR *, char *, u_int); -XDRLIBAPI bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t); XDRLIBAPI bool_t xdr_float(XDR *, float *); XDRLIBAPI bool_t xdr_double(XDR *, double *); XDRLIBAPI void xdr_free(xdrproc_t, void *); -/* - * These are the public routines for the various implementations of - * xdr streams. - */ +/* Only used in xdrtest.c */ +XDRLIBAPI bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t); + #ifdef __cplusplus extern "C" { #endif -/* XDR using stdio library */ +/* XDR using stdio library (only used in xdrtest.c) */ XDRLIBAPI void xdrstdio_create(XDR *, FILE *, enum xdr_op); #ifdef __cplusplus From 186ff32e62d2cb5fdb6eda5369a789e9e3d19105 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 12:43:00 -0800 Subject: [PATCH 14/52] Moved xdr_vector into xdrtest.c Also minor cleanup --- mfhdf/libsrc/xdr.c | 85 +++++++++++--------------------------------- mfhdf/libsrc/xdr.h | 3 -- mfhdf/test/xdrtest.c | 26 ++++++++++++++ 3 files changed, 47 insertions(+), 67 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 814fe0cee6..ad10903bd0 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -73,12 +73,11 @@ xdr_int(XDR *xdrs, int *ip) case XDR_ENCODE: l = (long)*ip; - return (xdr_putlong(xdrs, &l)); + return xdr_putlong(xdrs, &l); case XDR_DECODE: - if (!xdr_getlong(xdrs, &l)) { + if (!xdr_getlong(xdrs, &l)) return FALSE; - } *ip = (int)l; return TRUE; @@ -101,12 +100,11 @@ xdr_u_int(XDR *xdrs, u_int *up) case XDR_ENCODE: l = (u_long)*up; - return (xdr_putlong(xdrs, (long *)&l)); + return xdr_putlong(xdrs, (long *)&l); case XDR_DECODE: - if (!xdr_getlong(xdrs, (long *)&l)) { + if (!xdr_getlong(xdrs, (long *)&l)) return FALSE; - } *up = (u_int)l; return TRUE; @@ -125,9 +123,9 @@ xdr_long(XDR *xdrs, long *lp) { switch (xdrs->x_op) { case XDR_ENCODE: - return (xdr_putlong(xdrs, lp)); + return xdr_putlong(xdrs, lp); case XDR_DECODE: - return (xdr_getlong(xdrs, lp)); + return xdr_getlong(xdrs, lp); case XDR_FREE: return TRUE; } @@ -143,9 +141,9 @@ xdr_u_long(XDR *xdrs, u_long *ulp) { switch (xdrs->x_op) { case XDR_ENCODE: - return (xdr_putlong(xdrs, (long *)ulp)); + return xdr_putlong(xdrs, (long *)ulp); case XDR_DECODE: - return (xdr_getlong(xdrs, (long *)ulp)); + return xdr_getlong(xdrs, (long *)ulp); case XDR_FREE: return TRUE; } @@ -178,21 +176,19 @@ xdr_opaque(XDR *xdrs, char *cp, u_int cnt) rndup = BYTES_PER_XDR_UNIT - rndup; if (xdrs->x_op == XDR_DECODE) { - if (!xdr_getbytes(xdrs, cp, cnt)) { + if (!xdr_getbytes(xdrs, cp, cnt)) return FALSE; - } if (rndup == 0) return TRUE; - return (xdr_getbytes(xdrs, (char *)crud, rndup)); + return xdr_getbytes(xdrs, (char *)crud, rndup); } if (xdrs->x_op == XDR_ENCODE) { - if (!xdr_putbytes(xdrs, cp, cnt)) { + if (!xdr_putbytes(xdrs, cp, cnt)) return FALSE; - } if (rndup == 0) return TRUE; - return (xdr_putbytes(xdrs, xdr_zero, rndup)); + return xdr_putbytes(xdrs, xdr_zero, rndup); } if (xdrs->x_op == XDR_FREE) { @@ -252,7 +248,7 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) *cpp = NULL; } } - return (ret); + return ret; case XDR_FREE: if (sp != NULL) { @@ -297,12 +293,12 @@ xdr_double(XDR *xdrs, double *dp) #ifdef H4_WORDS_BIGENDIAN rv = xdr_putint32(xdrs, i32p); if (!rv) - return (rv); + return rv; rv = xdr_putint32(xdrs, i32p + 1); #else rv = xdr_putint32(xdrs, i32p + 1); if (!rv) - return (rv); + return rv; rv = xdr_putint32(xdrs, i32p); #endif return rv; @@ -313,15 +309,15 @@ xdr_double(XDR *xdrs, double *dp) #ifdef H4_WORDS_BIGENDIAN rv = xdr_getint32(xdrs, i32p); if (!rv) - return (rv); + return rv; rv = xdr_getint32(xdrs, i32p + 1); #else rv = xdr_getint32(xdrs, i32p + 1); if (!rv) - return (rv); + return rv; rv = xdr_getint32(xdrs, i32p); #endif - return (rv); + return rv; break; case XDR_FREE: @@ -331,45 +327,6 @@ xdr_double(XDR *xdrs, double *dp) return FALSE; } -/* - * xdr_vector(): - * - * XDR a fixed length array. Unlike variable-length arrays, - * the storage of fixed length arrays is static and unfreeable. - * > basep: base of the array - * > size: size of the array - * > elemsize: size of each element - * > xdr_elem: routine to XDR each element - */ -bool_t -xdr_vector(XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_elem) -{ - u_int i; - char *elptr; - - elptr = basep; - for (i = 0; i < nelem; i++) { - if (!(*xdr_elem)(xdrs, elptr)) { - return FALSE; - } - elptr += elemsize; - } - return TRUE; -} - -/* - * Non-portable xdr primitives. - * Care should be taken when moving these routines to new architectures. - */ - -/* - * NOTE: xdr_longlong_t() and xdr_u_longlong_t() - * are in the "non-portable" section because they require that a `long long' - * be a 64-bit type. - * - * --thorpej@netbsd.org, November 30, 1999 - */ - /* * XDR 64-bit integers */ @@ -383,13 +340,13 @@ xdr_int64_t(XDR *xdrs, int64_t *llp) ul[0] = (u_long)((uint64_t)*llp >> 32) & 0xffffffff; ul[1] = (u_long)((uint64_t)*llp) & 0xffffffff; if (xdr_putlong(xdrs, (long *)&ul[0]) == FALSE) - return (FALSE); + return FALSE; return (xdr_putlong(xdrs, (long *)&ul[1])); case XDR_DECODE: if (xdr_getlong(xdrs, (long *)&ul[0]) == FALSE) - return (FALSE); + return FALSE; if (xdr_getlong(xdrs, (long *)&ul[1]) == FALSE) - return (FALSE); + return FALSE; *llp = (int64_t)(((uint64_t)ul[0] << 32) | ((uint64_t)(ul[1]) & 0xffffffff)); return TRUE; case XDR_FREE: diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 79bda5cfce..df55966ea4 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -209,9 +209,6 @@ XDRLIBAPI bool_t xdr_float(XDR *, float *); XDRLIBAPI bool_t xdr_double(XDR *, double *); XDRLIBAPI void xdr_free(xdrproc_t, void *); -/* Only used in xdrtest.c */ -XDRLIBAPI bool_t xdr_vector(XDR *, char *, u_int, u_int, xdrproc_t); - #ifdef __cplusplus extern "C" { #endif diff --git a/mfhdf/test/xdrtest.c b/mfhdf/test/xdrtest.c index 7f55ea29ae..33fd90fae6 100644 --- a/mfhdf/test/xdrtest.c +++ b/mfhdf/test/xdrtest.c @@ -33,6 +33,32 @@ #define EPSILON .0005 #endif +/* + * xdr_vector(): + * + * XDR a fixed length array. Unlike variable-length arrays, + * the storage of fixed length arrays is static and unfreeable. + * > basep: base of the array + * > size: size of the array + * > elemsize: size of each element + * > xdr_elem: routine to XDR each element + */ +bool_t +xdr_vector(XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_elem) +{ + u_int i; + char *elptr; + + elptr = basep; + for (i = 0; i < nelem; i++) { + if (!(*xdr_elem)(xdrs, elptr)) { + return FALSE; + } + elptr += elemsize; + } + return TRUE; +} + int main(int ac, char *av[]) { From 07dba711f47428d0d5763e8c5fed72d459b8df58 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 12:46:58 -0800 Subject: [PATCH 15/52] Remove xdrposix_inline --- mfhdf/libsrc/xdrposix.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/mfhdf/libsrc/xdrposix.c b/mfhdf/libsrc/xdrposix.c index eb2b898086..91abe8deec 100644 --- a/mfhdf/libsrc/xdrposix.c +++ b/mfhdf/libsrc/xdrposix.c @@ -212,7 +212,6 @@ static bool_t xdrposix_getbytes(XDR *xdrs, char *addr, u_int len); static bool_t xdrposix_putbytes(XDR *xdrs, const char *addr, u_int len); static u_int xdrposix_getpos(XDR *xdrs); static bool_t xdrposix_setpos(XDR *xdrs, u_int pos); -static int32_t *xdrposix_inline(XDR *xdrs, u_int len); static void xdrposix_destroy(XDR *xdrs); #if (defined __sun && defined _LP64) static bool_t xdrposix_getint(XDR *xdrs, int *lp); @@ -411,20 +410,6 @@ xdrposix_setpos(XDR *xdrs, u_int pos) return FALSE; } -static int32_t * -xdrposix_inline(XDR *xdrs, u_int len) -{ - (void)xdrs; - (void)len; - /* - * Must do some work to implement this: must insure - * enough data in the underlying posix buffer, - * that the buffer is aligned so that we can indirect through a - * int32_t *, and stuff this pointer in xdrs->x_buf. - */ - return NULL; -} - #if (defined __sun && defined _LP64) static bool_t From e9fd083bb956b66ad32faf407a9b567337108ad5 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 13:26:59 -0800 Subject: [PATCH 16/52] Change XDRLIBAPI --> HDFLIBAPI --- hdf/src/H4api_adpt.h | 16 ---------------- mfhdf/libsrc/xdr.h | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/hdf/src/H4api_adpt.h b/hdf/src/H4api_adpt.h index c3ebfff79d..cd5531728a 100644 --- a/hdf/src/H4api_adpt.h +++ b/hdf/src/H4api_adpt.h @@ -25,14 +25,6 @@ /* This will only be defined if HDF4 was built with CMake */ #if defined(H4_BUILT_AS_DYNAMIC_LIB) -#if defined(xdr_shared_EXPORTS) -#if defined(_MSC_VER) || defined(__MINGW32__) /* MSVC Compiler Case */ -#define XDRLIBAPI extern __declspec(dllexport) -#elif (__GNUC__ >= 4) /* GCC 4.x has support for visibility options */ -#define XDRLIBAPI extern __attribute__((visibility("default"))) -#endif -#endif /* xdr_shared_EXPORTS */ - #if defined(hdf_shared_EXPORTS) #if defined(_MSC_VER) || defined(__MINGW32__) /* MSVC Compiler Case */ #define HDFERRPUBLIC extern __declspec(dllimport) @@ -113,13 +105,6 @@ #endif #endif /* mfhdf_hrepack_shared_EXPORTS */ -#if !defined(XDRLIBAPI) -#if defined(_MSC_VER) || defined(__MINGW32__) /* MSVC Compiler Case */ -#define XDRLIBAPI extern __declspec(dllimport) -#elif (__GNUC__ >= 4) /* GCC 4.x has support for visibility options */ -#define XDRLIBAPI extern __attribute__((visibility("default"))) -#endif -#endif #if !defined(HDFERRPUBLIC) #if defined(_MSC_VER) || defined(__MINGW32__) /* MSVC Compiler Case */ #define HDFERRPUBLIC extern __declspec(dllimport) @@ -150,7 +135,6 @@ #endif #else -#define XDRLIBAPI extern #define HDFERRPUBLIC extern #define HDFPUBLIC #define HDFLIBAPI extern diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index df55966ea4..f354d9e3db 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -197,24 +197,24 @@ xdr_putint32(XDR *xdrs, int32_t *ip) #ifdef __cplusplus extern "C" { #endif -XDRLIBAPI bool_t xdr_int(XDR *, int *); -XDRLIBAPI bool_t xdr_u_int(XDR *, u_int *); -XDRLIBAPI bool_t xdr_long(XDR *, long *); -XDRLIBAPI bool_t xdr_u_long(XDR *, u_long *); -XDRLIBAPI bool_t xdr_int64_t(XDR *, int64_t *); -XDRLIBAPI bool_t xdr_uint64_t(XDR *, uint64_t *); -XDRLIBAPI bool_t xdr_bytes(XDR *, char **, u_int *, u_int); -XDRLIBAPI bool_t xdr_opaque(XDR *, char *, u_int); -XDRLIBAPI bool_t xdr_float(XDR *, float *); -XDRLIBAPI bool_t xdr_double(XDR *, double *); -XDRLIBAPI void xdr_free(xdrproc_t, void *); +HDFLIBAPI bool_t xdr_int(XDR *, int *); +HDFLIBAPI bool_t xdr_u_int(XDR *, u_int *); +HDFLIBAPI bool_t xdr_long(XDR *, long *); +HDFLIBAPI bool_t xdr_u_long(XDR *, u_long *); +HDFLIBAPI bool_t xdr_int64_t(XDR *, int64_t *); +HDFLIBAPI bool_t xdr_uint64_t(XDR *, uint64_t *); +HDFLIBAPI bool_t xdr_bytes(XDR *, char **, u_int *, u_int); +HDFLIBAPI bool_t xdr_opaque(XDR *, char *, u_int); +HDFLIBAPI bool_t xdr_float(XDR *, float *); +HDFLIBAPI bool_t xdr_double(XDR *, double *); +HDFLIBAPI void xdr_free(xdrproc_t, void *); #ifdef __cplusplus extern "C" { #endif /* XDR using stdio library (only used in xdrtest.c) */ -XDRLIBAPI void xdrstdio_create(XDR *, FILE *, enum xdr_op); +HDFLIBAPI void xdrstdio_create(XDR *, FILE *, enum xdr_op); #ifdef __cplusplus } From b652425f9586b3f9c00e9d10d0681e5756b4065b Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 15:12:20 -0800 Subject: [PATCH 17/52] Remove free, 64-bit int XDR functions --- mfhdf/libsrc/xdr.c | 20 ++++++-------------- mfhdf/libsrc/xdr.h | 20 +++++++------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index ad10903bd0..9ceb3a8437 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -39,6 +39,7 @@ #include "h4config.h" #include +#include #include #include "xdr.h" @@ -48,19 +49,6 @@ */ static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0}; -/* - * Free a data structure using XDR - * Not a filter, but a convenient utility nonetheless - */ -void -xdr_free(xdrproc_t proc, void *objp) -{ - XDR x; - - x.x_op = XDR_FREE; - (*proc)(&x, objp); -} - /* * XDR integers */ @@ -322,11 +310,14 @@ xdr_double(XDR *xdrs, double *dp) case XDR_FREE: return TRUE; - } /* switch xdrs->x_op */ + } return FALSE; } +/* XXX: Keep this code around in case it's needed when handling longs */ + +#if 0 /* * XDR 64-bit integers */ @@ -384,3 +375,4 @@ xdr_uint64_t(XDR *xdrs, uint64_t *ullp) /* NOTREACHED */ return FALSE; } +#endif diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index f354d9e3db..4d48a17959 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -60,9 +60,6 @@ typedef unsigned long u_long; #endif typedef int32_t bool_t; -/* Define the enumerated type in the wire protocol. */ -typedef int32_t enum_t; - /* * XDR provides a conventional way for converting between C data * types and an external bit-string representation. Library supplied @@ -191,27 +188,24 @@ xdr_putint32(XDR *xdrs, int32_t *ip) if ((xdrs)->x_ops->x_destroy) \ (*(xdrs)->x_ops->x_destroy)(xdrs) -/* - * These are the "generic" xdr routines. - */ #ifdef __cplusplus extern "C" { #endif + +/* + * These are the "generic" xdr routines. + */ HDFLIBAPI bool_t xdr_int(XDR *, int *); HDFLIBAPI bool_t xdr_u_int(XDR *, u_int *); + HDFLIBAPI bool_t xdr_long(XDR *, long *); HDFLIBAPI bool_t xdr_u_long(XDR *, u_long *); -HDFLIBAPI bool_t xdr_int64_t(XDR *, int64_t *); -HDFLIBAPI bool_t xdr_uint64_t(XDR *, uint64_t *); + HDFLIBAPI bool_t xdr_bytes(XDR *, char **, u_int *, u_int); HDFLIBAPI bool_t xdr_opaque(XDR *, char *, u_int); + HDFLIBAPI bool_t xdr_float(XDR *, float *); HDFLIBAPI bool_t xdr_double(XDR *, double *); -HDFLIBAPI void xdr_free(xdrproc_t, void *); - -#ifdef __cplusplus -extern "C" { -#endif /* XDR using stdio library (only used in xdrtest.c) */ HDFLIBAPI void xdrstdio_create(XDR *, FILE *, enum xdr_op); From 9cb6f01897b96a0ea5d0dd5c9991f99f049a6fb0 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 15:38:38 -0800 Subject: [PATCH 18/52] Replace u_int and u_long with ANSI types Also, ran the formatter --- mfhdf/libsrc/cdf.c | 6 ++--- mfhdf/libsrc/file.c | 8 +++--- mfhdf/libsrc/iarray.c | 6 ++--- mfhdf/libsrc/local_nc.h | 2 +- mfhdf/libsrc/putget.c | 59 +++++++++++++++++++++-------------------- mfhdf/libsrc/sharray.c | 4 +-- mfhdf/libsrc/string.c | 4 +-- mfhdf/libsrc/xdr.c | 41 +++++++++++++--------------- mfhdf/libsrc/xdr.h | 33 +++++++++-------------- mfhdf/libsrc/xdrposix.c | 18 ++++++------- mfhdf/libsrc/xdrstdio.c | 30 ++++++++++----------- mfhdf/test/xdrtest.c | 14 +++++----- 12 files changed, 108 insertions(+), 117 deletions(-) diff --git a/mfhdf/libsrc/cdf.c b/mfhdf/libsrc/cdf.c index bf3ce3559f..6579b59c4a 100644 --- a/mfhdf/libsrc/cdf.c +++ b/mfhdf/libsrc/cdf.c @@ -548,7 +548,7 @@ xdr_cdf(XDR *xdrs, NC **handlep) static bool_t NC_xdr_cdf(XDR *xdrs, NC **handlep) { - u_long magic; + unsigned long magic; if (xdrs->x_op == XDR_FREE) { NC_free_xcdf(*handlep); @@ -2863,8 +2863,8 @@ xdr_NC_fill(XDR *xdrs, NC_var *vp) char fillp[2 * sizeof(double)]; bool_t stat; bool_t (*xdr_NC_fnct)(); - u_long alen = vp->len; - NC_attr **attr = NULL; + unsigned long alen = vp->len; + NC_attr **attr = NULL; /* * set up fill value diff --git a/mfhdf/libsrc/file.c b/mfhdf/libsrc/file.c index d2c93f46e0..49bdebb4d5 100644 --- a/mfhdf/libsrc/file.c +++ b/mfhdf/libsrc/file.c @@ -646,10 +646,10 @@ ncredef(int cdfid) static void NC_begins(NC *handle) { - unsigned ii; - u_long index = 0; - NC_var **vpp; - NC_var *last = NULL; + unsigned ii; + unsigned long index = 0; + NC_var **vpp; + NC_var *last = NULL; if (handle->vars == NULL) return; diff --git a/mfhdf/libsrc/iarray.c b/mfhdf/libsrc/iarray.c index 44315e7509..8720d321a1 100644 --- a/mfhdf/libsrc/iarray.c +++ b/mfhdf/libsrc/iarray.c @@ -67,9 +67,9 @@ NC_free_iarray(NC_iarray *iarray) bool_t xdr_NC_iarray(XDR *xdrs, NC_iarray **ipp) { - int *ip; - u_long count = 0; - bool_t stat = TRUE; + int *ip; + unsigned long count = 0; + bool_t stat = TRUE; switch (xdrs->x_op) { case XDR_FREE: diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index 42b7bd915f..3acc8b176b 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -443,7 +443,7 @@ HDFLIBAPI bool_t NCcktype(nc_type datatype); HDFLIBAPI bool_t NC_indefine(int cdfid, bool_t iserr); HDFLIBAPI bool_t xdr_cdf(XDR *xdrs, NC **handlep); HDFLIBAPI bool_t xdr_numrecs(XDR *xdrs, NC *handle); -HDFLIBAPI bool_t xdr_shorts(XDR *xdrs, short *sp, u_int cnt); +HDFLIBAPI bool_t xdr_shorts(XDR *xdrs, short *sp, unsigned cnt); HDFLIBAPI bool_t xdr_NC_array(XDR *xdrs, NC_array **app); HDFLIBAPI bool_t xdr_NC_attr(XDR *xdrs, NC_attr **app); HDFLIBAPI bool_t xdr_NC_dim(XDR *xdrs, NC_dim **dpp); diff --git a/mfhdf/libsrc/putget.c b/mfhdf/libsrc/putget.c index 36a2282325..1522de5c3b 100644 --- a/mfhdf/libsrc/putget.c +++ b/mfhdf/libsrc/putget.c @@ -20,12 +20,13 @@ #include "hfile.h" /* Ugh! We need the defs for HI_READ and HI_SEEK */ /* Local function prototypes */ -static bool_t nssdc_xdr_NCvdata(NC *handle, NC_var *vp, u_long where, nc_type type, uint32 count, +static bool_t nssdc_xdr_NCvdata(NC *handle, NC_var *vp, unsigned long where, nc_type type, uint32 count, void *values); -static intn hdf_xdr_NCvdata(NC *handle, NC_var *vp, u_long where, nc_type type, uint32 count, void *values); +static intn hdf_xdr_NCvdata(NC *handle, NC_var *vp, unsigned long where, nc_type type, uint32 count, + void *values); -static intn hdf_xdr_NCv1data(NC *handle, NC_var *vp, u_long where, nc_type type, void *values); +static intn hdf_xdr_NCv1data(NC *handle, NC_var *vp, unsigned long where, nc_type type, void *values); static intn SDIresizebuf(void **buf, int32 *buf_size, int32 size_wanted); @@ -324,10 +325,10 @@ NCcoordck(NC *handle, NC_var *vp, const long *coords) /* * Translate the (variable, coords) pair into a seek index */ -static u_long +static unsigned long NC_varoffset(NC *handle, NC_var *vp, const long *coords) { - u_long offset; + unsigned long offset; const long *ip; unsigned long *up; const long *boundary; @@ -415,9 +416,9 @@ NC_varoffset(NC *handle, NC_var *vp, const long *coords) static bool_t xdr_NCvbyte(XDR *xdrs, unsigned rem, unsigned count, char *values) { - char buf[4]; - u_long origin = 0; - enum xdr_op x_op = xdrs->x_op; /* save state */ + char buf[4]; + unsigned long origin = 0; + enum xdr_op x_op = xdrs->x_op; /* save state */ if (x_op == XDR_ENCODE) { /* @@ -466,7 +467,7 @@ bool_t xdr_NCvshort(XDR *xdrs, unsigned which, short *values) { unsigned char buf[4]; /* unsigned is important here */ - u_long origin = 0; + unsigned long origin = 0; enum xdr_op x_op = xdrs->x_op; /* save state */ if (x_op == XDR_ENCODE) { @@ -510,9 +511,9 @@ xdr_NCvshort(XDR *xdrs, unsigned which, short *values) * xdr a single datum of type 'type' at 'where' */ static bool_t -xdr_NCv1data(XDR *xdrs, u_long where, nc_type type, Void *values) +xdr_NCv1data(XDR *xdrs, unsigned long where, nc_type type, Void *values) { - u_long rem = 0; + unsigned long rem = 0; switch (type) { case NC_BYTE: @@ -874,7 +875,7 @@ hdf_get_vp_aid(NC *handle, NC_var *vp) * The calling routine is responsible for calling DFKsetNT() as required. */ static intn -hdf_xdr_NCvdata(NC *handle, NC_var *vp, u_long where, nc_type type, uint32 count, void *values) +hdf_xdr_NCvdata(NC *handle, NC_var *vp, unsigned long where, nc_type type, uint32 count, void *values) { NC_attr **attr = NULL; /* pointer to the fill-value attribute */ int32 status; @@ -1432,7 +1433,7 @@ hdf_xdr_NCvdata(NC *handle, NC_var *vp, u_long where, nc_type type, uint32 count * Return TRUE if everything worked, else FALSE */ static intn -hdf_xdr_NCv1data(NC *handle, NC_var *vp, u_long where, nc_type type, void *values) +hdf_xdr_NCv1data(NC *handle, NC_var *vp, unsigned long where, nc_type type, void *values) { intn ret_value = SUCCEED; @@ -1459,7 +1460,7 @@ hdf_xdr_NCv1data(NC *handle, NC_var *vp, u_long where, nc_type type, void *value * it 100 percent -GV */ static bool_t -nssdc_xdr_NCvdata(NC *handle, NC_var *vp, u_long where, nc_type type, uint32 count, void *values) +nssdc_xdr_NCvdata(NC *handle, NC_var *vp, unsigned long where, nc_type type, uint32 count, void *values) { int32 status; int32 byte_count; @@ -1501,8 +1502,8 @@ nssdc_xdr_NCvdata(NC *handle, NC_var *vp, u_long where, nc_type type, uint32 cou static int NCvar1io(NC *handle, int varid, const long *coords, Void *value) { - NC_var *vp; - u_long offset; + NC_var *vp; + unsigned long offset; if (handle->flags & NC_INDEF) return (-1); @@ -1601,9 +1602,9 @@ ncvarget1(int cdfid, int varid, const long *coords, ncvoid *value) * xdr 'count' items of contiguous data of type 'type' at 'where' */ static bool_t -xdr_NCvdata(XDR *xdrs, u_long where, nc_type type, unsigned count, Void *values) +xdr_NCvdata(XDR *xdrs, unsigned long where, nc_type type, unsigned count, Void *values) { - u_long rem = 0; + unsigned long rem = 0; bool_t (*xdr_NC_fnct)(); bool_t stat; size_t szof; @@ -1879,11 +1880,11 @@ NCvario(NC *handle, int varid, const long *start, const long *edges, void *value /* now edp = edp0 - 1 */ { /* inline */ - long coords[H4_MAX_VAR_DIMS], upper[H4_MAX_VAR_DIMS]; - long *cc; - const long *mm; - u_long offset; - size_t szof = nctypelen(vp->type); + long coords[H4_MAX_VAR_DIMS], upper[H4_MAX_VAR_DIMS]; + long *cc; + const long *mm; + unsigned long offset; + size_t szof = nctypelen(vp->type); /* copy in starting indices */ cc = coords; @@ -2208,12 +2209,12 @@ ncrecinq(int cdfid, int *nrecvars, int *recvarids, long *recsizes) static int NCrecio(NC *handle, long recnum, Void **datap) { - int nrvars; - NC_var *rvp[H4_MAX_NC_VARS]; - int ii; - long coords[H4_MAX_VAR_DIMS]; - u_long offset; - unsigned iocount; + int nrvars; + NC_var *rvp[H4_MAX_NC_VARS]; + int ii; + long coords[H4_MAX_VAR_DIMS]; + unsigned long offset; + unsigned iocount; nrvars = NCnumrecvars(handle, rvp, (int *)NULL); if (nrvars == -1) diff --git a/mfhdf/libsrc/sharray.c b/mfhdf/libsrc/sharray.c index b200ed05f5..f447ce8bd5 100644 --- a/mfhdf/libsrc/sharray.c +++ b/mfhdf/libsrc/sharray.c @@ -24,7 +24,7 @@ * internal function, bulk xdr of an even number of shorts, less than NC_NSHRTS_PER */ static bool_t -NCxdr_shortsb(XDR *xdrs, short *sp, u_int nshorts) +NCxdr_shortsb(XDR *xdrs, short *sp, unsigned nshorts) { unsigned char buf[NC_SHRT_BUFSIZ]; unsigned char *cp; @@ -60,7 +60,7 @@ NCxdr_shortsb(XDR *xdrs, short *sp, u_int nshorts) * Translate an array of cnt short integers at sp. */ bool_t -xdr_shorts(XDR *xdrs, short *sp, u_int cnt) +xdr_shorts(XDR *xdrs, short *sp, unsigned cnt) { int odd; /* 1 if cnt is odd, 0 otherwise */ diff --git a/mfhdf/libsrc/string.c b/mfhdf/libsrc/string.c index 71c3ed4976..d74e65879d 100644 --- a/mfhdf/libsrc/string.c +++ b/mfhdf/libsrc/string.c @@ -131,8 +131,8 @@ NC_re_string(NC_string *old, unsigned count, const char *str) bool_t xdr_NC_string(XDR *xdrs, NC_string **spp) { - u_long count = 0; - int status; + unsigned long count = 0; + int status; switch (xdrs->x_op) { case XDR_FREE: diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 9ceb3a8437..c6bda9f736 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -80,20 +80,20 @@ xdr_int(XDR *xdrs, int *ip) * XDR unsigned integers */ bool_t -xdr_u_int(XDR *xdrs, u_int *up) +xdr_u_int(XDR *xdrs, unsigned *up) { - u_long l; + unsigned long l; switch (xdrs->x_op) { case XDR_ENCODE: - l = (u_long)*up; + l = (unsigned long)*up; return xdr_putlong(xdrs, (long *)&l); case XDR_DECODE: if (!xdr_getlong(xdrs, (long *)&l)) return FALSE; - *up = (u_int)l; + *up = (unsigned)l; return TRUE; case XDR_FREE: @@ -125,7 +125,7 @@ xdr_long(XDR *xdrs, long *lp) * XDR unsigned long integers */ bool_t -xdr_u_long(XDR *xdrs, u_long *ulp) +xdr_u_long(XDR *xdrs, unsigned long *ulp) { switch (xdrs->x_op) { case XDR_ENCODE: @@ -145,9 +145,9 @@ xdr_u_long(XDR *xdrs, u_long *ulp) * cp points to the opaque object and cnt gives the byte length. */ bool_t -xdr_opaque(XDR *xdrs, char *cp, u_int cnt) +xdr_opaque(XDR *xdrs, char *cp, unsigned cnt) { - u_int rndup; + unsigned rndup; static int crud[BYTES_PER_XDR_UNIT]; /* @@ -179,9 +179,8 @@ xdr_opaque(XDR *xdrs, char *cp, u_int cnt) return xdr_putbytes(xdrs, xdr_zero, rndup); } - if (xdrs->x_op == XDR_FREE) { + if (xdrs->x_op == XDR_FREE) return TRUE; - } return FALSE; } @@ -192,22 +191,21 @@ xdr_opaque(XDR *xdrs, char *cp, u_int cnt) * If *cpp is NULL maxsize bytes are allocated */ bool_t -xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) +xdr_bytes(XDR *xdrs, char **cpp, unsigned *sizep, unsigned maxsize) { - char *sp = *cpp; /* sp is the actual string pointer */ - u_int nodesize; - bool_t ret, allocated = FALSE; + char *sp = *cpp; /* sp is the actual string pointer */ + unsigned nodesize; + bool_t ret; + bool_t allocated = FALSE; /* * first deal with the length since xdr bytes are counted */ - if (!xdr_u_int(xdrs, sizep)) { + if (!xdr_u_int(xdrs, sizep)) return FALSE; - } nodesize = *sizep; - if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) { + if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) return FALSE; - } /* * now deal with the actual bytes @@ -215,9 +213,8 @@ xdr_bytes(XDR *xdrs, char **cpp, u_int *sizep, u_int maxsize) switch (xdrs->x_op) { case XDR_DECODE: - if (nodesize == 0) { - return (TRUE); - } + if (nodesize == 0) + return TRUE; if (sp == NULL) { *cpp = sp = calloc(1, nodesize); allocated = TRUE; @@ -255,10 +252,10 @@ xdr_float(XDR *xdrs, float *fp) switch (xdrs->x_op) { case XDR_ENCODE: - return (xdr_putint32(xdrs, (int32_t *)fp)); + return xdr_putint32(xdrs, (int32_t *)fp); case XDR_DECODE: - return (xdr_getint32(xdrs, (int32_t *)fp)); + return xdr_getint32(xdrs, (int32_t *)fp); case XDR_FREE: return TRUE; diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 4d48a17959..736f64acfe 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -45,13 +45,6 @@ #include #endif -#ifndef u_int -typedef uint32_t u_int; -#endif -#ifndef u_long -typedef unsigned long u_long; -#endif - #ifndef TRUE #define TRUE 1 #endif @@ -115,11 +108,11 @@ typedef struct xinfo { bool_t (*x_getlong)(struct xinfo *, long *); bool_t (*x_putlong)(struct xinfo *, const long *); /* Get/put bytes. */ - bool_t (*x_getbytes)(struct xinfo *, char *, u_int); - bool_t (*x_putbytes)(struct xinfo *, const char *, u_int); + bool_t (*x_getbytes)(struct xinfo *, char *, unsigned); + bool_t (*x_putbytes)(struct xinfo *, const char *, unsigned); /* Get or seek within the stream (offsets from beginning of stream). */ - u_int (*x_getpostn)(struct xinfo *); - bool_t (*x_setpostn)(struct xinfo *, u_int); + unsigned (*x_getpostn)(struct xinfo *); + bool_t (*x_setpostn)(struct xinfo *, unsigned); /* Free the stream. */ void (*x_destroy)(struct xinfo *); } * x_ops; @@ -151,9 +144,9 @@ typedef bool_t (*xdrproc_t)(XDR *, void *, ...); * * XDR *xdrs; * long *longp; - * char * addr; - * u_int len; - * u_int pos; + * char *addr; + * unsigned len; + * unsigned pos; */ #define xdr_getlong(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp) #define xdr_putlong(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp) @@ -181,12 +174,12 @@ xdr_putint32(XDR *xdrs, int32_t *ip) #define xdr_getbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) #define xdr_putbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) -#define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) +#define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) #define xdr_setpos(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) #define xdr_destroy(xdrs) \ if ((xdrs)->x_ops->x_destroy) \ - (*(xdrs)->x_ops->x_destroy)(xdrs) + (*(xdrs)->x_ops->x_destroy)(xdrs) #ifdef __cplusplus extern "C" { @@ -196,13 +189,13 @@ extern "C" { * These are the "generic" xdr routines. */ HDFLIBAPI bool_t xdr_int(XDR *, int *); -HDFLIBAPI bool_t xdr_u_int(XDR *, u_int *); +HDFLIBAPI bool_t xdr_u_int(XDR *, unsigned *); HDFLIBAPI bool_t xdr_long(XDR *, long *); -HDFLIBAPI bool_t xdr_u_long(XDR *, u_long *); +HDFLIBAPI bool_t xdr_u_long(XDR *, unsigned long *); -HDFLIBAPI bool_t xdr_bytes(XDR *, char **, u_int *, u_int); -HDFLIBAPI bool_t xdr_opaque(XDR *, char *, u_int); +HDFLIBAPI bool_t xdr_bytes(XDR *, char **, unsigned *, unsigned); +HDFLIBAPI bool_t xdr_opaque(XDR *, char *, unsigned); HDFLIBAPI bool_t xdr_float(XDR *, float *); HDFLIBAPI bool_t xdr_double(XDR *, double *); diff --git a/mfhdf/libsrc/xdrposix.c b/mfhdf/libsrc/xdrposix.c index 91abe8deec..00a3206b0c 100644 --- a/mfhdf/libsrc/xdrposix.c +++ b/mfhdf/libsrc/xdrposix.c @@ -208,10 +208,10 @@ biowrite(biobuf *biop, unsigned char *ptr, int nbytes) static bool_t xdrposix_getlong(XDR *xdrs, long *lp); static bool_t xdrposix_putlong(XDR *xdrs, const long *lp); -static bool_t xdrposix_getbytes(XDR *xdrs, char *addr, u_int len); -static bool_t xdrposix_putbytes(XDR *xdrs, const char *addr, u_int len); -static u_int xdrposix_getpos(XDR *xdrs); -static bool_t xdrposix_setpos(XDR *xdrs, u_int pos); +static bool_t xdrposix_getbytes(XDR *xdrs, char *addr, unsigned len); +static bool_t xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len); +static unsigned xdrposix_getpos(XDR *xdrs); +static bool_t xdrposix_setpos(XDR *xdrs, unsigned pos); static void xdrposix_destroy(XDR *xdrs); #if (defined __sun && defined _LP64) static bool_t xdrposix_getint(XDR *xdrs, int *lp); @@ -266,7 +266,7 @@ hdf_xdrfile_create(XDR *xdrs, int ncop) static int xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) { - biobuf *biop = new_biobuf(fd, fmode); + biobuf *biop = new_biobuf(fd, fmode); xdrs->x_op = op; xdrs->x_ops = &xdrposix_ops; xdrs->x_private = (char *)biop; @@ -357,7 +357,7 @@ xdrposix_putlong(XDR *xdrs, const long *lp) } static bool_t -xdrposix_getbytes(XDR *xdrs, char *addr, u_int len) +xdrposix_getbytes(XDR *xdrs, char *addr, unsigned len) { if ((len != 0) && (bioread((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) return FALSE; @@ -365,14 +365,14 @@ xdrposix_getbytes(XDR *xdrs, char *addr, u_int len) } static bool_t -xdrposix_putbytes(XDR *xdrs, const char *addr, u_int len) +xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len) { if ((len != 0) && (biowrite((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) return FALSE; return TRUE; } -static u_int +static unsigned xdrposix_getpos(XDR *xdrs) { biobuf *biop = (biobuf *)xdrs->x_private; @@ -380,7 +380,7 @@ xdrposix_getpos(XDR *xdrs) } static bool_t -xdrposix_setpos(XDR *xdrs, u_int pos) +xdrposix_setpos(XDR *xdrs, unsigned pos) { biobuf *biop = (biobuf *)xdrs->x_private; if (biop != NULL) { diff --git a/mfhdf/libsrc/xdrstdio.c b/mfhdf/libsrc/xdrstdio.c index 4785aa9629..bfd71618ab 100644 --- a/mfhdf/libsrc/xdrstdio.c +++ b/mfhdf/libsrc/xdrstdio.c @@ -56,10 +56,10 @@ static void xdrstdio_destroy(XDR *); static bool_t xdrstdio_getlong(XDR *, long *); static bool_t xdrstdio_putlong(XDR *, const long *); -static bool_t xdrstdio_getbytes(XDR *, char *, u_int); -static bool_t xdrstdio_putbytes(XDR *, const char *, u_int); -static u_int xdrstdio_getpos(XDR *); -static bool_t xdrstdio_setpos(XDR *, u_int); +static bool_t xdrstdio_getbytes(XDR *, char *, unsigned); +static bool_t xdrstdio_putbytes(XDR *, const char *, unsigned); +static unsigned xdrstdio_getpos(XDR *); +static bool_t xdrstdio_setpos(XDR *, unsigned); /* * Ops vector for stdio type XDR @@ -107,7 +107,7 @@ xdrstdio_getlong(XDR *xdrs, long *lp) return (FALSE); *lp = (long)ntohl(mycopy); - return (TRUE); + return TRUE; } static bool_t @@ -125,33 +125,33 @@ xdrstdio_putlong(XDR *xdrs, const long *lp) } static bool_t -xdrstdio_getbytes(XDR *xdrs, char *addr, u_int len) +xdrstdio_getbytes(XDR *xdrs, char *addr, unsigned len) { if ((len != 0) && (fread(addr, (size_t)len, 1, (FILE *)xdrs->x_private) != 1)) - return (FALSE); - return (TRUE); + return FALSE; + return TRUE; } static bool_t -xdrstdio_putbytes(XDR *xdrs, const char *addr, u_int len) +xdrstdio_putbytes(XDR *xdrs, const char *addr, unsigned len) { if ((len != 0) && (fwrite(addr, (size_t)len, 1, (FILE *)xdrs->x_private) != 1)) - return (FALSE); - return (TRUE); + return FALSE; + return TRUE; } -static u_int +static unsigned xdrstdio_getpos(XDR *xdrs) { - return ((u_int)ftell((FILE *)xdrs->x_private)); + return (unsigned)ftell((FILE *)xdrs->x_private); } static bool_t -xdrstdio_setpos(XDR *xdrs, u_int pos) +xdrstdio_setpos(XDR *xdrs, unsigned pos) { - return ((fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ? FALSE : TRUE); + return (fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ? FALSE : TRUE; } diff --git a/mfhdf/test/xdrtest.c b/mfhdf/test/xdrtest.c index 33fd90fae6..c8e4c73a66 100644 --- a/mfhdf/test/xdrtest.c +++ b/mfhdf/test/xdrtest.c @@ -44,10 +44,10 @@ * > xdr_elem: routine to XDR each element */ bool_t -xdr_vector(XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_elem) +xdr_vector(XDR *xdrs, char *basep, unsigned nelem, unsigned elemsize, xdrproc_t xdr_elem) { - u_int i; - char *elptr; + unsigned i; + char *elptr; elptr = basep; for (i = 0; i < nelem; i++) { @@ -67,10 +67,10 @@ main(int ac, char *av[]) FILE *F; XDR xdrs[1]; size_t count; - u_int szof; + unsigned szof; /* some random numbers, divisible by 4 and less than 32k */ - static u_int seeks[] = { + static unsigned seeks[] = { 16828, 8448, 20632, @@ -90,8 +90,8 @@ main(int ac, char *av[]) 12556, }; - u_int poses[8]; - int jj = 0; + unsigned poses[8]; + int jj = 0; static char text[32] = {"Hiya sailor. New in town?"}; char got_s[32]; From 479e6323a2d441f28c1c8d36cadef05254131e3c Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 15:44:51 -0800 Subject: [PATCH 19/52] xdr.h Boolean cleanup * Included mfhdf.h to get Boolean values * Removed redundant TRUE/FALSE --- mfhdf/libsrc/xdr.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 736f64acfe..774029e5ee 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -45,12 +45,8 @@ #include #endif -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif +#include "mfhdf.h" + typedef int32_t bool_t; /* From 8d8c7b37e0583566f92590303e3781edaeafae75 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 21:05:02 -0800 Subject: [PATCH 20/52] Moved things out of xdr.h --- mfhdf/libsrc/xdr.c | 28 +++++++++++++++++++++++ mfhdf/libsrc/xdr.h | 54 +++++--------------------------------------- mfhdf/test/xdrtest.c | 20 ++++++++++++++++ 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index c6bda9f736..3f7e716172 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -44,11 +44,39 @@ #include "xdr.h" +/* + * This is the number of bytes per unit of external data. + */ +#define BYTES_PER_XDR_UNIT (4) + /* * for unit alignment */ static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0}; +/* + * Utility functions for 32-bit ints + */ +static int +xdr_getint32(XDR *xdrs, int32_t *ip) +{ + long l; + + if (!xdr_getlong(xdrs, &l)) + return FALSE; + *ip = (int32_t)l; + return TRUE; +} + +static int +xdr_putint32(XDR *xdrs, int32_t *ip) +{ + long l; + + l = (long)*ip; + return xdr_putlong(xdrs, &l); +} + /* * XDR integers */ diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 774029e5ee..3f30bd4c29 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -86,11 +86,6 @@ typedef int32_t bool_t; */ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; -/* - * This is the number of bytes per unit of external data. - */ -#define BYTES_PER_XDR_UNIT (4) - /* * The XDR handle. * Contains operation which is being applied to the stream, @@ -103,38 +98,21 @@ typedef struct xinfo { /* Get/put long from underlying stream */ bool_t (*x_getlong)(struct xinfo *, long *); bool_t (*x_putlong)(struct xinfo *, const long *); - /* Get/put bytes. */ + + /* Get/put bytes */ bool_t (*x_getbytes)(struct xinfo *, char *, unsigned); bool_t (*x_putbytes)(struct xinfo *, const char *, unsigned); - /* Get or seek within the stream (offsets from beginning of stream). */ + + /* Get or seek within the stream (offsets from beginning of stream) */ unsigned (*x_getpostn)(struct xinfo *); bool_t (*x_setpostn)(struct xinfo *, unsigned); - /* Free the stream. */ + + /* Free the stream */ void (*x_destroy)(struct xinfo *); } * x_ops; void *x_private; /* pointer to private data */ } XDR; -/*                                                                                - * A xdrproc_t exists for each data type which is to be encoded or decoded.       - *                                                                                - * The second argument to the xdrproc_t is a pointer to an opaque pointer.        - * The opaque pointer generally points to a structure of the data type            - * to be decoded.  If this pointer is 0, then the type routines should            - * allocate dynamic storage of the appropriate size and return it.                - *                                                                                - * This typedef has caused problems in the past. Most compilers flag the          - * signature as incompatible and this can result in undefined behavior            - * according to the C99 standard.                                                 - *                                                                                - * The current typedef used here works on all tested platforms, but be            - * aware that future compilers could have trouble with it. Failures               - * will most often be raised in xdr_vector calls in xdrtest.c. We've              - * papered over the incompatible pointer warnings with casts for the              - * time being.                                                                    - */ -typedef bool_t (*xdrproc_t)(XDR *, void *, ...); - /* * Operations defined on a XDR handle * @@ -147,26 +125,6 @@ typedef bool_t (*xdrproc_t)(XDR *, void *, ...); #define xdr_getlong(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp) #define xdr_putlong(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp) -static inline int -xdr_getint32(XDR *xdrs, int32_t *ip) -{ - long l; - - if (!xdr_getlong(xdrs, &l)) - return FALSE; - *ip = (int32_t)l; - return TRUE; -} - -static inline int -xdr_putint32(XDR *xdrs, int32_t *ip) -{ - long l; - - l = (long)*ip; - return xdr_putlong(xdrs, &l); -} - #define xdr_getbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) #define xdr_putbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) diff --git a/mfhdf/test/xdrtest.c b/mfhdf/test/xdrtest.c index c8e4c73a66..29c82cf7c8 100644 --- a/mfhdf/test/xdrtest.c +++ b/mfhdf/test/xdrtest.c @@ -33,6 +33,26 @@ #define EPSILON .0005 #endif +/*                                                                                + * A xdrproc_t exists for each data type which is to be encoded or decoded.       + *                                                                                + * The second argument to the xdrproc_t is a pointer to an opaque pointer.        + * The opaque pointer generally points to a structure of the data type            + * to be decoded.  If this pointer is 0, then the type routines should            + * allocate dynamic storage of the appropriate size and return it.                + *                                                                                + * This typedef has caused problems in the past. Most compilers flag the          + * signature as incompatible and this can result in undefined behavior            + * according to the C99 standard.                                                 + *                                                                                + * The current typedef used here works on all tested platforms, but be            + * aware that future compilers could have trouble with it. Failures               + * will most often be raised in xdr_vector calls in xdrtest.c. We've              + * papered over the incompatible pointer warnings with casts for the              + * time being.                                                                    + */ +typedef bool_t (*xdrproc_t)(XDR *, void *, ...); + /* * xdr_vector(): * From 3f7cecf6c98a499b95c1303859a9d9315713c58a Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 21:51:46 -0800 Subject: [PATCH 21/52] Misc XDR cleanup * Move xdrposix.c netCDF fxns to file.c * XDR handle ops macro --> function * Comment out Sun get/put_int calls * Misc reorg and commenting --- mfhdf/libsrc/file.c | 55 ++++++++++++++++++++++++ mfhdf/libsrc/xdr.c | 46 ++++++++++++++++++++ mfhdf/libsrc/xdr.h | 54 ++++++++++++------------ mfhdf/libsrc/xdrposix.c | 93 ++++++----------------------------------- 4 files changed, 141 insertions(+), 107 deletions(-) diff --git a/mfhdf/libsrc/file.c b/mfhdf/libsrc/file.c index 49bdebb4d5..c5589e2852 100644 --- a/mfhdf/libsrc/file.c +++ b/mfhdf/libsrc/file.c @@ -1030,3 +1030,58 @@ ncsetfill(int id, int fillmode) return ret; } + +int +NCxdrfile_sync(XDR *xdrs) +{ + return xdrposix_sync(xdrs); +} + +int +NCxdrfile_create(XDR *xdrs, const char *path, int ncmode) +{ + int fmode; + int fd; + enum xdr_op op; + + switch (ncmode & 0x0f) { + case NC_NOCLOBBER: + fmode = O_RDWR | O_CREAT | O_EXCL; + break; + case NC_CLOBBER: + fmode = O_RDWR | O_CREAT | O_TRUNC; + break; + case NC_WRITE: + fmode = O_RDWR; + break; + case NC_NOWRITE: + fmode = O_RDONLY; + break; + default: + NCadvise(NC_EINVAL, "Bad flag %0x", ncmode & 0x0f); + return -1; + } + +#ifdef H4_HAVE_WIN32_API + /* Set default mode to binary to suppress the expansion of 0x0f into CRLF */ + _fmode |= O_BINARY; +#endif + + fd = open(path, fmode, 0666); + if (fd == -1) { + nc_serror("filename \"%s\"", path); + return -1; + } + + if (ncmode & NC_CREAT) { + op = XDR_ENCODE; + } + else { + op = XDR_DECODE; + } + + if (xdrposix_create(xdrs, fd, fmode, op) < 0) + return -1; + else + return fd; +} diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 3f7e716172..b3a01664c9 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -54,6 +54,52 @@ */ static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0}; +/* + * Operations defined on an XDR handle + */ +bool_t +xdr_getlong(XDR *xdrs, long *lp) +{ + return (*(xdrs)->x_ops->x_getlong)(xdrs, lp); +} + +bool_t +xdr_putlong(XDR *xdrs, long *lp) +{ + return (*(xdrs)->x_ops->x_putlong)(xdrs, lp); +} + +bool_t +xdr_getbytes(XDR *xdrs, char *addr, unsigned len) +{ + return (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len); +} + +bool_t +xdr_putbytes(XDR *xdrs, const char *addr, unsigned len) +{ + return (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len); +} + +unsigned +xdr_getpos(XDR *xdrs) +{ + return (*(xdrs)->x_ops->x_getpostn)(xdrs); +} + +bool_t +xdr_setpos(XDR *xdrs, unsigned pos) +{ + return (*(xdrs)->x_ops->x_setpostn)(xdrs, pos); +} + +void +xdr_destroy(XDR *xdrs) +{ + if ((xdrs)->x_ops->x_destroy) + (*(xdrs)->x_ops->x_destroy)(xdrs); +} + /* * Utility functions for 32-bit ints */ diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 3f30bd4c29..e64ca899bb 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -86,14 +86,16 @@ typedef int32_t bool_t; */ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; -/* - * The XDR handle. - * Contains operation which is being applied to the stream, - * an operations vector for the particular implementation (e.g. see xdr_mem.c), - * and two private fields for the use of the particular implementation. +/* The XDR handle + * + * Contains operation which is being applied to the stream, an operations + * vector for the particular implementation (e.g. see xdr_mem.c), and a + * private field for the use of the particular implementation. */ typedef struct xinfo { - enum xdr_op x_op; /* operation; fast additional param */ + enum xdr_op x_op; /* Operation */ + + /* XDR functions */ struct xdr_ops { /* Get/put long from underlying stream */ bool_t (*x_getlong)(struct xinfo *, long *); @@ -110,37 +112,31 @@ typedef struct xinfo { /* Free the stream */ void (*x_destroy)(struct xinfo *); } * x_ops; - void *x_private; /* pointer to private data */ + + void *x_private; /* Pointer to private data */ } XDR; +#ifdef __cplusplus +extern "C" { +#endif + /* - * Operations defined on a XDR handle - * - * XDR *xdrs; - * long *longp; - * char *addr; - * unsigned len; - * unsigned pos; + * Operations defined on an XDR handle */ -#define xdr_getlong(xdrs, longp) (*(xdrs)->x_ops->x_getlong)(xdrs, longp) -#define xdr_putlong(xdrs, longp) (*(xdrs)->x_ops->x_putlong)(xdrs, longp) +HDFLIBAPI bool_t xdr_getlong(XDR *, long *); +HDFLIBAPI bool_t xdr_putlong(XDR *, long *); -#define xdr_getbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) -#define xdr_putbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) +HDFLIBAPI bool_t xdr_getbytes(XDR *, char *, unsigned); +HDFLIBAPI bool_t xdr_putbytes(XDR *, const char *, unsigned); -#define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs) -#define xdr_setpos(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) +HDFLIBAPI unsigned xdr_getpos(XDR *); +HDFLIBAPI bool_t xdr_setpos(XDR *, unsigned); -#define xdr_destroy(xdrs) \ - if ((xdrs)->x_ops->x_destroy) \ - (*(xdrs)->x_ops->x_destroy)(xdrs) +HDFLIBAPI void xdr_destroy(XDR *); -#ifdef __cplusplus -extern "C" { -#endif /* - * These are the "generic" xdr routines. + * "Generic type" XDR routines */ HDFLIBAPI bool_t xdr_int(XDR *, int *); HDFLIBAPI bool_t xdr_u_int(XDR *, unsigned *); @@ -157,6 +153,10 @@ HDFLIBAPI bool_t xdr_double(XDR *, double *); /* XDR using stdio library (only used in xdrtest.c) */ HDFLIBAPI void xdrstdio_create(XDR *, FILE *, enum xdr_op); +/* POSIX implementation of XDR */ +HDFLIBAPI int xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op); +HDFLIBAPI int xdrposix_sync(XDR *xdrs); + #ifdef __cplusplus } #endif diff --git a/mfhdf/libsrc/xdrposix.c b/mfhdf/libsrc/xdrposix.c index 00a3206b0c..3841b3aa08 100644 --- a/mfhdf/libsrc/xdrposix.c +++ b/mfhdf/libsrc/xdrposix.c @@ -15,37 +15,18 @@ #include #include -#ifdef H4_HAVE_FCNTL_H -#include -#endif - -#ifdef H4_HAVE_IO_H -#include -#endif - -#ifdef H4_HAVE_UNISTD_H -#include -#endif - -#ifdef H4_HAVE_SYS_TYPES_H -#include -#endif - -/* prototypes for NCadvis, nc_error also obtains , , & - * - */ -#include "local_nc.h" - -#include "mfhdf.h" - #ifdef H4_HAVE_ARPA_INET_H #include #endif - #ifdef H4_HAVE_NETINET_IN_H #include /* for htonl() */ #endif +#include "mfhdf.h" +#include "xdr.h" + +/* NOTE: "bio" == Buffered I/O */ + typedef struct { int fd; /* the file descriptor */ int mode; /* file access mode, O_RDONLY, etc */ @@ -213,10 +194,13 @@ static bool_t xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len); static unsigned xdrposix_getpos(XDR *xdrs); static bool_t xdrposix_setpos(XDR *xdrs, unsigned pos); static void xdrposix_destroy(XDR *xdrs); + +#if 0 #if (defined __sun && defined _LP64) static bool_t xdrposix_getint(XDR *xdrs, int *lp); static bool_t xdrposix_putint(XDR *xdrs, const int *lp); #endif +#endif /* * Ops vector for posix type XDR @@ -229,6 +213,7 @@ static struct xdr_ops xdrposix_ops = { xdrposix_getpos, /* get offset in the stream */ xdrposix_setpos, /* set offset in the stream */ xdrposix_destroy, /* destroy stream */ +#if 0 #if defined(__sun) && defined(_LP64) /* Solaris 64-bit (arch=v9 and arch=amd64) differentiates between * 32-bit integers and 64-bit longs via two extra callbacks for @@ -238,6 +223,7 @@ static struct xdr_ops xdrposix_ops = { xdrposix_getint, /* deserialize a 32-bit int */ xdrposix_putint /* serialize a 32-bit int */ #endif +#endif }; /* @@ -263,7 +249,7 @@ hdf_xdrfile_create(XDR *xdrs, int ncop) * Sets the xdr stream handle xdrs for use on the file descriptor fd. * Operation flag is set to op. */ -static int +int xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) { biobuf *biop = new_biobuf(fd, fmode); @@ -284,7 +270,7 @@ xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) /* * "sync" a posix xdr stream. */ -static int +int xdrposix_sync(XDR *xdrs) { biobuf *biop = (biobuf *)xdrs->x_private; @@ -410,6 +396,7 @@ xdrposix_setpos(XDR *xdrs, unsigned pos) return FALSE; } +#if 0 #if (defined __sun && defined _LP64) static bool_t @@ -437,58 +424,4 @@ xdrposix_putint(XDR *xdrs, const int *lp) return TRUE; } #endif /* end of xdrposix_put(get)int */ - -int -NCxdrfile_sync(XDR *xdrs) -{ - return xdrposix_sync(xdrs); -} - -int -NCxdrfile_create(XDR *xdrs, const char *path, int ncmode) -{ - int fmode; - int fd; - enum xdr_op op; - - switch (ncmode & 0x0f) { - case NC_NOCLOBBER: - fmode = O_RDWR | O_CREAT | O_EXCL; - break; - case NC_CLOBBER: - fmode = O_RDWR | O_CREAT | O_TRUNC; - break; - case NC_WRITE: - fmode = O_RDWR; - break; - case NC_NOWRITE: - fmode = O_RDONLY; - break; - default: - NCadvise(NC_EINVAL, "Bad flag %0x", ncmode & 0x0f); - return -1; - } - -#ifdef H4_HAVE_WIN32_API - /* Set default mode to binary to suppress the expansion of 0x0f into CRLF */ - _fmode |= O_BINARY; #endif - - fd = open(path, fmode, 0666); - if (fd == -1) { - nc_serror("filename \"%s\"", path); - return -1; - } - - if (ncmode & NC_CREAT) { - op = XDR_ENCODE; - } - else { - op = XDR_DECODE; - } - - if (xdrposix_create(xdrs, fd, fmode, op) < 0) - return -1; - else - return fd; -} From 7cb8fe2fcffc5e20011c28577404458736c4eb27 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 22:02:47 -0800 Subject: [PATCH 22/52] Removed ancient Sun get/put_int ops No longer needed since we make everyone use our XDR --- mfhdf/libsrc/xdrposix.c | 55 +++-------------------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) diff --git a/mfhdf/libsrc/xdrposix.c b/mfhdf/libsrc/xdrposix.c index 3841b3aa08..e34c336909 100644 --- a/mfhdf/libsrc/xdrposix.c +++ b/mfhdf/libsrc/xdrposix.c @@ -43,10 +43,9 @@ typedef struct { static biobuf * new_biobuf(int fd, int fmode) { - biobuf *biop; + biobuf *biop = NULL; - biop = malloc(sizeof(biobuf)); - if (biop == NULL) + if (NULL == (biop = malloc(sizeof(biobuf)))) return NULL; biop->fd = fd; @@ -195,15 +194,8 @@ static unsigned xdrposix_getpos(XDR *xdrs); static bool_t xdrposix_setpos(XDR *xdrs, unsigned pos); static void xdrposix_destroy(XDR *xdrs); -#if 0 -#if (defined __sun && defined _LP64) -static bool_t xdrposix_getint(XDR *xdrs, int *lp); -static bool_t xdrposix_putint(XDR *xdrs, const int *lp); -#endif -#endif - /* - * Ops vector for posix type XDR + * POSIX XDR operations */ static struct xdr_ops xdrposix_ops = { xdrposix_getlong, /* deserialize a 32-bit int */ @@ -213,17 +205,6 @@ static struct xdr_ops xdrposix_ops = { xdrposix_getpos, /* get offset in the stream */ xdrposix_setpos, /* set offset in the stream */ xdrposix_destroy, /* destroy stream */ -#if 0 -#if defined(__sun) && defined(_LP64) - /* Solaris 64-bit (arch=v9 and arch=amd64) differentiates between - * 32-bit integers and 64-bit longs via two extra callbacks for - * int here. These are not present on other XDR implementations - * like TI-RPC. - */ - xdrposix_getint, /* deserialize a 32-bit int */ - xdrposix_putint /* serialize a 32-bit int */ -#endif -#endif }; /* @@ -395,33 +376,3 @@ xdrposix_setpos(XDR *xdrs, unsigned pos) else return FALSE; } - -#if 0 -#if (defined __sun && defined _LP64) - -static bool_t -xdrposix_getint(XDR *xdrs, int *lp) -{ - unsigned char *up = (unsigned char *)lp; - if (bioread((biobuf *)xdrs->x_private, up, 4) < 4) - return FALSE; -#ifndef H4_WORDS_BIGENDIAN - *lp = ntohl(*lp); -#endif - return TRUE; -} - -static bool_t -xdrposix_putint(XDR *xdrs, const int *lp) -{ - unsigned char *up = (unsigned char *)lp; -#ifndef H4_WORDS_BIGENDIAN - int32_t mycopy = htonl(*lp); - up = (unsigned char *)&mycopy; -#endif - if (biowrite((biobuf *)xdrs->x_private, up, 4) < 4) - return FALSE; - return TRUE; -} -#endif /* end of xdrposix_put(get)int */ -#endif From 94b4b4de3d81f542a567fcf0a0e28ef40f2d555b Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 22:12:20 -0800 Subject: [PATCH 23/52] Remove xdrstdio and xdrtest xdrtest.c relies on xdrstdio and I want to unify xdr.c and xdrposix.c, so out they go... --- mfhdf/libsrc/CMakeLists.txt | 1 - mfhdf/libsrc/Makefile.am | 2 +- mfhdf/libsrc/xdrstdio.c | 157 ------------------ mfhdf/test/CMakeLists.txt | 14 -- mfhdf/test/CMakeTests.cmake | 25 --- mfhdf/test/Makefile.am | 4 +- mfhdf/test/test_xdr.sav | Bin 28228 -> 0 bytes mfhdf/test/xdr_testout.sav | 22 --- mfhdf/test/xdrtest.c | 323 ------------------------------------ mfhdf/test/xdrtest.cyg | 22 --- mfhdf/test/xdrtest.out | 22 --- 11 files changed, 3 insertions(+), 589 deletions(-) delete mode 100644 mfhdf/libsrc/xdrstdio.c delete mode 100644 mfhdf/test/test_xdr.sav delete mode 100644 mfhdf/test/xdr_testout.sav delete mode 100644 mfhdf/test/xdrtest.c delete mode 100644 mfhdf/test/xdrtest.cyg delete mode 100644 mfhdf/test/xdrtest.out diff --git a/mfhdf/libsrc/CMakeLists.txt b/mfhdf/libsrc/CMakeLists.txt index 2fdac31c6c..63a5386966 100644 --- a/mfhdf/libsrc/CMakeLists.txt +++ b/mfhdf/libsrc/CMakeLists.txt @@ -33,7 +33,6 @@ set (HDF4_MFHDF_LIBSRC_CSRCS ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/var.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdr.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrposix.c - ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrstdio.c ) set (HDF4_MFHDF_LIBSRC_INSTALL_CHDRS diff --git a/mfhdf/libsrc/Makefile.am b/mfhdf/libsrc/Makefile.am index d36195fca8..c57d4633a1 100644 --- a/mfhdf/libsrc/Makefile.am +++ b/mfhdf/libsrc/Makefile.am @@ -19,7 +19,7 @@ lib_LTLIBRARIES = libmfhdf.la ## Information for building the "libmfhdf.la" library CSOURCES = array.c attr.c cdf.c dim.c file.c hdfsds.c iarray.c error.c \ globdef.c mfsd.c mfdatainfo.c nssdc.c putget.c putgetg.c \ - sharray.c string.c var.c xdr.c xdrposix.c xdrstdio.c + sharray.c string.c var.c xdr.c xdrposix.c if HDF_BUILD_NETCDF FSOURCES = $(top_builddir)/mfhdf/fortran/jackets.c $(top_srcdir)/mfhdf/fortran/mfsdf.c $(top_srcdir)/mfhdf/fortran/mfsdff.f diff --git a/mfhdf/libsrc/xdrstdio.c b/mfhdf/libsrc/xdrstdio.c deleted file mode 100644 index bfd71618ab..0000000000 --- a/mfhdf/libsrc/xdrstdio.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2009, Sun Microsystems, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - Neither the name of Sun Microsystems, Inc. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * xdr_stdio.c, XDR implementation on standard i/o file. - * - * Copyright (C) 1984, Sun Microsystems, Inc. - * - * This set of routines implements a XDR on a stdio stream. - * XDR_ENCODE serializes onto the stream, XDR_DECODE de-serializes - * from the stream. - */ -#include "h4config.h" - -#include - -#ifdef H4_HAVE_ARPA_INET_H -#include -#endif - -#ifdef H4_HAVE_NETINET_IN_H -#include /* for htonl() */ -#else -#ifdef H4_HAVE_WINSOCK2_H -#include -#endif -#endif - -#include "xdr.h" - -static void xdrstdio_destroy(XDR *); -static bool_t xdrstdio_getlong(XDR *, long *); -static bool_t xdrstdio_putlong(XDR *, const long *); -static bool_t xdrstdio_getbytes(XDR *, char *, unsigned); -static bool_t xdrstdio_putbytes(XDR *, const char *, unsigned); -static unsigned xdrstdio_getpos(XDR *); -static bool_t xdrstdio_setpos(XDR *, unsigned); - -/* - * Ops vector for stdio type XDR - */ -static const struct xdr_ops xdrstdio_ops = { - xdrstdio_getlong, /* deseraialize a long int */ - xdrstdio_putlong, /* seraialize a long int */ - xdrstdio_getbytes, /* deserialize counted bytes */ - xdrstdio_putbytes, /* serialize counted bytes */ - xdrstdio_getpos, /* get offset in the stream */ - xdrstdio_setpos, /* set offset in the stream */ - xdrstdio_destroy /* destroy stream */ -}; - -/* - * Initialize a stdio xdr stream. - * Sets the xdr stream handle xdrs for use on the stream file. - * Operation flag is set to op. - */ -void -xdrstdio_create(XDR *xdrs, FILE *file, enum xdr_op op) -{ - xdrs->x_op = op; - xdrs->x_ops = &xdrstdio_ops; - xdrs->x_private = file; -} - -/* - * Destroy a stdio xdr stream. - * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create. - */ -static void -xdrstdio_destroy(XDR *xdrs) -{ - (void)fflush((FILE *)xdrs->x_private); - /* xx should we close the file ?? */ -} - -static bool_t -xdrstdio_getlong(XDR *xdrs, long *lp) -{ - int32_t mycopy; - - if (fread(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1) - return (FALSE); - - *lp = (long)ntohl(mycopy); - return TRUE; -} - -static bool_t -xdrstdio_putlong(XDR *xdrs, const long *lp) -{ - int32_t mycopy; - - if ((*lp > INT32_MAX) || (*lp < INT32_MIN)) - return FALSE; - - mycopy = (int32_t)htonl((int32_t)*lp); - if (fwrite(&mycopy, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1) - return FALSE; - return TRUE; -} - -static bool_t -xdrstdio_getbytes(XDR *xdrs, char *addr, unsigned len) -{ - - if ((len != 0) && (fread(addr, (size_t)len, 1, (FILE *)xdrs->x_private) != 1)) - return FALSE; - return TRUE; -} - -static bool_t -xdrstdio_putbytes(XDR *xdrs, const char *addr, unsigned len) -{ - - if ((len != 0) && (fwrite(addr, (size_t)len, 1, (FILE *)xdrs->x_private) != 1)) - return FALSE; - return TRUE; -} - -static unsigned -xdrstdio_getpos(XDR *xdrs) -{ - - return (unsigned)ftell((FILE *)xdrs->x_private); -} - -static bool_t -xdrstdio_setpos(XDR *xdrs, unsigned pos) -{ - - return (fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ? FALSE : TRUE; -} diff --git a/mfhdf/test/CMakeLists.txt b/mfhdf/test/CMakeLists.txt index 48b511354b..93ccf66228 100644 --- a/mfhdf/test/CMakeLists.txt +++ b/mfhdf/test/CMakeLists.txt @@ -47,20 +47,6 @@ else () endif () set_target_properties (cdftest PROPERTIES FOLDER test COMPILE_DEFINITIONS "HDF") -#-- Adding test for xdrtest -add_executable (xdrtest xdrtest.c) -target_include_directories(xdrtest PRIVATE "${HDF4_MFHDFSOURCE_DIR}") -if (NOT BUILD_SHARED_LIBS) - TARGET_C_PROPERTIES (xdrtest STATIC) - target_link_libraries (xdrtest PRIVATE ${HDF4_MF_LIB_TARGET}) -else () - TARGET_C_PROPERTIES (xdrtest SHARED) - target_link_libraries (xdrtest PRIVATE ${HDF4_MF_LIBSH_TARGET}) -endif () -if (CMAKE_C_COMPILER_ID MATCHES "IntelLLVM") - target_compile_options(xdrtest PRIVATE "-Wno-incompatible-function-pointer-types") -endif () - #-- Adding test for hdfnctest set (hdfnctest_SRCS ${HDF4_MFHDF_TEST_SOURCE_DIR}/hdfnctest.c diff --git a/mfhdf/test/CMakeTests.cmake b/mfhdf/test/CMakeTests.cmake index b82bd756f6..91900509d8 100644 --- a/mfhdf/test/CMakeTests.cmake +++ b/mfhdf/test/CMakeTests.cmake @@ -130,28 +130,3 @@ set_tests_properties (MFHDF_TEST-hdfnctest PROPERTIES DEPENDS MFHDF_TEST-cdftest LABELS ${PROJECT_NAME} ) - -if (MSVC_VERSION LESS 1900) - HDFTEST_COPY_FILE("${HDF4_MFHDF_TEST_DIR}/xdrtest.out" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") -else () - HDFTEST_COPY_FILE("${HDF4_MFHDF_TEST_DIR}/xdrtest.cyg" "${PROJECT_BINARY_DIR}/TEST/xdrtest.out" "xdrtest_files") -endif () -add_custom_target(xdrtest_files ALL COMMENT "Copying files needed by xdrtest tests" DEPENDS ${xdrtest_files_list}) - -if (HDF4_ENABLE_USING_MEMCHECKER) - add_test (NAME MFHDF_TEST-xdrtest COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $) -else () - add_test ( - NAME MFHDF_TEST-xdrtest - COMMAND "${CMAKE_COMMAND}" - -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}" - -D "TEST_PROGRAM=$" - -D "TEST_ARGS:STRING=" - -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/TEST" - -D "TEST_OUTPUT=xdrtest.tst" - -D "TEST_EXPECT=0" - -D "TEST_REFERENCE=xdrtest.out" - -P "${HDF_RESOURCES_DIR}/runTest.cmake" - ) -endif () -set_tests_properties (MFHDF_TEST-xdrtest PROPERTIES DEPENDS hdfnctest LABELS ${PROJECT_NAME}) diff --git a/mfhdf/test/Makefile.am b/mfhdf/test/Makefile.am index c2740d0a8f..9df63dad8c 100644 --- a/mfhdf/test/Makefile.am +++ b/mfhdf/test/Makefile.am @@ -15,9 +15,9 @@ AM_CPPFLAGS=$(test_INCLUDES) $(DEFINES) ## Testing ## ############################################################################# -TEST_PROG = cdftest hdfnctest hdftest xdrtest +TEST_PROG = cdftest hdfnctest hdftest TEST_SCRIPT = testmfhdf.sh -check_PROGRAMS = cdftest hdfnctest hdftest xdrtest +check_PROGRAMS = cdftest hdfnctest hdftest check_SCRIPTS = testmfhdf.sh cdftest_SOURCES = cdftest.c diff --git a/mfhdf/test/test_xdr.sav b/mfhdf/test/test_xdr.sav deleted file mode 100644 index 06e8dd02630215d0640b3fb3b8fb7b8028e26e4b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28228 zcmeI)PfEi;6bImm|GmYWK)iuzR<6V&*oBLLw4g!}Hy+Jpy_05ql5tnMY^;0(KORX2 z-sGEAU`R>^0RjXF5FkK+009C72uvl=t=rVC-y-j+`$&;?s-@^lfB*pk1PBlyK!5-N z0t5&UATXss)4fjF{y+2{N@@}Jc*5f6+>aPz00t5&UAV7cs0RjZ}O~7~5zU`Rx5+Fc;009C72oNAZ wfB*pk1PBlyK!5-N0t5&UAn-Q?W_ROH&t|u^wzXc?n#WpK`+KhSFs_fj0rU_pJ^%m! diff --git a/mfhdf/test/xdr_testout.sav b/mfhdf/test/xdr_testout.sav deleted file mode 100644 index 474fdf1c2f..0000000000 --- a/mfhdf/test/xdr_testout.sav +++ /dev/null @@ -1,22 +0,0 @@ -string: Hiya sailor. New in town? -unsigned bytes: 254 255 0 1 2 0 0 0 -ints: 5 6 7 8 9 -unsigned ints: 65535 65534 0 1 2 -LONG: 82555 -longs: -4 -3 -2 -1 0 -unsigned longs: 65535 65534 0 1 2 -floats: - 1.001250e+02 - 1.002500e+02 - 1.003750e+02 - 1.005000e+02 - 1.006250e+02 - -doubles: - 8.388608250000e+06 - 4.194304125000e+06 - 2.097152062500e+06 - 1.048576031250e+06 - 5.242880156250e+05 - -enums: 0 1 2 3 4 diff --git a/mfhdf/test/xdrtest.c b/mfhdf/test/xdrtest.c deleted file mode 100644 index 29c82cf7c8..0000000000 --- a/mfhdf/test/xdrtest.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright 1988, University Corporation for Atmospheric Research - * Not for Resale. All copies to include this notice. - */ - -#include "h4config.h" - -#include -#include - -/* - * This program tests only the xdr library functionality required by netCDF. - * 'xdr_vector' is not used by the netCDF, it is used here for convenience. - */ - -#define xdr_assert(ex) \ - { \ - if (!(ex)) { \ - (void)fprintf(stderr, "Assertion failed: file \"%s\", line %d\n", __FILE__, __LINE__); \ - } \ - } - -#include "xdr.h" - -#define TESTFILE "test.xdr" - -/* if this is NOT defined, then the program just reads the file */ -#define CREATE - -#ifdef __FreeBSD__ -#define EPSILON .005 -#else -#define EPSILON .0005 -#endif - -/*                                                                                - * A xdrproc_t exists for each data type which is to be encoded or decoded.       - *                                                                                - * The second argument to the xdrproc_t is a pointer to an opaque pointer.        - * The opaque pointer generally points to a structure of the data type            - * to be decoded.  If this pointer is 0, then the type routines should            - * allocate dynamic storage of the appropriate size and return it.                - *                                                                                - * This typedef has caused problems in the past. Most compilers flag the          - * signature as incompatible and this can result in undefined behavior            - * according to the C99 standard.                                                 - *                                                                                - * The current typedef used here works on all tested platforms, but be            - * aware that future compilers could have trouble with it. Failures               - * will most often be raised in xdr_vector calls in xdrtest.c. We've              - * papered over the incompatible pointer warnings with casts for the              - * time being.                                                                    - */ -typedef bool_t (*xdrproc_t)(XDR *, void *, ...); - -/* - * xdr_vector(): - * - * XDR a fixed length array. Unlike variable-length arrays, - * the storage of fixed length arrays is static and unfreeable. - * > basep: base of the array - * > size: size of the array - * > elemsize: size of each element - * > xdr_elem: routine to XDR each element - */ -bool_t -xdr_vector(XDR *xdrs, char *basep, unsigned nelem, unsigned elemsize, xdrproc_t xdr_elem) -{ - unsigned i; - char *elptr; - - elptr = basep; - for (i = 0; i < nelem; i++) { - if (!(*xdr_elem)(xdrs, elptr)) { - return FALSE; - } - elptr += elemsize; - } - return TRUE; -} - -int -main(int ac, char *av[]) -{ - int ii; - const char *fname; - FILE *F; - XDR xdrs[1]; - size_t count; - unsigned szof; - - /* some random numbers, divisible by 4 and less than 32k */ - static unsigned seeks[] = { - 16828, - 8448, - 20632, - 8124, - 16764, - 17232, - 3476, - 28168, /* +(5 * sizeof(double) + (5 * sizeof(enum) */ - /* */ - 28108, - 16796, - 10968, - 24104, - 30560, - 16880, - 17260, - 12556, - }; - - unsigned poses[8]; - int jj = 0; - - static char text[32] = {"Hiya sailor. New in town?"}; - char got_s[32]; - - static unsigned char bytes[8] = {254, 255, 0, 1, 2}; - unsigned char *bp, got_ab[8]; - - static int ints[5] = {5, 6, 7, 8, 9}; - int *ip, got_ip[5]; - - static unsigned int u_ints[5] = {((unsigned)65535), ((unsigned)65534), ((unsigned)0), ((unsigned)1), - ((unsigned)2)}; - unsigned int *uip, got_uip[5]; - - long lnum = 82555; - - static long longs[5] = {-4, -3, -2, -1, 0}; - long *lp, got_al[5]; - - static unsigned long u_longs[5] = {((unsigned)65535), ((unsigned)65534), ((unsigned)0), ((unsigned)1), - ((unsigned)2)}; - unsigned long *ulp, got_aul[5]; - - static float floats[5] = {100.125, 100.25, 100.375, 100.5, 100.625}; - float *fp, got_af[5]; - - /* These all require 25 bits: 2^(25-i)+1/2^i, i = 2, 3, ..., 6 */ - static double doubles[5] = {8388608.25, 4194304.125, 2097152.0625, 1048576.03125, 524288.015625}; - - double *dp, got_ad[5]; - - fname = TESTFILE; - if (ac > 1) { - fname = av[1]; - } -#ifdef CREATE - /* Create */ - - F = fopen(fname, "wb"); - if (F == NULL) { - perror("fopen failed"); - exit(EXIT_FAILURE); - } - - /* fill the file so seeks will work even on non-virtual machines */ - for (ii = 0; ii < 28227; ii++) { - xdr_assert(putc(0, F) != EOF); - } - - xdrstdio_create(xdrs, F, XDR_ENCODE); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - xdr_assert(xdr_opaque(xdrs, text, sizeof(text))); - poses[jj++] = xdr_getpos(xdrs); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - xdr_assert(xdr_opaque(xdrs, (char *)bytes, sizeof(bytes))); - - /* no setpos, just for variety */ - szof = sizeof(int); - count = sizeof(ints) / sizeof(int); - xdr_assert(xdr_vector(xdrs, (char *)ints, count, szof, (xdrproc_t)xdr_int)); - poses[jj++] = xdr_getpos(xdrs); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(unsigned int); - count = sizeof(u_ints) / sizeof(unsigned int); - xdr_assert(xdr_vector(xdrs, (char *)u_ints, count, szof, (xdrproc_t)xdr_u_int)); - poses[jj++] = xdr_getpos(xdrs); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - xdr_assert(xdr_long(xdrs, &lnum)); - poses[jj++] = xdr_getpos(xdrs); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(long); - count = sizeof(longs) / sizeof(long); - xdr_assert(xdr_vector(xdrs, (char *)longs, count, szof, (xdrproc_t)xdr_long)); - poses[jj++] = xdr_getpos(xdrs); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(unsigned long); - count = sizeof(u_longs) / sizeof(unsigned long); - xdr_assert(xdr_vector(xdrs, (char *)u_longs, count, szof, (xdrproc_t)xdr_u_long)); - poses[jj++] = xdr_getpos(xdrs); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(float); - count = sizeof(floats) / sizeof(float); - xdr_assert(xdr_vector(xdrs, (char *)floats, count, szof, (xdrproc_t)xdr_float)); - poses[jj++] = xdr_getpos(xdrs); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(double); - count = sizeof(doubles) / sizeof(double); - xdr_assert(xdr_vector(xdrs, (char *)doubles, count, szof, (xdrproc_t)xdr_double)); - poses[jj++] = xdr_getpos(xdrs); - - /* flush, rewind and reopen */ - - xdr_assert(fflush((FILE *)xdrs->x_private) != EOF); /* xdr_destroy(xdrs) */ - - xdr_assert(fclose(F) != EOF); -#endif /* CREATE */ - F = fopen(fname, "rb"); - if (F == NULL) { - perror("fopen failed"); - exit(-1); - } - xdrstdio_create(xdrs, F, XDR_DECODE); - - jj = 0; - - /* check contents */ - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - xdr_assert(xdr_opaque(xdrs, got_s, sizeof(text))); - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - printf("string: %s\n", got_s); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - xdr_assert(xdr_opaque(xdrs, (char *)got_ab, sizeof(bytes))); - printf("unsigned bytes: "); - for (ii = 0, bp = got_ab; ii < (int)sizeof(bytes); ii++, bp++) { - printf("%u ", *bp); - xdr_assert(*bp == bytes[ii]); - } - putchar('\n'); - - szof = sizeof(int); - count = sizeof(ints) / sizeof(int); - xdr_assert(xdr_vector(xdrs, (char *)got_ip, count, szof, (xdrproc_t)xdr_int)); - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - printf("ints: "); - for (ii = 0, ip = got_ip; ii < (int)count; ii++, ip++) { - printf("%d ", *ip); - xdr_assert(*ip == ints[ii]); - } - putchar('\n'); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(unsigned int); - count = sizeof(u_ints) / sizeof(unsigned int); - xdr_assert(xdr_vector(xdrs, (char *)got_uip, count, szof, (xdrproc_t)xdr_u_int)); - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - printf("unsigned ints: "); - for (ii = 0, uip = got_uip; ii < (int)count; ii++, uip++) { - printf("%u ", *uip); - xdr_assert(*uip == u_ints[ii]); - } - putchar('\n'); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - xdr_assert(xdr_long(xdrs, got_al)); - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - printf("LONG: %ld\n", *got_al); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(long); - count = sizeof(longs) / sizeof(long); - xdr_assert(xdr_vector(xdrs, (char *)got_al, count, szof, (xdrproc_t)xdr_long)); - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - printf("longs: "); - for (ii = 0, lp = got_al; ii < (int)count; ii++, lp++) { - printf("%d ", (int)*lp); - xdr_assert((int)*lp == (int)longs[ii]); - } - putchar('\n'); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(unsigned long); - count = sizeof(u_longs) / sizeof(unsigned long); - xdr_assert(xdr_vector(xdrs, (char *)got_aul, count, szof, (xdrproc_t)xdr_u_long)); - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - printf("unsigned longs: "); - for (ii = 0, ulp = got_aul; ii < (int)count; ii++, ulp++) { - printf("%lu ", *ulp); - xdr_assert(*ulp == u_longs[ii]); - } - putchar('\n'); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(float); - count = sizeof(floats) / sizeof(float); - xdr_assert(xdr_vector(xdrs, (char *)got_af, count, szof, (xdrproc_t)xdr_float)); - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - printf("floats:\n"); - for (ii = 0, fp = got_af; ii < (int)count; ii++, fp++) { - printf("\t% .6e\n", *fp); - xdr_assert(*fp floats[ii] - EPSILON); - } - putchar('\n'); - - xdr_assert(xdr_setpos(xdrs, seeks[jj])); - szof = sizeof(double); - count = sizeof(doubles) / sizeof(double); - xdr_assert(xdr_vector(xdrs, (char *)got_ad, count, szof, (xdrproc_t)xdr_double)); - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - printf("doubles:\n"); - for (ii = 0, dp = got_ad; ii < (int)count; ii++, dp++) { - printf("\t% .12e\n", *dp); - xdr_assert((*dp < (doubles[ii] + (double)EPSILON)) && (*dp > (doubles[ii] - (double)EPSILON))); - } - putchar('\n'); - - xdr_assert(poses[jj++] = xdr_getpos(xdrs)); - - exit(EXIT_SUCCESS); -} diff --git a/mfhdf/test/xdrtest.cyg b/mfhdf/test/xdrtest.cyg deleted file mode 100644 index 474fdf1c2f..0000000000 --- a/mfhdf/test/xdrtest.cyg +++ /dev/null @@ -1,22 +0,0 @@ -string: Hiya sailor. New in town? -unsigned bytes: 254 255 0 1 2 0 0 0 -ints: 5 6 7 8 9 -unsigned ints: 65535 65534 0 1 2 -LONG: 82555 -longs: -4 -3 -2 -1 0 -unsigned longs: 65535 65534 0 1 2 -floats: - 1.001250e+02 - 1.002500e+02 - 1.003750e+02 - 1.005000e+02 - 1.006250e+02 - -doubles: - 8.388608250000e+06 - 4.194304125000e+06 - 2.097152062500e+06 - 1.048576031250e+06 - 5.242880156250e+05 - -enums: 0 1 2 3 4 diff --git a/mfhdf/test/xdrtest.out b/mfhdf/test/xdrtest.out deleted file mode 100644 index 66555283cf..0000000000 --- a/mfhdf/test/xdrtest.out +++ /dev/null @@ -1,22 +0,0 @@ -string: Hiya sailor. New in town? -unsigned bytes: 254 255 0 1 2 0 0 0 -ints: 5 6 7 8 9 -unsigned ints: 65535 65534 0 1 2 -LONG: 82555 -longs: -4 -3 -2 -1 0 -unsigned longs: 65535 65534 0 1 2 -floats: - 1.001250e+002 - 1.002500e+002 - 1.003750e+002 - 1.005000e+002 - 1.006250e+002 - -doubles: - 8.388608250000e+006 - 4.194304125000e+006 - 2.097152062500e+006 - 1.048576031250e+006 - 5.242880156250e+005 - -enums: 0 1 2 3 4 From c35b8858dc7a8605facc0235f0a3349743f37d0d Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 22:26:25 -0800 Subject: [PATCH 24/52] Move xdrposix.c to xdr.c Also hard-codes xdrposix calls for op-specific calls --- mfhdf/libsrc/CMakeLists.txt | 1 - mfhdf/libsrc/Makefile.am | 2 +- mfhdf/libsrc/xdr.c | 380 +++++++++++++++++++++++++++++++++++- mfhdf/libsrc/xdr.h | 3 - mfhdf/libsrc/xdrposix.c | 378 ----------------------------------- 5 files changed, 373 insertions(+), 391 deletions(-) delete mode 100644 mfhdf/libsrc/xdrposix.c diff --git a/mfhdf/libsrc/CMakeLists.txt b/mfhdf/libsrc/CMakeLists.txt index 63a5386966..c3f478c159 100644 --- a/mfhdf/libsrc/CMakeLists.txt +++ b/mfhdf/libsrc/CMakeLists.txt @@ -32,7 +32,6 @@ set (HDF4_MFHDF_LIBSRC_CSRCS ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/string.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/var.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdr.c - ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdrposix.c ) set (HDF4_MFHDF_LIBSRC_INSTALL_CHDRS diff --git a/mfhdf/libsrc/Makefile.am b/mfhdf/libsrc/Makefile.am index c57d4633a1..bd51e66f94 100644 --- a/mfhdf/libsrc/Makefile.am +++ b/mfhdf/libsrc/Makefile.am @@ -19,7 +19,7 @@ lib_LTLIBRARIES = libmfhdf.la ## Information for building the "libmfhdf.la" library CSOURCES = array.c attr.c cdf.c dim.c file.c hdfsds.c iarray.c error.c \ globdef.c mfsd.c mfdatainfo.c nssdc.c putget.c putgetg.c \ - sharray.c string.c var.c xdr.c xdrposix.c + sharray.c string.c var.c xdr.c if HDF_BUILD_NETCDF FSOURCES = $(top_builddir)/mfhdf/fortran/jackets.c $(top_srcdir)/mfhdf/fortran/mfsdf.c $(top_srcdir)/mfhdf/fortran/mfsdff.f diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index b3a01664c9..61f55bf0f7 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -38,10 +38,19 @@ #include "h4config.h" +#include #include #include #include +#ifdef H4_HAVE_ARPA_INET_H +#include +#endif +#ifdef H4_HAVE_NETINET_IN_H +#include /* for htonl() */ +#endif + +#include "mfhdf.h" #include "xdr.h" /* @@ -54,50 +63,57 @@ */ static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0}; +static bool_t xdrposix_getlong(XDR *xdrs, long *lp); +static bool_t xdrposix_putlong(XDR *xdrs, const long *lp); +static bool_t xdrposix_getbytes(XDR *xdrs, char *addr, unsigned len); +static bool_t xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len); +static unsigned xdrposix_getpos(XDR *xdrs); +static bool_t xdrposix_setpos(XDR *xdrs, unsigned pos); +static void xdrposix_destroy(XDR *xdrs); + /* * Operations defined on an XDR handle */ bool_t xdr_getlong(XDR *xdrs, long *lp) { - return (*(xdrs)->x_ops->x_getlong)(xdrs, lp); + return xdrposix_getlong(xdrs, lp); } bool_t xdr_putlong(XDR *xdrs, long *lp) { - return (*(xdrs)->x_ops->x_putlong)(xdrs, lp); + return xdrposix_putlong(xdrs, lp); } bool_t xdr_getbytes(XDR *xdrs, char *addr, unsigned len) { - return (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len); + return xdrposix_getbytes(xdrs, addr, len); } bool_t xdr_putbytes(XDR *xdrs, const char *addr, unsigned len) { - return (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len); + return xdrposix_putbytes(xdrs, addr, len); } unsigned xdr_getpos(XDR *xdrs) { - return (*(xdrs)->x_ops->x_getpostn)(xdrs); + return xdrposix_getpos(xdrs); } bool_t xdr_setpos(XDR *xdrs, unsigned pos) { - return (*(xdrs)->x_ops->x_setpostn)(xdrs, pos); + return xdrposix_setpos(xdrs, pos); } void xdr_destroy(XDR *xdrs) { - if ((xdrs)->x_ops->x_destroy) - (*(xdrs)->x_ops->x_destroy)(xdrs); + xdrposix_destroy(xdrs); } /* @@ -447,3 +463,351 @@ xdr_uint64_t(XDR *xdrs, uint64_t *ullp) return FALSE; } #endif + +/*********************/ +/* FORMER xdrposix.c */ +/*********************/ + +/* NOTE: "bio" == Buffered I/O */ + +typedef struct { + int fd; /* the file descriptor */ + int mode; /* file access mode, O_RDONLY, etc */ + int isdirty; + off_t page; + int nread; /* number of bytes successfully read */ + int nwrote; /* number of bytes last write */ + int cnt; /* number of valid bytes in buffer */ + unsigned char *ptr; /* next byte */ +#define BIOBUFSIZ 8192 + unsigned char base[BIOBUFSIZ]; /* the data buffer */ +} biobuf; + +static biobuf * +new_biobuf(int fd, int fmode) +{ + biobuf *biop = NULL; + + if (NULL == (biop = malloc(sizeof(biobuf)))) + return NULL; + biop->fd = fd; + + biop->mode = fmode; + + biop->isdirty = 0; + biop->page = 0; + biop->nread = 0; + biop->nwrote = 0; + biop->cnt = 0; + memset(biop->base, 0, ((size_t)(BIOBUFSIZ))); + biop->ptr = biop->base; + + return biop; +} + +static int +rdbuf(biobuf *biop) +{ + memset(biop->base, 0, ((size_t)(BIOBUFSIZ))); + + if (biop->mode & O_WRONLY) { + biop->cnt = 0; + } + else { + if (biop->nwrote != BIOBUFSIZ) { + /* last write wasn't a full block, adjust position ahead */ + if (lseek(biop->fd, biop->page * BIOBUFSIZ, SEEK_SET) == ((off_t)-1)) + return -1; + } + biop->nread = biop->cnt = read(biop->fd, (void *)biop->base, BIOBUFSIZ); + } + biop->ptr = biop->base; + return biop->cnt; +} + +static int +wrbuf(biobuf *biop) +{ + + if (!((biop->mode & O_WRONLY) || (biop->mode & O_RDWR)) || biop->cnt == 0) { + biop->nwrote = 0; + } + else { + if (biop->nread != 0) { + /* if we read something, we have to adjust position back */ + if (lseek(biop->fd, biop->page * BIOBUFSIZ, SEEK_SET) == ((off_t)-1)) + return -1; + } + biop->nwrote = write(biop->fd, (void *)biop->base, biop->cnt); + } + biop->isdirty = 0; + + return biop->nwrote; +} + +static int +nextbuf(biobuf *biop) +{ + if (biop->isdirty) { + if (wrbuf(biop) < 0) + return -1; + } + + biop->page++; + + /* read it in */ + if (rdbuf(biop) < 0) + return -1; + + return biop->cnt; +} + +#define CNT(p) ((p)->ptr - (p)->base) + +/* # of unread bytes in buffer */ +#define REM(p) ((p)->cnt - CNT(p)) + +/* available space for write in buffer */ +#define BREM(p) (BIOBUFSIZ - CNT(p)) + +static int +bioread(biobuf *biop, unsigned char *ptr, int nbytes) +{ + int ngot = 0; + size_t rem; + + if (nbytes == 0) + return 0; + + while (nbytes > (rem = REM(biop))) { + if (rem > 0) { + (void)memcpy(ptr, biop->ptr, rem); + ptr += rem; + nbytes -= rem; + ngot += rem; + } + if (nextbuf(biop) <= 0) + return ngot; + } + /* we know nbytes <= REM at this point */ + (void)memcpy(ptr, biop->ptr, (size_t)nbytes); + biop->ptr += nbytes; + ngot += nbytes; + return ngot; +} + +static int +biowrite(biobuf *biop, unsigned char *ptr, int nbytes) +{ + size_t rem; + int nwrote = 0; + int cnt; + + if (!((biop->mode & O_WRONLY) || (biop->mode & O_RDWR))) + return -1; + + while (nbytes > (rem = BREM(biop))) { + if (rem > 0) { + (void)memcpy(biop->ptr, ptr, rem); + biop->isdirty = !0; + biop->cnt = BIOBUFSIZ; + ptr += rem; + nbytes -= rem; + nwrote += rem; + } + if (nextbuf(biop) < 0) + return nwrote; + } + /* we know nbytes <= BREM at this point */ + (void)memcpy(biop->ptr, ptr, (size_t)nbytes); + biop->isdirty = !0; + biop->ptr += nbytes; + if ((cnt = CNT(biop)) > biop->cnt) + biop->cnt = cnt; + nwrote += nbytes; + + return nwrote; +} + +/* + * POSIX XDR operations + */ +static struct xdr_ops xdrposix_ops = { + xdrposix_getlong, /* deserialize a 32-bit int */ + xdrposix_putlong, /* serialize a 32-bit int */ + xdrposix_getbytes, /* deserialize counted bytes */ + xdrposix_putbytes, /* serialize counted bytes */ + xdrposix_getpos, /* get offset in the stream */ + xdrposix_setpos, /* set offset in the stream */ + xdrposix_destroy, /* destroy stream */ +}; + +/* + * Fake an XDR initialization for HDF files + */ +void +hdf_xdrfile_create(XDR *xdrs, int ncop) +{ + biobuf *biop = new_biobuf(-1, 0); + + if (ncop & NC_CREAT) + xdrs->x_op = XDR_ENCODE; + else + xdrs->x_op = XDR_DECODE; + + xdrs->x_ops = &xdrposix_ops; + xdrs->x_private = (char *)biop; + +} /* hdf_xdrfile_create */ + +/* + * Initialize a posix xdr stream. + * Sets the xdr stream handle xdrs for use on the file descriptor fd. + * Operation flag is set to op. + */ +int +xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) +{ + biobuf *biop = new_biobuf(fd, fmode); + xdrs->x_op = op; + xdrs->x_ops = &xdrposix_ops; + xdrs->x_private = (char *)biop; + if (biop == NULL) + return -1; + + /* if write only, or just created (empty), done */ + if ((biop->mode & O_WRONLY) || (biop->mode & O_CREAT)) + return 0; + + /* else, read the first bufferful */ + return rdbuf(biop); +} + +/* + * "sync" a posix xdr stream. + */ +int +xdrposix_sync(XDR *xdrs) +{ + biobuf *biop = (biobuf *)xdrs->x_private; + if (biop->isdirty) { + /* flush */ + if (wrbuf(biop) < 0) + return -1; + } + + biop->nwrote = 0; /* force seek in rdbuf */ + + /* read it in */ + if (rdbuf(biop) < 0) + return -1; + + return biop->cnt; +} + +/* + * Destroy a posix xdr stream. + * Cleans up the xdr stream handle xdrs previously set up by xdrposix_create. + */ +static void +xdrposix_destroy(XDR *xdrs) +{ + /* flush */ + biobuf *biop = (biobuf *)xdrs->x_private; + if (biop != NULL) { + if (biop->isdirty) { + (void)wrbuf(biop); + } + if (biop->fd != -1) + (void)close(biop->fd); + free(biop); + } +} + +static bool_t +xdrposix_getlong(XDR *xdrs, long *lp) +{ + unsigned char *up = (unsigned char *)lp; +#if (defined AIX5L64 || defined __powerpc64__) + *lp = 0; + up += (sizeof(long) - 4); +#endif + if (bioread((biobuf *)xdrs->x_private, up, 4) < 4) + return FALSE; +#ifndef H4_WORDS_BIGENDIAN + *lp = ntohl(*lp); +#endif + return TRUE; +} + +static bool_t +xdrposix_putlong(XDR *xdrs, const long *lp) +{ + + unsigned char *up = (unsigned char *)lp; +#ifndef H4_WORDS_BIGENDIAN + int32_t mycopy = htonl(*lp); + up = (unsigned char *)&mycopy; +#endif +#if (defined AIX5L64 || defined __powerpc64__) + up += (sizeof(long) - 4); +#endif + + if (biowrite((biobuf *)xdrs->x_private, up, 4) < 4) + return FALSE; + return TRUE; +} + +static bool_t +xdrposix_getbytes(XDR *xdrs, char *addr, unsigned len) +{ + if ((len != 0) && (bioread((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) + return FALSE; + return TRUE; +} + +static bool_t +xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len) +{ + if ((len != 0) && (biowrite((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) + return FALSE; + return TRUE; +} + +static unsigned +xdrposix_getpos(XDR *xdrs) +{ + biobuf *biop = (biobuf *)xdrs->x_private; + return BIOBUFSIZ * biop->page + CNT(biop); +} + +static bool_t +xdrposix_setpos(XDR *xdrs, unsigned pos) +{ + biobuf *biop = (biobuf *)xdrs->x_private; + if (biop != NULL) { + off_t page; + int index; + int nread; + page = pos / BIOBUFSIZ; + index = pos % BIOBUFSIZ; + if (page != biop->page) { + if (biop->isdirty) { + if (wrbuf(biop) < 0) + return FALSE; + } + if (page != biop->page + 1) + biop->nwrote = 0; /* force seek in rdbuf */ + + biop->page = page; + + nread = rdbuf(biop); + if (nread < 0 || ((biop->mode & O_RDONLY) && nread < index)) + return FALSE; + } + biop->ptr = biop->base + index; + return TRUE; + } + else + return FALSE; +} diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index e64ca899bb..cc95030fbe 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -150,9 +150,6 @@ HDFLIBAPI bool_t xdr_opaque(XDR *, char *, unsigned); HDFLIBAPI bool_t xdr_float(XDR *, float *); HDFLIBAPI bool_t xdr_double(XDR *, double *); -/* XDR using stdio library (only used in xdrtest.c) */ -HDFLIBAPI void xdrstdio_create(XDR *, FILE *, enum xdr_op); - /* POSIX implementation of XDR */ HDFLIBAPI int xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op); HDFLIBAPI int xdrposix_sync(XDR *xdrs); diff --git a/mfhdf/libsrc/xdrposix.c b/mfhdf/libsrc/xdrposix.c deleted file mode 100644 index e34c336909..0000000000 --- a/mfhdf/libsrc/xdrposix.c +++ /dev/null @@ -1,378 +0,0 @@ -/* - * XDR implementation on POSIX file interface, with buffering - * - * Copyright (C) 1992, University Corp for Atmospheric Research - * - * This set of routines implements a XDR on a POSIX file descriptor. - * XDR_ENCODE serializes onto the descriptor, XDR_DECODE de-serializes - * from the descriptor. As in stdio, we buffer i/o. This XDR is most - * useful when the descriptor actually represents a file. It - * corrects some performance problems with xdrstdio_getpos() and - * xdrstdio_getpos() in the xdr_stdio implementation. - */ -#include "h4config.h" - -#include -#include - -#ifdef H4_HAVE_ARPA_INET_H -#include -#endif -#ifdef H4_HAVE_NETINET_IN_H -#include /* for htonl() */ -#endif - -#include "mfhdf.h" -#include "xdr.h" - -/* NOTE: "bio" == Buffered I/O */ - -typedef struct { - int fd; /* the file descriptor */ - int mode; /* file access mode, O_RDONLY, etc */ - int isdirty; - off_t page; - int nread; /* number of bytes successfully read */ - int nwrote; /* number of bytes last write */ - int cnt; /* number of valid bytes in buffer */ - unsigned char *ptr; /* next byte */ -#define BIOBUFSIZ 8192 - unsigned char base[BIOBUFSIZ]; /* the data buffer */ -} biobuf; - -static biobuf * -new_biobuf(int fd, int fmode) -{ - biobuf *biop = NULL; - - if (NULL == (biop = malloc(sizeof(biobuf)))) - return NULL; - biop->fd = fd; - - biop->mode = fmode; - - biop->isdirty = 0; - biop->page = 0; - biop->nread = 0; - biop->nwrote = 0; - biop->cnt = 0; - memset(biop->base, 0, ((size_t)(BIOBUFSIZ))); - biop->ptr = biop->base; - - return biop; -} - -static int -rdbuf(biobuf *biop) -{ - memset(biop->base, 0, ((size_t)(BIOBUFSIZ))); - - if (biop->mode & O_WRONLY) { - biop->cnt = 0; - } - else { - if (biop->nwrote != BIOBUFSIZ) { - /* last write wasn't a full block, adjust position ahead */ - if (lseek(biop->fd, biop->page * BIOBUFSIZ, SEEK_SET) == ((off_t)-1)) - return -1; - } - biop->nread = biop->cnt = read(biop->fd, (void *)biop->base, BIOBUFSIZ); - } - biop->ptr = biop->base; - return biop->cnt; -} - -static int -wrbuf(biobuf *biop) -{ - - if (!((biop->mode & O_WRONLY) || (biop->mode & O_RDWR)) || biop->cnt == 0) { - biop->nwrote = 0; - } - else { - if (biop->nread != 0) { - /* if we read something, we have to adjust position back */ - if (lseek(biop->fd, biop->page * BIOBUFSIZ, SEEK_SET) == ((off_t)-1)) - return -1; - } - biop->nwrote = write(biop->fd, (void *)biop->base, biop->cnt); - } - biop->isdirty = 0; - - return biop->nwrote; -} - -static int -nextbuf(biobuf *biop) -{ - if (biop->isdirty) { - if (wrbuf(biop) < 0) - return -1; - } - - biop->page++; - - /* read it in */ - if (rdbuf(biop) < 0) - return -1; - - return biop->cnt; -} - -#define CNT(p) ((p)->ptr - (p)->base) - -/* # of unread bytes in buffer */ -#define REM(p) ((p)->cnt - CNT(p)) - -/* available space for write in buffer */ -#define BREM(p) (BIOBUFSIZ - CNT(p)) - -static int -bioread(biobuf *biop, unsigned char *ptr, int nbytes) -{ - int ngot = 0; - size_t rem; - - if (nbytes == 0) - return 0; - - while (nbytes > (rem = REM(biop))) { - if (rem > 0) { - (void)memcpy(ptr, biop->ptr, rem); - ptr += rem; - nbytes -= rem; - ngot += rem; - } - if (nextbuf(biop) <= 0) - return ngot; - } - /* we know nbytes <= REM at this point */ - (void)memcpy(ptr, biop->ptr, (size_t)nbytes); - biop->ptr += nbytes; - ngot += nbytes; - return ngot; -} - -static int -biowrite(biobuf *biop, unsigned char *ptr, int nbytes) -{ - size_t rem; - int nwrote = 0; - int cnt; - - if (!((biop->mode & O_WRONLY) || (biop->mode & O_RDWR))) - return -1; - - while (nbytes > (rem = BREM(biop))) { - if (rem > 0) { - (void)memcpy(biop->ptr, ptr, rem); - biop->isdirty = !0; - biop->cnt = BIOBUFSIZ; - ptr += rem; - nbytes -= rem; - nwrote += rem; - } - if (nextbuf(biop) < 0) - return nwrote; - } - /* we know nbytes <= BREM at this point */ - (void)memcpy(biop->ptr, ptr, (size_t)nbytes); - biop->isdirty = !0; - biop->ptr += nbytes; - if ((cnt = CNT(biop)) > biop->cnt) - biop->cnt = cnt; - nwrote += nbytes; - - return nwrote; -} - -static bool_t xdrposix_getlong(XDR *xdrs, long *lp); -static bool_t xdrposix_putlong(XDR *xdrs, const long *lp); -static bool_t xdrposix_getbytes(XDR *xdrs, char *addr, unsigned len); -static bool_t xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len); -static unsigned xdrposix_getpos(XDR *xdrs); -static bool_t xdrposix_setpos(XDR *xdrs, unsigned pos); -static void xdrposix_destroy(XDR *xdrs); - -/* - * POSIX XDR operations - */ -static struct xdr_ops xdrposix_ops = { - xdrposix_getlong, /* deserialize a 32-bit int */ - xdrposix_putlong, /* serialize a 32-bit int */ - xdrposix_getbytes, /* deserialize counted bytes */ - xdrposix_putbytes, /* serialize counted bytes */ - xdrposix_getpos, /* get offset in the stream */ - xdrposix_setpos, /* set offset in the stream */ - xdrposix_destroy, /* destroy stream */ -}; - -/* - * Fake an XDR initialization for HDF files - */ -void -hdf_xdrfile_create(XDR *xdrs, int ncop) -{ - biobuf *biop = new_biobuf(-1, 0); - - if (ncop & NC_CREAT) - xdrs->x_op = XDR_ENCODE; - else - xdrs->x_op = XDR_DECODE; - - xdrs->x_ops = &xdrposix_ops; - xdrs->x_private = (char *)biop; - -} /* hdf_xdrfile_create */ - -/* - * Initialize a posix xdr stream. - * Sets the xdr stream handle xdrs for use on the file descriptor fd. - * Operation flag is set to op. - */ -int -xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) -{ - biobuf *biop = new_biobuf(fd, fmode); - xdrs->x_op = op; - xdrs->x_ops = &xdrposix_ops; - xdrs->x_private = (char *)biop; - if (biop == NULL) - return -1; - - /* if write only, or just created (empty), done */ - if ((biop->mode & O_WRONLY) || (biop->mode & O_CREAT)) - return 0; - - /* else, read the first bufferful */ - return rdbuf(biop); -} - -/* - * "sync" a posix xdr stream. - */ -int -xdrposix_sync(XDR *xdrs) -{ - biobuf *biop = (biobuf *)xdrs->x_private; - if (biop->isdirty) { - /* flush */ - if (wrbuf(biop) < 0) - return -1; - } - - biop->nwrote = 0; /* force seek in rdbuf */ - - /* read it in */ - if (rdbuf(biop) < 0) - return -1; - - return biop->cnt; -} - -/* - * Destroy a posix xdr stream. - * Cleans up the xdr stream handle xdrs previously set up by xdrposix_create. - */ -static void -xdrposix_destroy(XDR *xdrs) -{ - /* flush */ - biobuf *biop = (biobuf *)xdrs->x_private; - if (biop != NULL) { - if (biop->isdirty) { - (void)wrbuf(biop); - } - if (biop->fd != -1) - (void)close(biop->fd); - free(biop); - } -} - -static bool_t -xdrposix_getlong(XDR *xdrs, long *lp) -{ - unsigned char *up = (unsigned char *)lp; -#if (defined AIX5L64 || defined __powerpc64__) - *lp = 0; - up += (sizeof(long) - 4); -#endif - if (bioread((biobuf *)xdrs->x_private, up, 4) < 4) - return FALSE; -#ifndef H4_WORDS_BIGENDIAN - *lp = ntohl(*lp); -#endif - return TRUE; -} - -static bool_t -xdrposix_putlong(XDR *xdrs, const long *lp) -{ - - unsigned char *up = (unsigned char *)lp; -#ifndef H4_WORDS_BIGENDIAN - int32_t mycopy = htonl(*lp); - up = (unsigned char *)&mycopy; -#endif -#if (defined AIX5L64 || defined __powerpc64__) - up += (sizeof(long) - 4); -#endif - - if (biowrite((biobuf *)xdrs->x_private, up, 4) < 4) - return FALSE; - return TRUE; -} - -static bool_t -xdrposix_getbytes(XDR *xdrs, char *addr, unsigned len) -{ - if ((len != 0) && (bioread((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) - return FALSE; - return TRUE; -} - -static bool_t -xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len) -{ - if ((len != 0) && (biowrite((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) - return FALSE; - return TRUE; -} - -static unsigned -xdrposix_getpos(XDR *xdrs) -{ - biobuf *biop = (biobuf *)xdrs->x_private; - return BIOBUFSIZ * biop->page + CNT(biop); -} - -static bool_t -xdrposix_setpos(XDR *xdrs, unsigned pos) -{ - biobuf *biop = (biobuf *)xdrs->x_private; - if (biop != NULL) { - off_t page; - int index; - int nread; - page = pos / BIOBUFSIZ; - index = pos % BIOBUFSIZ; - if (page != biop->page) { - if (biop->isdirty) { - if (wrbuf(biop) < 0) - return FALSE; - } - if (page != biop->page + 1) - biop->nwrote = 0; /* force seek in rdbuf */ - - biop->page = page; - - nread = rdbuf(biop); - if (nread < 0 || ((biop->mode & O_RDONLY) && nread < index)) - return FALSE; - } - biop->ptr = biop->base + index; - return TRUE; - } - else - return FALSE; -} From 2bbd6fd8f547603e058f20eed245970a6e1ebebf Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 22:31:58 -0800 Subject: [PATCH 25/52] Remove ops from XDR Everything is hard-coded to POSIX now --- mfhdf/libsrc/xdr.c | 15 -------------- mfhdf/libsrc/xdr.h | 51 +--------------------------------------------- 2 files changed, 1 insertion(+), 65 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 61f55bf0f7..71bcc56a31 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -629,19 +629,6 @@ biowrite(biobuf *biop, unsigned char *ptr, int nbytes) return nwrote; } -/* - * POSIX XDR operations - */ -static struct xdr_ops xdrposix_ops = { - xdrposix_getlong, /* deserialize a 32-bit int */ - xdrposix_putlong, /* serialize a 32-bit int */ - xdrposix_getbytes, /* deserialize counted bytes */ - xdrposix_putbytes, /* serialize counted bytes */ - xdrposix_getpos, /* get offset in the stream */ - xdrposix_setpos, /* set offset in the stream */ - xdrposix_destroy, /* destroy stream */ -}; - /* * Fake an XDR initialization for HDF files */ @@ -655,7 +642,6 @@ hdf_xdrfile_create(XDR *xdrs, int ncop) else xdrs->x_op = XDR_DECODE; - xdrs->x_ops = &xdrposix_ops; xdrs->x_private = (char *)biop; } /* hdf_xdrfile_create */ @@ -670,7 +656,6 @@ xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) { biobuf *biop = new_biobuf(fd, fmode); xdrs->x_op = op; - xdrs->x_ops = &xdrposix_ops; xdrs->x_private = (char *)biop; if (biop == NULL) return -1; diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index cc95030fbe..74d1255308 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -49,35 +49,6 @@ typedef int32_t bool_t; -/* - * XDR provides a conventional way for converting between C data - * types and an external bit-string representation. Library supplied - * routines provide for the conversion on built-in C data types. These - * routines and utility routines defined here are used to help implement - * a type encode/decode routine for each user-defined type. - * - * Each data type provides a single procedure which takes two arguments: - * - * bool_t - * xdrproc(xdrs, argresp) - * XDR *xdrs; - * *argresp; - * - * xdrs is an instance of a XDR handle, to which or from which the data - * type is to be converted. argresp is a pointer to the structure to be - * converted. The XDR handle contains an operation field which indicates - * which of the operations (ENCODE, DECODE * or FREE) is to be performed. - * - * XDR_DECODE may allocate space if the pointer argresp is null. This - * data can be freed with the XDR_FREE operation. - * - * We write only one procedure per data type to make it easy - * to keep the encode and decode procedures for a data type consistent. - * In many cases the same code performs all operations on a user defined type, - * because all the hard work is done in the component type routines. - * decode as a series of calls on the nested data types. - */ - /* * XDR operations. XDR_ENCODE causes the type to be encoded into the * stream. XDR_DECODE causes the type to be extracted from the stream. @@ -88,31 +59,11 @@ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; /* The XDR handle * - * Contains operation which is being applied to the stream, an operations - * vector for the particular implementation (e.g. see xdr_mem.c), and a + * Contains the operation which is being applied to the stream and a * private field for the use of the particular implementation. */ typedef struct xinfo { enum xdr_op x_op; /* Operation */ - - /* XDR functions */ - struct xdr_ops { - /* Get/put long from underlying stream */ - bool_t (*x_getlong)(struct xinfo *, long *); - bool_t (*x_putlong)(struct xinfo *, const long *); - - /* Get/put bytes */ - bool_t (*x_getbytes)(struct xinfo *, char *, unsigned); - bool_t (*x_putbytes)(struct xinfo *, const char *, unsigned); - - /* Get or seek within the stream (offsets from beginning of stream) */ - unsigned (*x_getpostn)(struct xinfo *); - bool_t (*x_setpostn)(struct xinfo *, unsigned); - - /* Free the stream */ - void (*x_destroy)(struct xinfo *); - } * x_ops; - void *x_private; /* Pointer to private data */ } XDR; From b48e32d61f39c724443974701e2f8b0da8720d97 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 2 Feb 2024 22:37:01 -0800 Subject: [PATCH 26/52] Remove put/getint32 functions Replaced with xdr_int, which is 32-bits on all supported platforms --- mfhdf/libsrc/xdr.c | 49 ++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 71bcc56a31..fba92488d1 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -116,29 +116,6 @@ xdr_destroy(XDR *xdrs) xdrposix_destroy(xdrs); } -/* - * Utility functions for 32-bit ints - */ -static int -xdr_getint32(XDR *xdrs, int32_t *ip) -{ - long l; - - if (!xdr_getlong(xdrs, &l)) - return FALSE; - *ip = (int32_t)l; - return TRUE; -} - -static int -xdr_putint32(XDR *xdrs, int32_t *ip) -{ - long l; - - l = (long)*ip; - return xdr_putlong(xdrs, &l); -} - /* * XDR integers */ @@ -342,10 +319,10 @@ xdr_float(XDR *xdrs, float *fp) switch (xdrs->x_op) { case XDR_ENCODE: - return xdr_putint32(xdrs, (int32_t *)fp); + return xdr_int(xdrs, (int *)fp); case XDR_DECODE: - return xdr_getint32(xdrs, (int32_t *)fp); + return xdr_int(xdrs, (int *)fp); case XDR_FREE: return TRUE; @@ -356,7 +333,7 @@ xdr_float(XDR *xdrs, float *fp) bool_t xdr_double(XDR *xdrs, double *dp) { - int32_t *i32p; + int *ip; bool_t rv; if (!dp) @@ -364,33 +341,33 @@ xdr_double(XDR *xdrs, double *dp) switch (xdrs->x_op) { case XDR_ENCODE: - i32p = (int32_t *)(void *)dp; + ip = (int *)(void *)dp; #ifdef H4_WORDS_BIGENDIAN - rv = xdr_putint32(xdrs, i32p); + rv = xdr_int(xdrs, ip); if (!rv) return rv; - rv = xdr_putint32(xdrs, i32p + 1); + rv = xdr_int(xdrs, ip + 1); #else - rv = xdr_putint32(xdrs, i32p + 1); + rv = xdr_int(xdrs, ip + 1); if (!rv) return rv; - rv = xdr_putint32(xdrs, i32p); + rv = xdr_int(xdrs, ip); #endif return rv; break; case XDR_DECODE: - i32p = (int32_t *)(void *)dp; + ip = (int *)(void *)dp; #ifdef H4_WORDS_BIGENDIAN - rv = xdr_getint32(xdrs, i32p); + rv = xdr_int(xdrs, ip); if (!rv) return rv; - rv = xdr_getint32(xdrs, i32p + 1); + rv = xdr_int(xdrs, ip + 1); #else - rv = xdr_getint32(xdrs, i32p + 1); + rv = xdr_int(xdrs, ip + 1); if (!rv) return rv; - rv = xdr_getint32(xdrs, i32p); + rv = xdr_int(xdrs, ip); #endif return rv; break; From df7bb3b9994910ef7baee44e7fa745d80aa5f9de Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 00:23:57 -0800 Subject: [PATCH 27/52] Removed 64-bit XDR functions These were commented out some time ago --- mfhdf/libsrc/xdr.c | 62 ---------------------------------------------- 1 file changed, 62 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index fba92488d1..b70678f86a 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -379,68 +379,6 @@ xdr_double(XDR *xdrs, double *dp) return FALSE; } -/* XXX: Keep this code around in case it's needed when handling longs */ - -#if 0 -/* - * XDR 64-bit integers - */ -bool_t -xdr_int64_t(XDR *xdrs, int64_t *llp) -{ - u_long ul[2]; - - switch (xdrs->x_op) { - case XDR_ENCODE: - ul[0] = (u_long)((uint64_t)*llp >> 32) & 0xffffffff; - ul[1] = (u_long)((uint64_t)*llp) & 0xffffffff; - if (xdr_putlong(xdrs, (long *)&ul[0]) == FALSE) - return FALSE; - return (xdr_putlong(xdrs, (long *)&ul[1])); - case XDR_DECODE: - if (xdr_getlong(xdrs, (long *)&ul[0]) == FALSE) - return FALSE; - if (xdr_getlong(xdrs, (long *)&ul[1]) == FALSE) - return FALSE; - *llp = (int64_t)(((uint64_t)ul[0] << 32) | ((uint64_t)(ul[1]) & 0xffffffff)); - return TRUE; - case XDR_FREE: - return TRUE; - } - /* NOTREACHED */ - return FALSE; -} - -/* - * XDR unsigned 64-bit integers - */ -bool_t -xdr_uint64_t(XDR *xdrs, uint64_t *ullp) -{ - u_long ul[2]; - - switch (xdrs->x_op) { - case XDR_ENCODE: - ul[0] = (u_long)(*ullp >> 32) & 0xffffffff; - ul[1] = (u_long)(*ullp) & 0xffffffff; - if (xdr_putlong(xdrs, (long *)&ul[0]) == FALSE) - return (FALSE); - return (xdr_putlong(xdrs, (long *)&ul[1])); - case XDR_DECODE: - if (xdr_getlong(xdrs, (long *)&ul[0]) == FALSE) - return FALSE; - if (xdr_getlong(xdrs, (long *)&ul[1]) == FALSE) - return FALSE; - *ullp = (uint64_t)(((uint64_t)ul[0] << 32) | ((uint64_t)(ul[1]) & 0xffffffff)); - return TRUE; - case XDR_FREE: - return TRUE; - } - /* NOTREACHED */ - return FALSE; -} -#endif - /*********************/ /* FORMER xdrposix.c */ /*********************/ From 057c4c1bf4a99249f809e2712e95f8179c34e65a Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 00:32:20 -0800 Subject: [PATCH 28/52] Remove redundant xdr_get/putlong() --- mfhdf/libsrc/xdr.c | 28 ++++++++-------------------- mfhdf/libsrc/xdr.h | 3 --- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index b70678f86a..40340fc99c 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -74,18 +74,6 @@ static void xdrposix_destroy(XDR *xdrs); /* * Operations defined on an XDR handle */ -bool_t -xdr_getlong(XDR *xdrs, long *lp) -{ - return xdrposix_getlong(xdrs, lp); -} - -bool_t -xdr_putlong(XDR *xdrs, long *lp) -{ - return xdrposix_putlong(xdrs, lp); -} - bool_t xdr_getbytes(XDR *xdrs, char *addr, unsigned len) { @@ -128,10 +116,10 @@ xdr_int(XDR *xdrs, int *ip) case XDR_ENCODE: l = (long)*ip; - return xdr_putlong(xdrs, &l); + return xdrposix_putlong(xdrs, &l); case XDR_DECODE: - if (!xdr_getlong(xdrs, &l)) + if (!xdrposix_getlong(xdrs, &l)) return FALSE; *ip = (int)l; return TRUE; @@ -155,10 +143,10 @@ xdr_u_int(XDR *xdrs, unsigned *up) case XDR_ENCODE: l = (unsigned long)*up; - return xdr_putlong(xdrs, (long *)&l); + return xdrposix_putlong(xdrs, (long *)&l); case XDR_DECODE: - if (!xdr_getlong(xdrs, (long *)&l)) + if (!xdrposix_getlong(xdrs, (long *)&l)) return FALSE; *up = (unsigned)l; return TRUE; @@ -178,9 +166,9 @@ xdr_long(XDR *xdrs, long *lp) { switch (xdrs->x_op) { case XDR_ENCODE: - return xdr_putlong(xdrs, lp); + return xdrposix_putlong(xdrs, lp); case XDR_DECODE: - return xdr_getlong(xdrs, lp); + return xdrposix_getlong(xdrs, lp); case XDR_FREE: return TRUE; } @@ -196,9 +184,9 @@ xdr_u_long(XDR *xdrs, unsigned long *ulp) { switch (xdrs->x_op) { case XDR_ENCODE: - return xdr_putlong(xdrs, (long *)ulp); + return xdrposix_putlong(xdrs, (long *)ulp); case XDR_DECODE: - return xdr_getlong(xdrs, (long *)ulp); + return xdrposix_getlong(xdrs, (long *)ulp); case XDR_FREE: return TRUE; } diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 74d1255308..c5175433e9 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -74,9 +74,6 @@ extern "C" { /* * Operations defined on an XDR handle */ -HDFLIBAPI bool_t xdr_getlong(XDR *, long *); -HDFLIBAPI bool_t xdr_putlong(XDR *, long *); - HDFLIBAPI bool_t xdr_getbytes(XDR *, char *, unsigned); HDFLIBAPI bool_t xdr_putbytes(XDR *, const char *, unsigned); From 4e39b8bcb90d5a379685cb0fb25d0cb3aa6aea03 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 00:33:18 -0800 Subject: [PATCH 29/52] Ran formatter --- mfhdf/libsrc/xdr.c | 4 ++-- mfhdf/libsrc/xdr.h | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 40340fc99c..4b65a63769 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -321,8 +321,8 @@ xdr_float(XDR *xdrs, float *fp) bool_t xdr_double(XDR *xdrs, double *dp) { - int *ip; - bool_t rv; + int *ip; + bool_t rv; if (!dp) return FALSE; diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index c5175433e9..e86693f887 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -63,8 +63,8 @@ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; * private field for the use of the particular implementation. */ typedef struct xinfo { - enum xdr_op x_op; /* Operation */ - void *x_private; /* Pointer to private data */ + enum xdr_op x_op; /* Operation */ + void *x_private; /* Pointer to private data */ } XDR; #ifdef __cplusplus @@ -82,7 +82,6 @@ HDFLIBAPI bool_t xdr_setpos(XDR *, unsigned); HDFLIBAPI void xdr_destroy(XDR *); - /* * "Generic type" XDR routines */ From 7e90156676cdc9b05b60eed869b13f85f23e49b8 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 00:41:09 -0800 Subject: [PATCH 30/52] Add helpful comments --- mfhdf/libsrc/xdr.c | 10 ++++++++++ mfhdf/libsrc/xdr.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 4b65a63769..0299bb6d86 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -74,6 +74,10 @@ static void xdrposix_destroy(XDR *xdrs); /* * Operations defined on an XDR handle */ + +/* NOTE: These deal with raw bytes, not "counted bytes", like xdr_bytes() + * does, below! + */ bool_t xdr_getbytes(XDR *xdrs, char *addr, unsigned len) { @@ -86,6 +90,9 @@ xdr_putbytes(XDR *xdrs, const char *addr, unsigned len) return xdrposix_putbytes(xdrs, addr, len); } +/* + * Set/Get the file position + */ unsigned xdr_getpos(XDR *xdrs) { @@ -98,6 +105,9 @@ xdr_setpos(XDR *xdrs, unsigned pos) return xdrposix_setpos(xdrs, pos); } +/* + * Close the file + */ void xdr_destroy(XDR *xdrs) { diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index e86693f887..f300e093cc 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -71,6 +71,8 @@ typedef struct xinfo { extern "C" { #endif +/* NOTE! There are additional netCDF XDR ops scattered throughout the code! */ + /* * Operations defined on an XDR handle */ From 46986f4fd860091b0ee04e4fda9441ce03b517a8 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 15:22:03 -0800 Subject: [PATCH 31/52] Add check for size of long to configure/CMake So I can replace the hard-coded XDR platform ifdefs with something generic. --- config/cmake/h4config.h.in | 3 +++ configure.ac | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/config/cmake/h4config.h.in b/config/cmake/h4config.h.in index adac72820a..26c7dda2bc 100644 --- a/config/cmake/h4config.h.in +++ b/config/cmake/h4config.h.in @@ -177,6 +177,9 @@ /* Define to the version of this package. */ #define H4_PACKAGE_VERSION "@HDF4_PACKAGE_VERSION_STRING@" +/* The size of `long', as computed by sizeof. */ +#define H4_SIZEOF_LONG @H4_SIZEOF_LONG@ + /* Define to 1 if all of the C90 standard headers exist (not just the ones required in a freestanding environment). This macro is provided for backward compatibility; new code need not use it. */ diff --git a/configure.ac b/configure.ac index 978009727b..67c3292d66 100644 --- a/configure.ac +++ b/configure.ac @@ -870,6 +870,16 @@ AC_CHECK_HEADERS([sys/types.h]) AC_CHECK_HEADERS([io.h]) AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) +## ---------------------------------------------------------------------- +## XDR grew up in a world where long integers were 32 bits in size. Now +## that many platforms have 64-bit longs, we need some hacks to paper +## over the differences in sizes, particularly on big-endian machines. +## + +AC_CHECK_SIZEOF([long]) + +## ---------------------------------------------------------------------- + AC_PROG_CC_C_O if test "X$BUILD_FORTRAN" = "Xyes"; then From b40378cfb07181afe212cdab71e6b88e8e9b7eb6 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 16:47:17 -0800 Subject: [PATCH 32/52] Fix codespell issues --- mfhdf/libsrc/xdr_NOTICE.h | 2 +- mfhdf/libsrc/xdr_README | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mfhdf/libsrc/xdr_NOTICE.h b/mfhdf/libsrc/xdr_NOTICE.h index 28f3a43ab4..6f796c8a8c 100644 --- a/mfhdf/libsrc/xdr_NOTICE.h +++ b/mfhdf/libsrc/xdr_NOTICE.h @@ -7,7 +7,7 @@ * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE - * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR + * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the diff --git a/mfhdf/libsrc/xdr_README b/mfhdf/libsrc/xdr_README index 35bdcca975..758452eb78 100644 --- a/mfhdf/libsrc/xdr_README +++ b/mfhdf/libsrc/xdr_README @@ -7,7 +7,7 @@ Please read "NOTICE.h" This is the minimum subset of RPCSRC 3.9 needed to build the netcdf library. It is included here for those systems which lack xdr support. If your system already has these xdr routines, by all means use them. -Unix systems which suport the Network File System (NFS) usually have these +Unix systems which support the Network File System (NFS) usually have these routines in the 'c' library, /usr/lib/libc.a, so you don't need to link in any additional libraries. Another candididate is librpclib.a in /usr/lib or /usr/local/lib. From 1b5d7af59ecd0b2b278c96b9c2692fbeb46a333e Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 17:12:00 -0800 Subject: [PATCH 33/52] Update preprocessor directives --- mfhdf/libsrc/xdr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index b5aba6df0f..e9d96c01c3 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -627,10 +627,12 @@ xdrposix_getlong(XDR *xdrs, long *lp) { unsigned char *up = (unsigned char *)lp; -#if H4_SIZEOF_LONG > 4 && defined(H4_WORDS_BIGENDIAN) +#if defined(H4_WORDS_BIGENDIAN) +#if H4_SIZEOF_LONG > 4 /* Need to move the pointer on BE systems w/ 64-bit longs */ *lp = 0; up += (sizeof(long) - 4); +#endif #endif if (bioread((biobuf *)xdrs->x_private, up, 4) < 4) @@ -654,9 +656,11 @@ xdrposix_putlong(XDR *xdrs, const long *lp) up = (unsigned char *)&mycopy; #endif -#if H4_SIZEOF_LONG > 4 && defined(H4_WORDS_BIGENDIAN) +#if defined(H4_WORDS_BIGENDIAN) +#if H4_SIZEOF_LONG > 4 /* Need to move the pointer on BE systems w/ 64-bit longs */ up += (sizeof(long) - 4); +#endif #endif if (biowrite((biobuf *)xdrs->x_private, up, 4) < 4) From 3367a270857eb4ffd616bd11f457e26c289f0d1c Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 17:21:41 -0800 Subject: [PATCH 34/52] Add winsock2.h for htonl on Windows --- mfhdf/libsrc/xdr.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index e9d96c01c3..c5e12ba745 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -47,7 +47,10 @@ #include #endif #ifdef H4_HAVE_NETINET_IN_H -#include /* for htonl() */ +#include /* htonl() on POSIX */ +#endif +#ifdef H4_HAVE_WINSOCK2_H +#include /* htonl() on Win32 */ #endif #include "mfhdf.h" From 7ab4bc6764b259d2a4beb93f2ec6a510c08f1591 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 17:41:07 -0800 Subject: [PATCH 35/52] Update winsock defines for MinGW --- configure.ac | 11 +++++++++++ mfhdf/libsrc/xdr.c | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 67c3292d66..92e5924ae6 100644 --- a/configure.ac +++ b/configure.ac @@ -191,6 +191,14 @@ if test "X$host_config" != "Xnone"; then . $host_config fi +## Special MinGW checks +case "`uname`" in + MINGW*) + # Check for Winsock library + AC_CHECK_LIB([ws2_32]), [htonl]) + ;; +esac + ## ====================================================================== ## Checks for netCDF-2.3.2 support ## ====================================================================== @@ -870,6 +878,9 @@ AC_CHECK_HEADERS([sys/types.h]) AC_CHECK_HEADERS([io.h]) AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) +## MinGW (for htonl, etc.) +AC_CHECK_HEADERS([winsock2.h]) + ## ---------------------------------------------------------------------- ## XDR grew up in a world where long integers were 32 bits in size. Now ## that many platforms have 64-bit longs, we need some hacks to paper diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index c5e12ba745..0b53ba6f74 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -43,14 +43,17 @@ #include #include -#ifdef H4_HAVE_ARPA_INET_H -#include -#endif -#ifdef H4_HAVE_NETINET_IN_H -#include /* htonl() on POSIX */ -#endif -#ifdef H4_HAVE_WINSOCK2_H -#include /* htonl() on Win32 */ +#ifdef H4_HAVE_WIN32_API +# ifdef H4_HAVE_WINSOCK2_H +# include /* htonl() on Win32 */ +# endif +#else +# ifdef H4_HAVE_ARPA_INET_H +# include +# endif +# ifdef H4_HAVE_NETINET_IN_H +# include /* htonl() on POSIX */ +# endif #endif #include "mfhdf.h" From 3a08966e2ace16c38185897104d5965a7b9943aa Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 4 Feb 2024 01:42:06 +0000 Subject: [PATCH 36/52] Committing clang-format changes --- mfhdf/libsrc/xdr.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 0b53ba6f74..cdef2e30a7 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -44,16 +44,16 @@ #include #ifdef H4_HAVE_WIN32_API -# ifdef H4_HAVE_WINSOCK2_H -# include /* htonl() on Win32 */ -# endif +#ifdef H4_HAVE_WINSOCK2_H +#include /* htonl() on Win32 */ +#endif #else -# ifdef H4_HAVE_ARPA_INET_H -# include -# endif -# ifdef H4_HAVE_NETINET_IN_H -# include /* htonl() on POSIX */ -# endif +#ifdef H4_HAVE_ARPA_INET_H +#include +#endif +#ifdef H4_HAVE_NETINET_IN_H +#include /* htonl() on POSIX */ +#endif #endif #include "mfhdf.h" From 26a55f23169a1071cc1b0c49dcaa485bafd33e2d Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 17:45:03 -0800 Subject: [PATCH 37/52] Add htonl comments --- mfhdf/libsrc/xdr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index cdef2e30a7..df5e1c17ad 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -43,16 +43,20 @@ #include #include +/* Which header files include htonl() ? */ + #ifdef H4_HAVE_WIN32_API #ifdef H4_HAVE_WINSOCK2_H -#include /* htonl() on Win32 */ +/* Use winsock on Win32 (including MinGW) */ +#include #endif #else +/* And normal network headers everywhere else */ #ifdef H4_HAVE_ARPA_INET_H #include #endif #ifdef H4_HAVE_NETINET_IN_H -#include /* htonl() on POSIX */ +#include #endif #endif From 5b488db5e192193351ab27e98d77b63f4077a4c1 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 18:01:18 -0800 Subject: [PATCH 38/52] Clean up htonl, etc. build functionality --- config/cmake/ConfigureChecks.cmake | 11 +--------- configure.ac | 32 ++++++++---------------------- mfhdf/libsrc/xdr.c | 5 ----- 3 files changed, 9 insertions(+), 39 deletions(-) diff --git a/config/cmake/ConfigureChecks.cmake b/config/cmake/ConfigureChecks.cmake index 70586cd453..7146b57aa4 100644 --- a/config/cmake/ConfigureChecks.cmake +++ b/config/cmake/ConfigureChecks.cmake @@ -451,17 +451,8 @@ CHECK_FUNCTION_EXISTS (asprintf ${HDF_PREFIX}_HAVE_ASPRINTF) CHECK_FUNCTION_EXISTS (vasprintf ${HDF_PREFIX}_HAVE_VASPRINTF) CHECK_FUNCTION_EXISTS (waitpid ${HDF_PREFIX}_HAVE_WAITPID) -if (NOT WINDOWS) - CHECK_FUNCTION_EXISTS (ntohl ${HDF_PREFIX}_HAVE_NTOHL) - CHECK_FUNCTION_EXISTS (htonl ${HDF_PREFIX}_HAVE_HTONL) - CHECK_FUNCTION_EXISTS (ntohs ${HDF_PREFIX}_HAVE_NTOHS) - CHECK_FUNCTION_EXISTS (htons ${HDF_PREFIX}_HAVE_HTONS) -else () +if (WINDOWS) set (CMAKE_REQUIRED_LIBRARIES "ws2_32") - check_symbol_exists (ntohl "winsock2.h" ${HDF_PREFIX}_HAVE_NTOHL) - check_symbol_exists (htonl "winsock2.h" ${HDF_PREFIX}_HAVE_HTONL) - check_symbol_exists (ntohs "winsock2.h" ${HDF_PREFIX}_HAVE_NTOHS) - check_symbol_exists (htons "winsock2.h" ${HDF_PREFIX}_HAVE_HTONS) endif () #----------------------------------------------------------------------------- diff --git a/configure.ac b/configure.ac index 92e5924ae6..98580e07f1 100644 --- a/configure.ac +++ b/configure.ac @@ -191,14 +191,6 @@ if test "X$host_config" != "Xnone"; then . $host_config fi -## Special MinGW checks -case "`uname`" in - MINGW*) - # Check for Winsock library - AC_CHECK_LIB([ws2_32]), [htonl]) - ;; -esac - ## ====================================================================== ## Checks for netCDF-2.3.2 support ## ====================================================================== @@ -854,19 +846,6 @@ AM_CONDITIONAL([BUILD_SHARED_SZIP_CONDITIONAL], [test "X$USE_COMP_SZIP" = "Xyes" ## http://www.gnu.org/s/libc/manual/html_node/Feature-Test-Macros.html CPPFLAGS="-D_POSIX_C_SOURCE=200809L $CPPFLAGS" -## ====================================================================== -## Checks for endianness functions -## The htons and ntohs functions are available on most systems. -## These functions convert betweennetwork endiannessand hostendianness. -## Network endianness is big-endian; because the standard TCP/IP network -## protocols use big-endian ordering. These functions come in two sizes: -## htonl and ntohl operate on 4-byte quantities, and -## htons and ntohs operate on 2-byte quantities. -## The hton functions convert host endianness to network endianness. -## The ntoh functions convert network endianness to host endianness -## ====================================================================== -AC_CHECK_FUNCS([htonl htons ntohl ntohs]) - ## ====================================================================== ## Checks for headers ## ====================================================================== @@ -876,10 +855,15 @@ AC_CHECK_HEADERS([sys/file.h sys/resource.h sys/stat.h sys/time.h sys/wait.h]) AC_CHECK_HEADERS([sys/types.h]) AC_CHECK_HEADERS([io.h]) -AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) +AC_CHECK_HEADERS([arpa/inet.h]) -## MinGW (for htonl, etc.) -AC_CHECK_HEADERS([winsock2.h]) +## Special MinGW checks +case "`uname`" in + MINGW*) + # Check for Winsock library + AC_CHECK_LIB([ws2_32], [htonl]) + ;; +esac ## ---------------------------------------------------------------------- ## XDR grew up in a world where long integers were 32 bits in size. Now diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index df5e1c17ad..a90c19170e 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -46,18 +46,13 @@ /* Which header files include htonl() ? */ #ifdef H4_HAVE_WIN32_API -#ifdef H4_HAVE_WINSOCK2_H /* Use winsock on Win32 (including MinGW) */ #include -#endif #else /* And normal network headers everywhere else */ #ifdef H4_HAVE_ARPA_INET_H #include #endif -#ifdef H4_HAVE_NETINET_IN_H -#include -#endif #endif #include "mfhdf.h" From 03517051aa53a2c0cb17d6f3842bed52a7797997 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 18:14:49 -0800 Subject: [PATCH 39/52] Tweak to CMake Windows network libraries --- config/cmake/ConfigureChecks.cmake | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/config/cmake/ConfigureChecks.cmake b/config/cmake/ConfigureChecks.cmake index 7146b57aa4..2b614ea05c 100644 --- a/config/cmake/ConfigureChecks.cmake +++ b/config/cmake/ConfigureChecks.cmake @@ -41,7 +41,7 @@ macro (CHECK_LIBRARY_EXISTS_CONCAT LIBRARY SYMBOL VARIABLE) endmacro () # ---------------------------------------------------------------------- -# WINDOWS Hard code Values +# WINDOWS hard-coded values # ---------------------------------------------------------------------- set (WINDOWS) @@ -85,7 +85,7 @@ if (WINDOWS) endif () # ---------------------------------------------------------------------- -# END of WINDOWS Hard code Values +# END of WINDOWS hard-coded values # ---------------------------------------------------------------------- if (NOT WINDOWS) @@ -451,10 +451,6 @@ CHECK_FUNCTION_EXISTS (asprintf ${HDF_PREFIX}_HAVE_ASPRINTF) CHECK_FUNCTION_EXISTS (vasprintf ${HDF_PREFIX}_HAVE_VASPRINTF) CHECK_FUNCTION_EXISTS (waitpid ${HDF_PREFIX}_HAVE_WAITPID) -if (WINDOWS) - set (CMAKE_REQUIRED_LIBRARIES "ws2_32") -endif () - #----------------------------------------------------------------------------- # Check how to print a Long Long integer #----------------------------------------------------------------------------- From 240f8c17743b6525235b4d361ace793b7d15b06a Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 18:33:08 -0800 Subject: [PATCH 40/52] HDF4 --> CMAKE_REQUIRED_LIBRARIES --- config/cmake/ConfigureChecks.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cmake/ConfigureChecks.cmake b/config/cmake/ConfigureChecks.cmake index 2b614ea05c..9cb997d00a 100644 --- a/config/cmake/ConfigureChecks.cmake +++ b/config/cmake/ConfigureChecks.cmake @@ -64,7 +64,7 @@ if (WIN32 AND NOT MINGW) endif () if (WINDOWS) - set (HDF4_REQUIRED_LIBRARIES "ws2_32.lib;wsock32.lib") + set (CMAKE_REQUIRED_LIBRARIES "ws2_32.lib;wsock32.lib") set (${HDF_PREFIX}_HAVE_WIN32_API 1) set (${HDF_PREFIX}_HAVE_LIBM 1) set (${HDF_PREFIX}_HAVE_STRDUP 1) From 07ae856842483f8baf04847a151e9c17f8e69dd7 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 18:40:22 -0800 Subject: [PATCH 41/52] Restore missing target_link_libraries --- mfhdf/libsrc/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mfhdf/libsrc/CMakeLists.txt b/mfhdf/libsrc/CMakeLists.txt index 57fec3acfb..2d8bde9b51 100644 --- a/mfhdf/libsrc/CMakeLists.txt +++ b/mfhdf/libsrc/CMakeLists.txt @@ -70,6 +70,7 @@ if (NOT ONLY_SHARED_LIBS) ${HDF_EXTRA_FLAGS} ) TARGET_C_PROPERTIES (${HDF4_MF_LIB_TARGET} STATIC) + target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC "$<$,$>:ws2_32.lib>") target_link_libraries (${HDF4_MF_LIB_TARGET} PUBLIC ${HDF4_SRC_LIB_TARGET}) set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_LIB_TARGET}") H4_SET_LIB_OPTIONS (${HDF4_MF_LIB_TARGET} ${HDF4_MF_LIB_NAME} STATIC) @@ -94,6 +95,7 @@ if (BUILD_SHARED_LIBS) ${HDF_EXTRA_FLAGS} ) TARGET_C_PROPERTIES (${HDF4_MF_LIBSH_TARGET} SHARED) + target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC "$<$,$>:ws2_32.lib>") target_link_libraries (${HDF4_MF_LIBSH_TARGET} PUBLIC ${HDF4_SRC_LIBSH_TARGET}) set_global_variable (HDF4_LIBRARIES_TO_EXPORT "${HDF4_LIBRARIES_TO_EXPORT};${HDF4_MF_LIBSH_TARGET}") H4_SET_LIB_OPTIONS (${HDF4_MF_LIBSH_TARGET} ${HDF4_MF_LIB_NAME} SHARED) From a9a954a6795c287b23018fdc3d2dfe823080d4d6 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 18:57:13 -0800 Subject: [PATCH 42/52] Restore netinet/in.h --- config/cmake/h4config.h.in | 12 ------------ configure.ac | 2 +- mfhdf/libsrc/xdr.c | 3 +++ 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/config/cmake/h4config.h.in b/config/cmake/h4config.h.in index 26c7dda2bc..2207a3bd70 100644 --- a/config/cmake/h4config.h.in +++ b/config/cmake/h4config.h.in @@ -41,12 +41,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine H4_HAVE_WINSOCK2_H @H4_HAVE_WINSOCK2_H@ -/* Define to 1 if you have the `htonl' function. */ -#cmakedefine H4_HAVE_HTONL @H4_HAVE_HTONL@ - -/* Define to 1 if you have the `htons' function. */ -#cmakedefine H4_HAVE_HTONS @H4_HAVE_HTONS@ - /* Define to 1 if you have the header file. */ #cmakedefine H4_HAVE_INTTYPES_H @H4_HAVE_INTTYPES_H@ @@ -77,12 +71,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine H4_HAVE_NETINET_IN_H @H4_HAVE_NETINET_IN_H@ -/* Define to 1 if you have the `ntohl' function. */ -#cmakedefine H4_HAVE_NTOHL @H4_HAVE_NTOHL@ - -/* Define to 1 if you have the `ntohs' function. */ -#cmakedefine H4_HAVE_NTOHS @H4_HAVE_NTOHS@ - /* Define to 1 if you have the header file. */ #cmakedefine H4_HAVE_RESOLV_H @H4_HAVE_RESOLV_H@ diff --git a/configure.ac b/configure.ac index 98580e07f1..9e69ab88e3 100644 --- a/configure.ac +++ b/configure.ac @@ -855,7 +855,7 @@ AC_CHECK_HEADERS([sys/file.h sys/resource.h sys/stat.h sys/time.h sys/wait.h]) AC_CHECK_HEADERS([sys/types.h]) AC_CHECK_HEADERS([io.h]) -AC_CHECK_HEADERS([arpa/inet.h]) +AC_CHECK_HEADERS([arpa/inet.h netinet/in.h]) ## Special MinGW checks case "`uname`" in diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index a90c19170e..590e1385ee 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -53,6 +53,9 @@ #ifdef H4_HAVE_ARPA_INET_H #include #endif +#ifdef H4_HAVE_NETINET_IN_H +#include /* for htonl() */ +#endif #endif #include "mfhdf.h" From 4da9e6ea01247dbd58028c155b19ca8119f4cda0 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 23:34:41 -0800 Subject: [PATCH 43/52] Refactoring and commenting --- mfhdf/libsrc/cdf.c | 4 +- mfhdf/libsrc/file.c | 4 +- mfhdf/libsrc/local_nc.h | 3 - mfhdf/libsrc/xdr.c | 447 ++++++++++++++++++++++------------------ mfhdf/libsrc/xdr.h | 54 +++-- 5 files changed, 293 insertions(+), 219 deletions(-) diff --git a/mfhdf/libsrc/cdf.c b/mfhdf/libsrc/cdf.c index 6579b59c4a..59e228fbbd 100644 --- a/mfhdf/libsrc/cdf.c +++ b/mfhdf/libsrc/cdf.c @@ -282,7 +282,7 @@ NC_new_cdf(const char *name, int mode) */ switch (cdf->file_type) { case HDF_FILE: - hdf_xdrfile_create(cdf->xdrs, mode); /* return type is 'void' */ + xdr_setup_nofile(cdf->xdrs, mode); /* return type is 'void' */ break; case netCDF_FILE: if (NCxdrfile_create(cdf->xdrs, name, mode) < 0) @@ -291,7 +291,7 @@ NC_new_cdf(const char *name, int mode) case CDF_FILE: /* CDF_xdrfile_create(); */ /* try this, I bet it will be sufficient */ - hdf_xdrfile_create(cdf->xdrs, mode); + xdr_setup_nofile(cdf->xdrs, mode); break; } diff --git a/mfhdf/libsrc/file.c b/mfhdf/libsrc/file.c index c5589e2852..36288efbf0 100644 --- a/mfhdf/libsrc/file.c +++ b/mfhdf/libsrc/file.c @@ -1034,7 +1034,7 @@ ncsetfill(int id, int fillmode) int NCxdrfile_sync(XDR *xdrs) { - return xdrposix_sync(xdrs); + return xdr_sync(xdrs); } int @@ -1080,7 +1080,7 @@ NCxdrfile_create(XDR *xdrs, const char *path, int ncmode) op = XDR_DECODE; } - if (xdrposix_create(xdrs, fd, fmode, op) < 0) + if (xdr_create(xdrs, fd, fmode, op) < 0) return -1; else return fd; diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index 3acc8b176b..fbb0adcf1e 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -476,9 +476,6 @@ HDFLIBAPI int NCxdrfile_sync(XDR *xdrs); HDFLIBAPI int NCxdrfile_create(XDR *xdrs, const char *path, int ncmode); #ifdef HDF -/* this routine is found in 'xdrposix.c' */ -HDFLIBAPI void hdf_xdrfile_create(XDR *xdrs, int ncop); - HDFLIBAPI intn hdf_fill_array(Void *storage, int32 len, Void *value, int32 type); HDFLIBAPI intn hdf_get_data(NC *handle, NC_var *vp); diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 590e1385ee..157898224e 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -71,56 +71,18 @@ */ static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0}; -static bool_t xdrposix_getlong(XDR *xdrs, long *lp); -static bool_t xdrposix_putlong(XDR *xdrs, const long *lp); -static bool_t xdrposix_getbytes(XDR *xdrs, char *addr, unsigned len); -static bool_t xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len); -static unsigned xdrposix_getpos(XDR *xdrs); -static bool_t xdrposix_setpos(XDR *xdrs, unsigned pos); -static void xdrposix_destroy(XDR *xdrs); +/* Forward declarations */ +static bool_t xdr_getlong(XDR *xdrs, long *lp); +static bool_t xdr_putlong(XDR *xdrs, const long *lp); -/* - * Operations defined on an XDR handle - */ - -/* NOTE: These deal with raw bytes, not "counted bytes", like xdr_bytes() - * does, below! - */ -bool_t -xdr_getbytes(XDR *xdrs, char *addr, unsigned len) -{ - return xdrposix_getbytes(xdrs, addr, len); -} +/******************/ +/* XDR Type Calls */ +/******************/ -bool_t -xdr_putbytes(XDR *xdrs, const char *addr, unsigned len) -{ - return xdrposix_putbytes(xdrs, addr, len); -} - -/* - * Set/Get the file position +/* These per-type API calls encode/decode/free depending on the op field + * in the XDR struct. They use the lower-level XDR calls found after the + * I/O buffering code, below. */ -unsigned -xdr_getpos(XDR *xdrs) -{ - return xdrposix_getpos(xdrs); -} - -bool_t -xdr_setpos(XDR *xdrs, unsigned pos) -{ - return xdrposix_setpos(xdrs, pos); -} - -/* - * Close the file - */ -void -xdr_destroy(XDR *xdrs) -{ - xdrposix_destroy(xdrs); -} /* * XDR integers @@ -134,10 +96,10 @@ xdr_int(XDR *xdrs, int *ip) case XDR_ENCODE: l = (long)*ip; - return xdrposix_putlong(xdrs, &l); + return xdr_putlong(xdrs, &l); case XDR_DECODE: - if (!xdrposix_getlong(xdrs, &l)) + if (!xdr_getlong(xdrs, &l)) return FALSE; *ip = (int)l; return TRUE; @@ -161,10 +123,10 @@ xdr_u_int(XDR *xdrs, unsigned *up) case XDR_ENCODE: l = (unsigned long)*up; - return xdrposix_putlong(xdrs, (long *)&l); + return xdr_putlong(xdrs, (long *)&l); case XDR_DECODE: - if (!xdrposix_getlong(xdrs, (long *)&l)) + if (!xdr_getlong(xdrs, (long *)&l)) return FALSE; *up = (unsigned)l; return TRUE; @@ -184,9 +146,9 @@ xdr_long(XDR *xdrs, long *lp) { switch (xdrs->x_op) { case XDR_ENCODE: - return xdrposix_putlong(xdrs, lp); + return xdr_putlong(xdrs, lp); case XDR_DECODE: - return xdrposix_getlong(xdrs, lp); + return xdr_getlong(xdrs, lp); case XDR_FREE: return TRUE; } @@ -202,9 +164,9 @@ xdr_u_long(XDR *xdrs, unsigned long *ulp) { switch (xdrs->x_op) { case XDR_ENCODE: - return xdrposix_putlong(xdrs, (long *)ulp); + return xdr_putlong(xdrs, (long *)ulp); case XDR_DECODE: - return xdrposix_getlong(xdrs, (long *)ulp); + return xdr_getlong(xdrs, (long *)ulp); case XDR_FREE: return TRUE; } @@ -214,6 +176,7 @@ xdr_u_long(XDR *xdrs, unsigned long *ulp) /* * XDR opaque data + * * Allows the specification of a fixed size sequence of opaque bytes. * cp points to the opaque object and cnt gives the byte length. */ @@ -260,6 +223,12 @@ xdr_opaque(XDR *xdrs, char *cp, unsigned cnt) /* * XDR counted bytes + * + * This is a special data structure that starts with the size, followed + * by the raw bytes (as an opaque XDR type). + * + * For raw, uninterpreted byte I/O, see the xdr_put/getbytes() calls. + * * *cpp is a pointer to the bytes, *sizep is the count. * If *cpp is NULL maxsize bytes are allocated */ @@ -319,6 +288,9 @@ xdr_bytes(XDR *xdrs, char **cpp, unsigned *sizep, unsigned maxsize) return FALSE; } +/* + * XDR 4-byte floats + */ bool_t xdr_float(XDR *xdrs, float *fp) { @@ -336,6 +308,12 @@ xdr_float(XDR *xdrs, float *fp) return FALSE; } +/* + * XDR 8-byte doubles + * + * Performed in two 32-bit operations because XDR does not have a 64-bit + * I/O operation. + */ bool_t xdr_double(XDR *xdrs, double *dp) { @@ -385,69 +363,100 @@ xdr_double(XDR *xdrs, double *dp) return FALSE; } -/*********************/ -/* FORMER xdrposix.c */ -/*********************/ - -/* NOTE: "bio" == Buffered I/O */ - -typedef struct { - int fd; /* the file descriptor */ - int mode; /* file access mode, O_RDONLY, etc */ - int isdirty; - off_t page; - int nread; /* number of bytes successfully read */ - int nwrote; /* number of bytes last write */ - int cnt; /* number of valid bytes in buffer */ - unsigned char *ptr; /* next byte */ +/****************************/ +/* I/O Buffer Functionality */ +/****************************/ + +/* As an optimization, the XDR I/O layer uses a single I/O buffer to + * speed up nearby reads and writes ("bio" == Buffered I/O). + * + * TODO: This is not a very big cache! Bumping it might enhance I/O + * performance. + */ + +/* Size of the I/O buffer in bytes */ #define BIOBUFSIZ 8192 - unsigned char base[BIOBUFSIZ]; /* the data buffer */ + +/* # of valid bytes in the buffer */ +#define CNT(p) ((p)->ptr - (p)->base) + +/* # of unread bytes in buffer */ +#define REM(p) ((p)->cnt - CNT(p)) + +/* Available space for write in buffer */ +#define BREM(p) (BIOBUFSIZ - CNT(p)) + +/* POSIX and I/O buffer info + * + * Stored in the XDR struct's private data + * + * NOTE: off_t is 32-bits on Windows, but that shouldn't be a problem since + * HDF4 files are limited to 4 GB. + */ +typedef struct biobuf { + int fd; /* POSIX file descriptor */ + int mode; /* File access mode, O_RDONLY, etc */ + int isdirty; /* Dirty buffer flag */ + off_t page; /* Location in the file */ + int nread; /* Number of bytes successfully read */ + int nwrote; /* Number of bytes last written */ + int cnt; /* Number of valid bytes in buffer */ + uint8_t *ptr; /* Next byte (pointer into base) */ + uint8_t base[BIOBUFSIZ]; /* Data buffer */ } biobuf; +/* + * Initialize the POSIX/buffer XDR state + */ static biobuf * -new_biobuf(int fd, int fmode) +bio_get_new(int fd, int fmode) { biobuf *biop = NULL; - if (NULL == (biop = malloc(sizeof(biobuf)))) + if (NULL == (biop = (biobuf *)calloc(1, sizeof(biobuf)))) return NULL; - biop->fd = fd; + biop->fd = fd; biop->mode = fmode; - - biop->isdirty = 0; - biop->page = 0; - biop->nread = 0; - biop->nwrote = 0; - biop->cnt = 0; - memset(biop->base, 0, ((size_t)(BIOBUFSIZ))); - biop->ptr = biop->base; + biop->ptr = biop->base; return biop; } +/* + * Read a page from the file into the buffer + */ static int -rdbuf(biobuf *biop) +bio_read_page(biobuf *biop) { - memset(biop->base, 0, ((size_t)(BIOBUFSIZ))); + /* Clear out the buffer */ + memset(biop->base, 0, BIOBUFSIZ); if (biop->mode & O_WRONLY) { + /* If we're only writing, the buffer is empty */ biop->cnt = 0; } else { if (biop->nwrote != BIOBUFSIZ) { - /* last write wasn't a full block, adjust position ahead */ + /* Last write wasn't a full block, adjust position ahead */ if (lseek(biop->fd, biop->page * BIOBUFSIZ, SEEK_SET) == ((off_t)-1)) return -1; } + + /* Read from storage into the buffer */ biop->nread = biop->cnt = read(biop->fd, (void *)biop->base, BIOBUFSIZ); } + biop->ptr = biop->base; + return biop->cnt; } +/* + * Write a page from the buffer to the file + */ static int -wrbuf(biobuf *biop) +bio_write_page(biobuf *biop) { if (!((biop->mode & O_WRONLY) || (biop->mode & O_RDWR)) || biop->cnt == 0) { @@ -455,7 +464,7 @@ wrbuf(biobuf *biop) } else { if (biop->nread != 0) { - /* if we read something, we have to adjust position back */ + /* If we read something, we have to adjust position back */ if (lseek(biop->fd, biop->page * BIOBUFSIZ, SEEK_SET) == ((off_t)-1)) return -1; } @@ -466,33 +475,34 @@ wrbuf(biobuf *biop) return biop->nwrote; } +/* + * Get the next page from the file + * + * Returns the number of valid bytes in the buffer + */ static int -nextbuf(biobuf *biop) +bio_get_next_page(biobuf *biop) { + /* Flush if dirty */ if (biop->isdirty) { - if (wrbuf(biop) < 0) + if (bio_write_page(biop) < 0) return -1; } biop->page++; - /* read it in */ - if (rdbuf(biop) < 0) + /* Read in the next page */ + if (bio_read_page(biop) < 0) return -1; return biop->cnt; } -#define CNT(p) ((p)->ptr - (p)->base) - -/* # of unread bytes in buffer */ -#define REM(p) ((p)->cnt - CNT(p)) - -/* available space for write in buffer */ -#define BREM(p) (BIOBUFSIZ - CNT(p)) - +/* + * Read bytes from the file through the buffer + */ static int -bioread(biobuf *biop, unsigned char *ptr, int nbytes) +bio_read(biobuf *biop, unsigned char *ptr, int nbytes) { int ngot = 0; size_t rem; @@ -507,18 +517,22 @@ bioread(biobuf *biop, unsigned char *ptr, int nbytes) nbytes -= rem; ngot += rem; } - if (nextbuf(biop) <= 0) + if (bio_get_next_page(biop) <= 0) return ngot; } - /* we know nbytes <= REM at this point */ + + /* We know nbytes <= REM at this point */ (void)memcpy(ptr, biop->ptr, (size_t)nbytes); biop->ptr += nbytes; ngot += nbytes; return ngot; } +/* + * Write bytes to the file through the buffer + */ static int -biowrite(biobuf *biop, unsigned char *ptr, int nbytes) +bio_write(biobuf *biop, unsigned char *ptr, int nbytes) { size_t rem; int nwrote = 0; @@ -536,10 +550,11 @@ biowrite(biobuf *biop, unsigned char *ptr, int nbytes) nbytes -= rem; nwrote += rem; } - if (nextbuf(biop) < 0) + if (bio_get_next_page(biop) < 0) return nwrote; } - /* we know nbytes <= BREM at this point */ + + /* We know nbytes <= BREM at this point */ (void)memcpy(biop->ptr, ptr, (size_t)nbytes); biop->isdirty = !0; biop->ptr += nbytes; @@ -550,88 +565,25 @@ biowrite(biobuf *biop, unsigned char *ptr, int nbytes) return nwrote; } -/* - * Fake an XDR initialization for HDF files - */ -void -hdf_xdrfile_create(XDR *xdrs, int ncop) -{ - biobuf *biop = new_biobuf(-1, 0); - - if (ncop & NC_CREAT) - xdrs->x_op = XDR_ENCODE; - else - xdrs->x_op = XDR_DECODE; - - xdrs->x_private = (char *)biop; - -} /* hdf_xdrfile_create */ - -/* - * Initialize a posix xdr stream. - * Sets the xdr stream handle xdrs for use on the file descriptor fd. - * Operation flag is set to op. - */ -int -xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) -{ - biobuf *biop = new_biobuf(fd, fmode); - xdrs->x_op = op; - xdrs->x_private = (char *)biop; - if (biop == NULL) - return -1; - - /* if write only, or just created (empty), done */ - if ((biop->mode & O_WRONLY) || (biop->mode & O_CREAT)) - return 0; - - /* else, read the first bufferful */ - return rdbuf(biop); -} - -/* - * "sync" a posix xdr stream. - */ -int -xdrposix_sync(XDR *xdrs) -{ - biobuf *biop = (biobuf *)xdrs->x_private; - if (biop->isdirty) { - /* flush */ - if (wrbuf(biop) < 0) - return -1; - } - - biop->nwrote = 0; /* force seek in rdbuf */ - - /* read it in */ - if (rdbuf(biop) < 0) - return -1; - - return biop->cnt; -} +/***********************/ +/* Low-Level XDR Calls */ +/***********************/ /* - * Destroy a posix xdr stream. - * Cleans up the xdr stream handle xdrs previously set up by xdrposix_create. + * Read/write the number of bytes in a C long to the XDR file. 'long' is + * being used in the sense of 'n bytes' and not a long integer value. + * + * This obviously depends on the number of bytes in a long, which is 8 on most + * POSIX systems and 4 on Windows. + * + * XDR grew up at a time when all longs were 4 bytes, so we have to awkwardly + * hack around 32/64 and BE/LE differences in this call. Essentially, anything + * over (2^32 - 1) will be silently truncated. The 64-bit BE hack is to ensure + * we clip the bits that represent values > (2^32 - 1). */ -static void -xdrposix_destroy(XDR *xdrs) -{ - /* flush */ - biobuf *biop = (biobuf *)xdrs->x_private; - if (biop != NULL) { - if (biop->isdirty) { - (void)wrbuf(biop); - } - if (biop->fd != -1) - (void)close(biop->fd); - free(biop); - } -} static bool_t -xdrposix_getlong(XDR *xdrs, long *lp) +xdr_getlong(XDR *xdrs, long *lp) { unsigned char *up = (unsigned char *)lp; @@ -643,7 +595,7 @@ xdrposix_getlong(XDR *xdrs, long *lp) #endif #endif - if (bioread((biobuf *)xdrs->x_private, up, 4) < 4) + if (bio_read((biobuf *)xdrs->x_private, up, 4) < 4) return FALSE; #ifndef H4_WORDS_BIGENDIAN @@ -654,7 +606,7 @@ xdrposix_getlong(XDR *xdrs, long *lp) } static bool_t -xdrposix_putlong(XDR *xdrs, const long *lp) +xdr_putlong(XDR *xdrs, const long *lp) { unsigned char *up = (unsigned char *)lp; @@ -671,36 +623,46 @@ xdrposix_putlong(XDR *xdrs, const long *lp) #endif #endif - if (biowrite((biobuf *)xdrs->x_private, up, 4) < 4) + if (bio_write((biobuf *)xdrs->x_private, up, 4) < 4) return FALSE; return TRUE; } -static bool_t -xdrposix_getbytes(XDR *xdrs, char *addr, unsigned len) +/* + * Read/Write a bunch of bytes to/from an XDR file + * + * NOTE: These deal with raw bytes, not "counted bytes", like xdr_bytes() does! + */ + +bool_t +xdr_getbytes(XDR *xdrs, char *addr, unsigned len) { - if ((len != 0) && (bioread((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) + if ((len != 0) && (bio_read((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) return FALSE; return TRUE; } -static bool_t -xdrposix_putbytes(XDR *xdrs, const char *addr, unsigned len) +bool_t +xdr_putbytes(XDR *xdrs, const char *addr, unsigned len) { - if ((len != 0) && (biowrite((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) + if ((len != 0) && (bio_write((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) return FALSE; return TRUE; } -static unsigned -xdrposix_getpos(XDR *xdrs) +/* + * Get/set the position in an XDR file. Goes through the I/O buffer. + */ + +unsigned +xdr_getpos(XDR *xdrs) { biobuf *biop = (biobuf *)xdrs->x_private; return BIOBUFSIZ * biop->page + CNT(biop); } -static bool_t -xdrposix_setpos(XDR *xdrs, unsigned pos) +bool_t +xdr_setpos(XDR *xdrs, unsigned pos) { biobuf *biop = (biobuf *)xdrs->x_private; if (biop != NULL) { @@ -711,15 +673,15 @@ xdrposix_setpos(XDR *xdrs, unsigned pos) index = pos % BIOBUFSIZ; if (page != biop->page) { if (biop->isdirty) { - if (wrbuf(biop) < 0) + if (bio_write_page(biop) < 0) return FALSE; } if (page != biop->page + 1) - biop->nwrote = 0; /* force seek in rdbuf */ + biop->nwrote = 0; /* force seek in bio_read_page */ biop->page = page; - nread = rdbuf(biop); + nread = bio_read_page(biop); if (nread < 0 || ((biop->mode & O_RDONLY) && nread < index)) return FALSE; } @@ -729,3 +691,92 @@ xdrposix_setpos(XDR *xdrs, unsigned pos) else return FALSE; } + +/************************/ +/* XDR File State Calls */ +/************************/ + +/* + * Set up the I/O buffer in the passed-in XDR struct + * + * This is used in the netCDF code, which has a different way of setting + * up the file. + */ +void +xdr_setup_nofile(XDR *xdrs, int ncop) +{ + biobuf *biop = bio_get_new(-1, 0); + + if (ncop & NC_CREAT) + xdrs->x_op = XDR_ENCODE; + else + xdrs->x_op = XDR_DECODE; + + xdrs->x_private = biop; +} + +/* + * Initialize a POSIX XDR file + * + * Sets up XDR to use the POSIX file descriptor fd + * + * Operation flag is initialized to op + */ +int +xdr_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) +{ + biobuf *biop = bio_get_new(fd, fmode); + xdrs->x_op = op; + xdrs->x_private = (char *)biop; + if (biop == NULL) + return -1; + + /* If write only, or just created (empty), done */ + if ((biop->mode & O_WRONLY) || (biop->mode & O_CREAT)) + return 0; + + /* Else, read the first bufferful */ + return bio_read_page(biop); +} + +/* + * Flush the I/O buffer to the file + */ +int +xdr_sync(XDR *xdrs) +{ + biobuf *biop = (biobuf *)xdrs->x_private; + if (biop->isdirty) { + /* Flush */ + if (bio_write_page(biop) < 0) + return -1; + } + + biop->nwrote = 0; /* Force seek in bio_read_page */ + + /* Read it in */ + if (bio_read_page(biop) < 0) + return -1; + + return biop->cnt; +} + +/* + * Destroy a POSIX XDR stream + * + * Cleans up after xdrposix_create() + */ +void +xdr_destroy(XDR *xdrs) +{ + /* Flush */ + biobuf *biop = (biobuf *)xdrs->x_private; + if (biop != NULL) { + if (biop->isdirty) { + (void)bio_write_page(biop); + } + if (biop->fd != -1) + (void)close(biop->fd); + free(biop); + } +} diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index f300e093cc..5500c44a6e 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -47,24 +47,48 @@ #include "mfhdf.h" +/* NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE + * + * This is not a normal XDR implementation! + * + * XDR has caused a lot of problems due to the waning availablity of the + * library (removed from libc some time ago) and the variable size of long + * integers and the way various XDR implementations handled that. + * + * What we have here is a stripped-down implentation of XDR that only + * performs POSIX I/O to a file and assumes the put/get_long functions + * only care about 4 bytes (truncating when a long is larger). + * + * In the future, this implementation will be replaced with something + * simpler. + * + * NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE + */ + +/* XDR Boolean type */ typedef int32_t bool_t; /* - * XDR operations. XDR_ENCODE causes the type to be encoded into the - * stream. XDR_DECODE causes the type to be extracted from the stream. - * XDR_FREE can be used to release the space allocated by an XDR_DECODE - * request. + * XDR operations + * + * - XDR_ENCODE causes the type to be encoded into the stream + * - XDR_DECODE causes the type to be extracted from the stream + * - XDR_FREE can be used to release the space allocated by an XDR_DECODE request */ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; -/* The XDR handle +/* Forward declaration */ +struct biobuf; + +/* + * The XDR handle * * Contains the operation which is being applied to the stream and a - * private field for the use of the particular implementation. + * private field. */ typedef struct xinfo { - enum xdr_op x_op; /* Operation */ - void *x_private; /* Pointer to private data */ + enum xdr_op x_op; /* Operation */ + struct biobuf *x_private; /* Pointer to private data */ } XDR; #ifdef __cplusplus @@ -82,10 +106,9 @@ HDFLIBAPI bool_t xdr_putbytes(XDR *, const char *, unsigned); HDFLIBAPI unsigned xdr_getpos(XDR *); HDFLIBAPI bool_t xdr_setpos(XDR *, unsigned); -HDFLIBAPI void xdr_destroy(XDR *); - /* - * "Generic type" XDR routines + * "Data type" XDR routines that read/write/free depending on the op + * parameter of the XDR struct */ HDFLIBAPI bool_t xdr_int(XDR *, int *); HDFLIBAPI bool_t xdr_u_int(XDR *, unsigned *); @@ -99,9 +122,12 @@ HDFLIBAPI bool_t xdr_opaque(XDR *, char *, unsigned); HDFLIBAPI bool_t xdr_float(XDR *, float *); HDFLIBAPI bool_t xdr_double(XDR *, double *); -/* POSIX implementation of XDR */ -HDFLIBAPI int xdrposix_create(XDR *xdrs, int fd, int fmode, enum xdr_op op); -HDFLIBAPI int xdrposix_sync(XDR *xdrs); +/* XDR file manipulation */ +HDFLIBAPI int xdr_create(XDR *xdrs, int fd, int fmode, enum xdr_op op); +HDFLIBAPI int xdr_sync(XDR *xdrs); +HDFLIBAPI void xdr_destroy(XDR *); + +HDFLIBAPI void xdr_setup_nofile(XDR *xdrs, int ncop); #ifdef __cplusplus } From d66422bcc8aacc85b184ab813758673742eeded7 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 23:36:52 -0800 Subject: [PATCH 44/52] Spelling fixes --- mfhdf/libsrc/xdr.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 5500c44a6e..2d9e30d671 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -51,11 +51,11 @@ * * This is not a normal XDR implementation! * - * XDR has caused a lot of problems due to the waning availablity of the + * XDR has caused a lot of problems due to the waning availability of the * library (removed from libc some time ago) and the variable size of long * integers and the way various XDR implementations handled that. * - * What we have here is a stripped-down implentation of XDR that only + * What we have here is a stripped-down implementation of XDR that only * performs POSIX I/O to a file and assumes the put/get_long functions * only care about 4 bytes (truncating when a long is larger). * From 4e19ae1e2d3648d41f4c92ec274e3e194aed148b Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 3 Feb 2024 23:40:54 -0800 Subject: [PATCH 45/52] Fix typo --- mfhdf/libsrc/xdr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 157898224e..706d2846c4 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -764,7 +764,7 @@ xdr_sync(XDR *xdrs) /* * Destroy a POSIX XDR stream * - * Cleans up after xdrposix_create() + * Cleans up after xdr_create() */ void xdr_destroy(XDR *xdrs) From b8451c8eb7a800ce49d23fa52b1ec8c9f8d35bca Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 4 Feb 2024 00:00:32 -0800 Subject: [PATCH 46/52] Improve comments about 64-bit BE systems --- mfhdf/libsrc/xdr.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 706d2846c4..3c4997d693 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -578,8 +578,8 @@ bio_write(biobuf *biop, unsigned char *ptr, int nbytes) * * XDR grew up at a time when all longs were 4 bytes, so we have to awkwardly * hack around 32/64 and BE/LE differences in this call. Essentially, anything - * over (2^32 - 1) will be silently truncated. The 64-bit BE hack is to ensure - * we clip the bits that represent values > (2^32 - 1). + * over a 4-byte boundary will be silently truncated. The 64-bit BE hack is to + * ensure we clip the 32 least significant bits. */ static bool_t @@ -589,8 +589,12 @@ xdr_getlong(XDR *xdrs, long *lp) #if defined(H4_WORDS_BIGENDIAN) #if H4_SIZEOF_LONG > 4 - /* Need to move the pointer on BE systems w/ 64-bit longs */ + /* Zero out the returned bytes */ *lp = 0; + + /* Need to move the pointer on BE systems w/ 64-bit longs so we + * get the 4 lowest-order bytes + */ up += (sizeof(long) - 4); #endif #endif @@ -599,6 +603,7 @@ xdr_getlong(XDR *xdrs, long *lp) return FALSE; #ifndef H4_WORDS_BIGENDIAN + /* Reminder that ntohl returns a uint32_t on modern systems */ *lp = ntohl(*lp); #endif @@ -612,13 +617,16 @@ xdr_putlong(XDR *xdrs, const long *lp) unsigned char *up = (unsigned char *)lp; #ifndef H4_WORDS_BIGENDIAN + /* Reminder that htonl returns a uint32_t on modern systems */ int32_t mycopy = htonl(*lp); up = (unsigned char *)&mycopy; #endif #if defined(H4_WORDS_BIGENDIAN) #if H4_SIZEOF_LONG > 4 - /* Need to move the pointer on BE systems w/ 64-bit longs */ + /* Need to move the pointer on BE systems w/ 64-bit longs so we + * get the 4 lowest-order bytes + */ up += (sizeof(long) - 4); #endif #endif From 64e6dbdbfea1573f671d98b9dc6612907cc9d13b Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 4 Feb 2024 00:05:22 -0800 Subject: [PATCH 47/52] Fix incorrect error string --- mfhdf/libsrc/array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mfhdf/libsrc/array.c b/mfhdf/libsrc/array.c index 736b675336..6be93c2e04 100644 --- a/mfhdf/libsrc/array.c +++ b/mfhdf/libsrc/array.c @@ -506,7 +506,7 @@ xdr_NC_array(XDR *xdrs, NC_array **app) } if (!xdr_u_int(xdrs, &temp_count)) { - NCadvise(NC_EXDR, "xdr_NC_array:xdr_u_long"); + NCadvise(NC_EXDR, "xdr_NC_array:xdr_u_int"); return (FALSE); } *countp = temp_count; From 82400d07c19c8bd2f8e87670a28b2b8d65023a0d Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 4 Feb 2024 00:16:10 -0800 Subject: [PATCH 48/52] Switched some xdr long ops to int --- mfhdf/libsrc/cdf.c | 6 +++--- mfhdf/libsrc/iarray.c | 10 +++++----- mfhdf/libsrc/string.c | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mfhdf/libsrc/cdf.c b/mfhdf/libsrc/cdf.c index 59e228fbbd..45428df6f1 100644 --- a/mfhdf/libsrc/cdf.c +++ b/mfhdf/libsrc/cdf.c @@ -548,7 +548,7 @@ xdr_cdf(XDR *xdrs, NC **handlep) static bool_t NC_xdr_cdf(XDR *xdrs, NC **handlep) { - unsigned long magic; + unsigned magic; if (xdrs->x_op == XDR_FREE) { NC_free_xcdf(*handlep); @@ -563,13 +563,13 @@ NC_xdr_cdf(XDR *xdrs, NC **handlep) } /* magic number */ - if (!xdr_u_long(xdrs, &magic)) { + if (!xdr_u_int(xdrs, &magic)) { if (xdrs->x_op == XDR_DECODE) { NCadvise(NC_ENOTNC, "Not a netcdf file (Can't read magic number)"); } else { /* write error */ - nc_serror("xdr_cdf: xdr_u_long"); + nc_serror("xdr_cdf: xdr_u_int"); } return (FALSE); } diff --git a/mfhdf/libsrc/iarray.c b/mfhdf/libsrc/iarray.c index 8720d321a1..5fcfc67795 100644 --- a/mfhdf/libsrc/iarray.c +++ b/mfhdf/libsrc/iarray.c @@ -67,9 +67,9 @@ NC_free_iarray(NC_iarray *iarray) bool_t xdr_NC_iarray(XDR *xdrs, NC_iarray **ipp) { - int *ip; - unsigned long count = 0; - bool_t stat = TRUE; + int *ip; + unsigned count = 0; + bool_t stat = TRUE; switch (xdrs->x_op) { case XDR_FREE: @@ -77,7 +77,7 @@ xdr_NC_iarray(XDR *xdrs, NC_iarray **ipp) return (TRUE); case XDR_DECODE: /* need the length to pass to new */ - if (!xdr_u_long(xdrs, &count)) { + if (!xdr_u_int(xdrs, &count)) { return (FALSE); } (*ipp) = NC_new_iarray((unsigned)count, (int *)NULL); @@ -90,7 +90,7 @@ xdr_NC_iarray(XDR *xdrs, NC_iarray **ipp) case XDR_ENCODE: /* first deal with the length */ count = (*ipp)->count; - if (!xdr_u_long(xdrs, &count)) { + if (!xdr_u_int(xdrs, &count)) { return (FALSE); } /* then deal with the array */ diff --git a/mfhdf/libsrc/string.c b/mfhdf/libsrc/string.c index d74e65879d..c5dbb08a31 100644 --- a/mfhdf/libsrc/string.c +++ b/mfhdf/libsrc/string.c @@ -131,8 +131,8 @@ NC_re_string(NC_string *old, unsigned count, const char *str) bool_t xdr_NC_string(XDR *xdrs, NC_string **spp) { - unsigned long count = 0; - int status; + unsigned count = 0; + int status; switch (xdrs->x_op) { case XDR_FREE: @@ -140,7 +140,7 @@ xdr_NC_string(XDR *xdrs, NC_string **spp) return (TRUE); case XDR_DECODE: /* need the length to pass to new */ - if (!xdr_u_long(xdrs, &count)) { + if (!xdr_u_int(xdrs, &count)) { return (FALSE); } if (count == 0) { @@ -161,10 +161,10 @@ xdr_NC_string(XDR *xdrs, NC_string **spp) /* first deal with the length */ if (*spp == NULL) { count = 0; - return (xdr_u_long(xdrs, &count)); + return (xdr_u_int(xdrs, &count)); } /* else */ count = (*spp)->count; - if (!xdr_u_long(xdrs, &count)) { + if (!xdr_u_int(xdrs, &count)) { return (FALSE); } /* then deal with the characters */ From 56e6daf25fc33bd83a722b573d145d2f8c435dd2 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sun, 4 Feb 2024 00:48:29 -0800 Subject: [PATCH 49/52] Replaced problematic XDR long operations --- mfhdf/libsrc/cdf.c | 4 +- mfhdf/libsrc/dim.c | 2 +- mfhdf/libsrc/local_nc.h | 10 ++-- mfhdf/libsrc/putget.c | 5 +- mfhdf/libsrc/xdr.c | 113 +++++++--------------------------------- mfhdf/libsrc/xdr.h | 9 ++-- 6 files changed, 30 insertions(+), 113 deletions(-) diff --git a/mfhdf/libsrc/cdf.c b/mfhdf/libsrc/cdf.c index 45428df6f1..b0965bb81f 100644 --- a/mfhdf/libsrc/cdf.c +++ b/mfhdf/libsrc/cdf.c @@ -2839,7 +2839,7 @@ xdr_numrecs(XDR *xdrs, NC *handle) fprintf(stderr, "\txdr_numrecs %ld = %d + %ld * %d\n", xdr_getpos(xdrs), handle->begin_rec, handle->numrecs, handle->recsize); #endif /* RDEBUG */ - if (!xdr_u_long(xdrs, &(handle->numrecs))) + if (!xdr_u_int(xdrs, &(handle->numrecs))) return (FALSE); } @@ -2847,7 +2847,7 @@ xdr_numrecs(XDR *xdrs, NC *handle) nc_serror("Can't set position to RECPOS"); return (FALSE); } - return (xdr_u_long(xdrs, &(handle->numrecs))); + return (xdr_u_int(xdrs, &(handle->numrecs))); } static bool_t diff --git a/mfhdf/libsrc/dim.c b/mfhdf/libsrc/dim.c index 276e51725d..6655a4a9b7 100644 --- a/mfhdf/libsrc/dim.c +++ b/mfhdf/libsrc/dim.c @@ -295,7 +295,7 @@ xdr_NC_dim(XDR *xdrs, NC_dim **dpp) if (!xdr_NC_string(xdrs, &((*dpp)->name))) return (FALSE); - return (xdr_long(xdrs, &((*dpp)->size))); + return (xdr_int(xdrs, &((*dpp)->size))); } /* diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index fbb0adcf1e..14994e77ad 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -131,7 +131,7 @@ typedef struct { /* NC dimension structure */ typedef struct { NC_string *name; - long size; + int32 size; #ifdef HDF int32 dim00_compat; /* compatible with Dim0.0 */ int32 vgid; /* id of the Vgroup representing this dimension */ @@ -157,10 +157,10 @@ typedef struct { unsigned long recsize; /* length of 'record' */ int redefid; /* below gets xdr'd */ - unsigned long numrecs; /* number of 'records' allocated */ - NC_array *dims; - NC_array *attrs; - NC_array *vars; + unsigned numrecs; /* number of 'records' allocated */ + NC_array *dims; + NC_array *attrs; + NC_array *vars; #ifdef HDF int32 hdf_file; int file_type; diff --git a/mfhdf/libsrc/putget.c b/mfhdf/libsrc/putget.c index 1522de5c3b..439c68d204 100644 --- a/mfhdf/libsrc/putget.c +++ b/mfhdf/libsrc/putget.c @@ -535,11 +535,8 @@ xdr_NCv1data(XDR *xdrs, unsigned long where, nc_type type, Void *values) case NC_SHORT: return (xdr_NCvshort(xdrs, (unsigned)rem / 2, (short *)values)); case NC_LONG: -#ifdef H4_HAVE_LP64 + /* nclong is defined to a 32-bit integer type in netcdf.h */ return (xdr_int(xdrs, (nclong *)values)); -#else - return (xdr_long(xdrs, (nclong *)values)); -#endif case NC_FLOAT: return (xdr_float(xdrs, (float *)values)); case NC_DOUBLE: diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index 3c4997d693..d5af32ac40 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -72,8 +72,8 @@ static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0}; /* Forward declarations */ -static bool_t xdr_getlong(XDR *xdrs, long *lp); -static bool_t xdr_putlong(XDR *xdrs, const long *lp); +static bool_t xdr_get32(XDR *xdrs, uint32_t *up); +static bool_t xdr_put32(XDR *xdrs, const uint32_t *up); /******************/ /* XDR Type Calls */ @@ -90,19 +90,13 @@ static bool_t xdr_putlong(XDR *xdrs, const long *lp); bool_t xdr_int(XDR *xdrs, int *ip) { - long l; - switch (xdrs->x_op) { case XDR_ENCODE: - l = (long)*ip; - return xdr_putlong(xdrs, &l); + return xdr_put32(xdrs, (uint32_t *)ip); case XDR_DECODE: - if (!xdr_getlong(xdrs, &l)) - return FALSE; - *ip = (int)l; - return TRUE; + return xdr_get32(xdrs, (uint32_t *)ip); case XDR_FREE: return TRUE; @@ -117,56 +111,14 @@ xdr_int(XDR *xdrs, int *ip) bool_t xdr_u_int(XDR *xdrs, unsigned *up) { - unsigned long l; - switch (xdrs->x_op) { case XDR_ENCODE: - l = (unsigned long)*up; - return xdr_putlong(xdrs, (long *)&l); + return xdr_put32(xdrs, up); case XDR_DECODE: - if (!xdr_getlong(xdrs, (long *)&l)) - return FALSE; - *up = (unsigned)l; - return TRUE; - - case XDR_FREE: - return TRUE; - } - /* NOTREACHED */ - return FALSE; -} - -/* - * XDR long integers - */ -bool_t -xdr_long(XDR *xdrs, long *lp) -{ - switch (xdrs->x_op) { - case XDR_ENCODE: - return xdr_putlong(xdrs, lp); - case XDR_DECODE: - return xdr_getlong(xdrs, lp); - case XDR_FREE: - return TRUE; - } - /* NOTREACHED */ - return FALSE; -} + return xdr_get32(xdrs, up); -/* - * XDR unsigned long integers - */ -bool_t -xdr_u_long(XDR *xdrs, unsigned long *ulp) -{ - switch (xdrs->x_op) { - case XDR_ENCODE: - return xdr_putlong(xdrs, (long *)ulp); - case XDR_DECODE: - return xdr_getlong(xdrs, (long *)ulp); case XDR_FREE: return TRUE; } @@ -570,68 +522,39 @@ bio_write(biobuf *biop, unsigned char *ptr, int nbytes) /***********************/ /* - * Read/write the number of bytes in a C long to the XDR file. 'long' is - * being used in the sense of 'n bytes' and not a long integer value. - * - * This obviously depends on the number of bytes in a long, which is 8 on most - * POSIX systems and 4 on Windows. - * - * XDR grew up at a time when all longs were 4 bytes, so we have to awkwardly - * hack around 32/64 and BE/LE differences in this call. Essentially, anything - * over a 4-byte boundary will be silently truncated. The 64-bit BE hack is to - * ensure we clip the 32 least significant bits. + * Read/write the number of bytes in a C long to the XDR file. 'uint32_t' is + * being used in the sense of '4 bytes' and not a long integer value. */ static bool_t -xdr_getlong(XDR *xdrs, long *lp) +xdr_get32(XDR *xdrs, uint32_t *up) { - unsigned char *up = (unsigned char *)lp; - -#if defined(H4_WORDS_BIGENDIAN) -#if H4_SIZEOF_LONG > 4 - /* Zero out the returned bytes */ - *lp = 0; - - /* Need to move the pointer on BE systems w/ 64-bit longs so we - * get the 4 lowest-order bytes - */ - up += (sizeof(long) - 4); -#endif -#endif + uint8_t *p = (uint8_t *)up; - if (bio_read((biobuf *)xdrs->x_private, up, 4) < 4) + if (bio_read((biobuf *)xdrs->x_private, p, 4) < 4) return FALSE; #ifndef H4_WORDS_BIGENDIAN /* Reminder that ntohl returns a uint32_t on modern systems */ - *lp = ntohl(*lp); + *up = ntohl(*up); #endif return TRUE; } static bool_t -xdr_putlong(XDR *xdrs, const long *lp) +xdr_put32(XDR *xdrs, const uint32_t *up) { - unsigned char *up = (unsigned char *)lp; + uint8_t *p = (uint8_t *)up; #ifndef H4_WORDS_BIGENDIAN /* Reminder that htonl returns a uint32_t on modern systems */ - int32_t mycopy = htonl(*lp); - up = (unsigned char *)&mycopy; + uint32_t mycopy = htonl(*up); + p = (uint8_t *)&mycopy; #endif -#if defined(H4_WORDS_BIGENDIAN) -#if H4_SIZEOF_LONG > 4 - /* Need to move the pointer on BE systems w/ 64-bit longs so we - * get the 4 lowest-order bytes - */ - up += (sizeof(long) - 4); -#endif -#endif - - if (bio_write((biobuf *)xdrs->x_private, up, 4) < 4) + if (bio_write((biobuf *)xdrs->x_private, p, 4) < 4) return FALSE; return TRUE; } @@ -735,7 +658,7 @@ xdr_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) { biobuf *biop = bio_get_new(fd, fmode); xdrs->x_op = op; - xdrs->x_private = (char *)biop; + xdrs->x_private = biop; if (biop == NULL) return -1; diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index 2d9e30d671..fdbb5dc0d3 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -56,11 +56,11 @@ * integers and the way various XDR implementations handled that. * * What we have here is a stripped-down implementation of XDR that only - * performs POSIX I/O to a file and assumes the put/get_long functions - * only care about 4 bytes (truncating when a long is larger). + * performs POSIX I/O to a file and removes the problematic XDR "long" + * operations. * * In the future, this implementation will be replaced with something - * simpler. + * even simpler. * * NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE */ @@ -113,9 +113,6 @@ HDFLIBAPI bool_t xdr_setpos(XDR *, unsigned); HDFLIBAPI bool_t xdr_int(XDR *, int *); HDFLIBAPI bool_t xdr_u_int(XDR *, unsigned *); -HDFLIBAPI bool_t xdr_long(XDR *, long *); -HDFLIBAPI bool_t xdr_u_long(XDR *, unsigned long *); - HDFLIBAPI bool_t xdr_bytes(XDR *, char **, unsigned *, unsigned); HDFLIBAPI bool_t xdr_opaque(XDR *, char *, unsigned); From 2511111d76e5f4b1e57889e4b21cffdf60618f43 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 6 Feb 2024 03:24:06 -0800 Subject: [PATCH 50/52] Added h4 prefix to XDR calls --- mfhdf/libsrc/array.c | 16 ++++---- mfhdf/libsrc/cdf.c | 38 +++++++++---------- mfhdf/libsrc/dim.c | 8 ++-- mfhdf/libsrc/file.c | 22 +++++------ mfhdf/libsrc/iarray.c | 8 ++-- mfhdf/libsrc/local_nc.h | 11 +++--- mfhdf/libsrc/putget.c | 32 ++++++++-------- mfhdf/libsrc/sharray.c | 2 +- mfhdf/libsrc/string.c | 10 ++--- mfhdf/libsrc/var.c | 6 +-- mfhdf/libsrc/xdr.c | 82 ++++++++++++++++++++--------------------- mfhdf/libsrc/xdr.h | 28 +++++++------- 12 files changed, 131 insertions(+), 132 deletions(-) diff --git a/mfhdf/libsrc/array.c b/mfhdf/libsrc/array.c index 506fab0d7a..64db095ba0 100644 --- a/mfhdf/libsrc/array.c +++ b/mfhdf/libsrc/array.c @@ -472,13 +472,13 @@ xdr_NC_array(XDR *xdrs, NC_array **app) break; } - if (!xdr_int(xdrs, &type)) { - NCadvise(NC_EXDR, "xdr_NC_array:xdr_int (enum)"); + if (!h4_xdr_int(xdrs, &type)) { + NCadvise(NC_EXDR, "xdr_NC_array:h4_xdr_int (enum)"); return (FALSE); } - if (!xdr_u_int(xdrs, &temp_count)) { - NCadvise(NC_EXDR, "xdr_NC_array:xdr_u_int"); + if (!h4_xdr_u_int(xdrs, &temp_count)) { + NCadvise(NC_EXDR, "xdr_NC_array:h4_xdr_u_int"); return (FALSE); } *countp = temp_count; @@ -501,19 +501,19 @@ xdr_NC_array(XDR *xdrs, NC_array **app) case NC_UNSPECIFIED: case NC_BYTE: case NC_CHAR: - xdr_NC_fnct = xdr_opaque; + xdr_NC_fnct = h4_xdr_opaque; goto func; case NC_SHORT: xdr_NC_fnct = xdr_shorts; goto func; case NC_LONG: - xdr_NC_fnct = xdr_int; + xdr_NC_fnct = h4_xdr_int; goto loop; case NC_FLOAT: - xdr_NC_fnct = xdr_float; + xdr_NC_fnct = h4_xdr_float; goto loop; case NC_DOUBLE: - xdr_NC_fnct = xdr_double; + xdr_NC_fnct = h4_xdr_double; goto loop; /* private types */ case NC_STRING: diff --git a/mfhdf/libsrc/cdf.c b/mfhdf/libsrc/cdf.c index 2e6c0802cf..b19edc59d5 100644 --- a/mfhdf/libsrc/cdf.c +++ b/mfhdf/libsrc/cdf.c @@ -62,7 +62,7 @@ NC_free_cdf(NC *handle) HGOTO_FAIL(FAIL); /* destroy xdr struct */ - xdr_destroy(handle->xdrs); + h4_xdr_destroy(handle->xdrs); free(handle->xdrs); handle->xdrs = NULL; @@ -245,7 +245,7 @@ NC_new_cdf(const char *name, int mode) */ switch (cdf->file_type) { case HDF_FILE: - xdr_setup_nofile(cdf->xdrs, mode); /* return type is 'void' */ + h4_xdr_setup_nofile(cdf->xdrs, mode); /* return type is 'void' */ break; case netCDF_FILE: if (NCxdrfile_create(cdf->xdrs, name, mode) < 0) @@ -254,7 +254,7 @@ NC_new_cdf(const char *name, int mode) case CDF_FILE: /* CDF_xdrfile_create(); */ /* try this, I bet it will be sufficient */ - xdr_setup_nofile(cdf->xdrs, mode); + h4_xdr_setup_nofile(cdf->xdrs, mode); break; } @@ -354,7 +354,7 @@ NC_new_cdf(const char *name, int mode) These routines only free up allocated memory. */ NC_free_xcdf(cdf); /* no point in catching error here */ if (cdf->xdrs != NULL) { - xdr_destroy(cdf->xdrs); + h4_xdr_destroy(cdf->xdrs); free(cdf->xdrs); } free(cdf); @@ -497,21 +497,21 @@ NC_xdr_cdf(XDR *xdrs, NC **handlep) return (TRUE); } - if (xdr_getpos(xdrs) != 0) { - if (!xdr_setpos(xdrs, 0)) { + if (h4_xdr_getpos(xdrs) != 0) { + if (!h4_xdr_setpos(xdrs, 0)) { nc_serror("Can't set position to begin"); return (FALSE); } } /* magic number */ - if (!xdr_u_int(xdrs, &magic)) { + if (!h4_xdr_u_int(xdrs, &magic)) { if (xdrs->x_op == XDR_DECODE) { NCadvise(NC_ENOTNC, "Not a netcdf file (Can't read magic number)"); } else { /* write error */ - nc_serror("xdr_cdf: xdr_u_int"); + nc_serror("xdr_cdf: h4_xdr_u_int"); } return (FALSE); } @@ -2334,20 +2334,20 @@ xdr_numrecs(XDR *xdrs, NC *handle) * record so we can successfully read back the * entire last record. */ - if (!xdr_setpos(xdrs, handle->begin_rec + handle->numrecs * handle->recsize)) { + if (!h4_xdr_setpos(xdrs, handle->begin_rec + handle->numrecs * handle->recsize)) { nc_serror("Can't set position to EOF"); - return (FALSE); + return FALSE; } - if (!xdr_u_int(xdrs, &(handle->numrecs))) - return (FALSE); + if (!h4_xdr_u_int(xdrs, &(handle->numrecs))) + return FALSE; } - if (!xdr_setpos(xdrs, RECPOS)) { + if (!h4_xdr_setpos(xdrs, RECPOS)) { nc_serror("Can't set position to RECPOS"); - return (FALSE); + return FALSE; } - return (xdr_u_int(xdrs, &(handle->numrecs))); + return h4_xdr_u_int(xdrs, &(handle->numrecs)); } static bool_t @@ -2393,7 +2393,7 @@ xdr_NC_fill(XDR *xdrs, NC_var *vp) case NC_BYTE: case NC_CHAR: alen /= 4; - xdr_NC_fnct = xdr_bytes; + xdr_NC_fnct = h4_xdr_bytes; break; case NC_SHORT: alen /= 4; @@ -2401,15 +2401,15 @@ xdr_NC_fill(XDR *xdrs, NC_var *vp) break; case NC_LONG: alen /= 4; - xdr_NC_fnct = xdr_int; + xdr_NC_fnct = h4_xdr_int; break; case NC_FLOAT: alen /= 4; - xdr_NC_fnct = xdr_float; + xdr_NC_fnct = h4_xdr_float; break; case NC_DOUBLE: alen /= 8; - xdr_NC_fnct = xdr_double; + xdr_NC_fnct = h4_xdr_double; break; default: NCadvise(NC_EBADTYPE, "bad type %d", vp->type); diff --git a/mfhdf/libsrc/dim.c b/mfhdf/libsrc/dim.c index 5b62e0d8ad..82b4ade374 100644 --- a/mfhdf/libsrc/dim.c +++ b/mfhdf/libsrc/dim.c @@ -268,14 +268,14 @@ xdr_NC_dim(XDR *xdrs, NC_dim **dpp) { if (xdrs->x_op == XDR_FREE) { NC_free_dim((*dpp)); - return (TRUE); + return TRUE; } if (xdrs->x_op == XDR_DECODE) { *dpp = malloc(sizeof(NC_dim)); if (*dpp == NULL) { nc_serror("xdr_NC_dim"); - return (FALSE); + return FALSE; } } @@ -284,8 +284,8 @@ xdr_NC_dim(XDR *xdrs, NC_dim **dpp) (*dpp)->count = 0; if (!xdr_NC_string(xdrs, &((*dpp)->name))) - return (FALSE); - return (xdr_int(xdrs, &((*dpp)->size))); + return FALSE; + return h4_xdr_int(xdrs, &((*dpp)->size)); } /* diff --git a/mfhdf/libsrc/file.c b/mfhdf/libsrc/file.c index fd89ef2e74..1f2dd6f297 100644 --- a/mfhdf/libsrc/file.c +++ b/mfhdf/libsrc/file.c @@ -684,16 +684,16 @@ NC_dcpy(XDR *target, XDR *source, long nbytes) char buf[NC_DCP_BUFSIZE]; while (nbytes > sizeof(buf)) { - if (!xdr_getbytes(source, buf, sizeof(buf))) + if (!h4_xdr_getbytes(source, buf, sizeof(buf))) goto err; - if (!xdr_putbytes(target, buf, sizeof(buf))) + if (!h4_xdr_putbytes(target, buf, sizeof(buf))) goto err; nbytes -= sizeof(buf); } /* we know nbytes <= sizeof(buf) at this point */ - if (!xdr_getbytes(source, buf, nbytes)) + if (!h4_xdr_getbytes(source, buf, nbytes)) goto err; - if (!xdr_putbytes(target, buf, nbytes)) + if (!h4_xdr_putbytes(target, buf, nbytes)) goto err; return (TRUE); err: @@ -711,8 +711,8 @@ NC_vcpy(XDR *target, NC *old, int varid) vpp = (NC_var **)old->vars->values; vpp += varid; - if (!xdr_setpos(old->xdrs, (*vpp)->begin)) { - NCadvise(NC_EXDR, "NC_vcpy: xdr_setpos"); + if (!h4_xdr_setpos(old->xdrs, (*vpp)->begin)) { + NCadvise(NC_EXDR, "NC_vcpy: h4_xdr_setpos"); return (FALSE); } @@ -729,8 +729,8 @@ NC_reccpy(XDR *target, NC *old, int varid, int recnum) vpp = (NC_var **)old->vars->values; vpp += varid; - if (!xdr_setpos(old->xdrs, (*vpp)->begin + old->recsize * recnum)) { - NCadvise(NC_EXDR, "NC_reccpy: xdr_setpos"); + if (!h4_xdr_setpos(old->xdrs, (*vpp)->begin + old->recsize * recnum)) { + NCadvise(NC_EXDR, "NC_reccpy: h4_xdr_setpos"); return (FALSE); } @@ -822,7 +822,7 @@ NC_endef(int cdfid, NC *handle) /* close stash */ /* NC_free_cdf(stash) ; */ #ifdef H4_HAVE_WIN32_API - xdr_destroy(handle->xdrs); /* close handle */ + h4_xdr_destroy(handle->xdrs); /* close handle */ if (remove(realpath) != 0) nc_serror("couldn't remove filename \"%s\"", realpath); #endif @@ -987,7 +987,7 @@ ncsetfill(int id, int fillmode) int NCxdrfile_sync(XDR *xdrs) { - return xdr_sync(xdrs); + return h4_xdr_sync(xdrs); } int @@ -1033,7 +1033,7 @@ NCxdrfile_create(XDR *xdrs, const char *path, int ncmode) op = XDR_DECODE; } - if (xdr_create(xdrs, fd, fmode, op) < 0) + if (h4_xdr_create(xdrs, fd, fmode, op) < 0) return -1; else return fd; diff --git a/mfhdf/libsrc/iarray.c b/mfhdf/libsrc/iarray.c index 5fcfc67795..8d20ba81b8 100644 --- a/mfhdf/libsrc/iarray.c +++ b/mfhdf/libsrc/iarray.c @@ -77,7 +77,7 @@ xdr_NC_iarray(XDR *xdrs, NC_iarray **ipp) return (TRUE); case XDR_DECODE: /* need the length to pass to new */ - if (!xdr_u_int(xdrs, &count)) { + if (!h4_xdr_u_int(xdrs, &count)) { return (FALSE); } (*ipp) = NC_new_iarray((unsigned)count, (int *)NULL); @@ -85,17 +85,17 @@ xdr_NC_iarray(XDR *xdrs, NC_iarray **ipp) return (FALSE); /* then deal with the array */ for (ip = (*ipp)->values; (count > 0) && stat; count--) - stat = xdr_int(xdrs, ip++); + stat = h4_xdr_int(xdrs, ip++); return (stat); case XDR_ENCODE: /* first deal with the length */ count = (*ipp)->count; - if (!xdr_u_int(xdrs, &count)) { + if (!h4_xdr_u_int(xdrs, &count)) { return (FALSE); } /* then deal with the array */ for (ip = (*ipp)->values; (count > 0) && stat; count--) - stat = xdr_int(xdrs, ip++); + stat = h4_xdr_int(xdrs, ip++); return (stat); } return (FALSE); diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index ed1a5eea91..060f3ab775 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -230,8 +230,9 @@ extern "C" { #endif /* If using the real netCDF library and API (when --disable-netcdf configure flag is used) - need to mangle the HDF versions of netCDF API function names - to not conflict w/ oriinal netCDF ones */ + * need to mangle the HDF versions of netCDF API function names + * to not conflict w/ oriinal netCDF ones + */ #ifndef H4_HAVE_NETCDF #define nc_serror HNAME(nc_serror) #define NCadvise HNAME(NCadvise) @@ -288,10 +289,8 @@ extern "C" { #define NC_dcpy HNAME(NC_dcpy) #define NCxdrfile_sync HNAME(NCxdrfile_sync) #define NCxdrfile_create HNAME(NCxdrfile_create) -#ifdef HDF -#define NCgenio HNAME(NCgenio) /* from putgetg.c */ -#define NC_var_shape HNAME(NC_var_shape) /* from var.c */ -#endif +#define NCgenio HNAME(NCgenio) /* from putgetg.c */ +#define NC_var_shape HNAME(NC_var_shape) /* from var.c */ #endif /* !H4_HAVE_NETCDF ie. NOT USING HDF version of netCDF ncxxx API */ #define nncpopt H4_F77_FUNC(ncpopt, NCPOPT) diff --git a/mfhdf/libsrc/putget.c b/mfhdf/libsrc/putget.c index c97f60200e..2befea8f31 100644 --- a/mfhdf/libsrc/putget.c +++ b/mfhdf/libsrc/putget.c @@ -33,7 +33,7 @@ static const long *NCvcmaxcontig(NC *, NC_var *, const long *, const long *); int NC_fill_buffer(NC *handle, int varid, const long *edges, void *values); -#define xdr_NCsetpos(xdrs, pos) xdr_setpos((xdrs), (pos)) +#define xdr_NCsetpos(xdrs, pos) h4_xdr_setpos((xdrs), (pos)) /* * Check if an ncxxx function has called the current function @@ -352,13 +352,13 @@ xdr_NCvbyte(XDR *xdrs, unsigned rem, unsigned count, char *values) * Since we only read/write multiples of four bytes, * We will read in the word to change one byte in it. */ - origin = xdr_getpos(xdrs); + origin = h4_xdr_getpos(xdrs); /* Next op is a get */ xdrs->x_op = XDR_DECODE; } - if (!xdr_opaque(xdrs, buf, 4)) { + if (!h4_xdr_opaque(xdrs, buf, 4)) { /* Get failed, assume we are trying to read off the end */ memset(buf, 0, sizeof(buf)); } @@ -377,9 +377,9 @@ xdr_NCvbyte(XDR *xdrs, unsigned rem, unsigned count, char *values) } if (x_op == XDR_ENCODE) { - if (!xdr_setpos(xdrs, origin)) + if (!h4_xdr_setpos(xdrs, origin)) return (FALSE); - if (!xdr_opaque(xdrs, buf, 4)) + if (!h4_xdr_opaque(xdrs, buf, 4)) return (FALSE); } @@ -398,13 +398,13 @@ xdr_NCvshort(XDR *xdrs, unsigned which, short *values) enum xdr_op x_op = xdrs->x_op; /* save state */ if (x_op == XDR_ENCODE) { - origin = xdr_getpos(xdrs); + origin = h4_xdr_getpos(xdrs); /* Next op is a get */ xdrs->x_op = XDR_DECODE; } - if (!xdr_opaque(xdrs, (char *)buf, 4)) { + if (!h4_xdr_opaque(xdrs, (char *)buf, 4)) { /* Get failed, assume we are trying to read off the end */ memset(buf, 0, sizeof(buf)); } @@ -419,9 +419,9 @@ xdr_NCvshort(XDR *xdrs, unsigned which, short *values) buf[which + 1] = *values % 256; buf[which] = (*values >> 8); - if (!xdr_setpos(xdrs, origin)) + if (!h4_xdr_setpos(xdrs, origin)) return (FALSE); - if (!xdr_opaque(xdrs, (char *)buf, 4)) + if (!h4_xdr_opaque(xdrs, (char *)buf, 4)) return (FALSE); } else { @@ -463,11 +463,11 @@ xdr_NCv1data(XDR *xdrs, unsigned long where, nc_type type, Void *values) return (xdr_NCvshort(xdrs, (unsigned)rem / 2, (short *)values)); case NC_LONG: /* nclong is defined to a 32-bit integer type in netcdf.h */ - return (xdr_int(xdrs, (nclong *)values)); + return (h4_xdr_int(xdrs, (nclong *)values)); case NC_FLOAT: - return (xdr_float(xdrs, (float *)values)); + return (h4_xdr_float(xdrs, (float *)values)); case NC_DOUBLE: - return (xdr_double(xdrs, (double *)values)); + return (h4_xdr_double(xdrs, (double *)values)); default: break; } @@ -1471,7 +1471,7 @@ xdr_NCvdata(XDR *xdrs, unsigned long where, nc_type type, unsigned count, Void * rem = count % 4; /* tail remainder */ count -= rem; - if (!xdr_opaque(xdrs, values, count)) + if (!h4_xdr_opaque(xdrs, values, count)) return (FALSE); if (rem != 0) { @@ -1498,15 +1498,15 @@ xdr_NCvdata(XDR *xdrs, unsigned long where, nc_type type, unsigned count, Void * } /* else */ return (TRUE); case NC_LONG: - xdr_NC_fnct = xdr_int; + xdr_NC_fnct = h4_xdr_int; szof = sizeof(nclong); break; case NC_FLOAT: - xdr_NC_fnct = xdr_float; + xdr_NC_fnct = h4_xdr_float; szof = sizeof(float); break; case NC_DOUBLE: - xdr_NC_fnct = xdr_double; + xdr_NC_fnct = h4_xdr_double; szof = sizeof(double); break; default: diff --git a/mfhdf/libsrc/sharray.c b/mfhdf/libsrc/sharray.c index 33d4d37a74..fa737a91ac 100644 --- a/mfhdf/libsrc/sharray.c +++ b/mfhdf/libsrc/sharray.c @@ -37,7 +37,7 @@ NCxdr_shortsb(XDR *xdrs, short *sp, unsigned nshorts) } } - if (!xdr_opaque(xdrs, (char *)buf, nbytes)) + if (!h4_xdr_opaque(xdrs, (char *)buf, nbytes)) return FALSE; if (xdrs->x_op == XDR_DECODE) { diff --git a/mfhdf/libsrc/string.c b/mfhdf/libsrc/string.c index 9a3e840908..558c27e4f4 100644 --- a/mfhdf/libsrc/string.c +++ b/mfhdf/libsrc/string.c @@ -130,7 +130,7 @@ xdr_NC_string(XDR *xdrs, NC_string **spp) return (TRUE); case XDR_DECODE: /* need the length to pass to new */ - if (!xdr_u_int(xdrs, &count)) { + if (!h4_xdr_u_int(xdrs, &count)) { return (FALSE); } if (count == 0) { @@ -142,7 +142,7 @@ xdr_NC_string(XDR *xdrs, NC_string **spp) return (FALSE); (*spp)->values[count] = 0; /* then deal with the characters */ - status = xdr_opaque(xdrs, (*spp)->values, (*spp)->count); + status = h4_xdr_opaque(xdrs, (*spp)->values, (*spp)->count); /* might be padded */ (*spp)->len = strlen((*spp)->values); @@ -151,14 +151,14 @@ xdr_NC_string(XDR *xdrs, NC_string **spp) /* first deal with the length */ if (*spp == NULL) { count = 0; - return (xdr_u_int(xdrs, &count)); + return (h4_xdr_u_int(xdrs, &count)); } /* else */ count = (*spp)->count; - if (!xdr_u_int(xdrs, &count)) { + if (!h4_xdr_u_int(xdrs, &count)) { return (FALSE); } /* then deal with the characters */ - return (xdr_opaque(xdrs, (*spp)->values, (*spp)->count)); + return (h4_xdr_opaque(xdrs, (*spp)->values, (*spp)->count)); } return (FALSE); } diff --git a/mfhdf/libsrc/var.c b/mfhdf/libsrc/var.c index f7a3bac353..acf78812bf 100644 --- a/mfhdf/libsrc/var.c +++ b/mfhdf/libsrc/var.c @@ -517,12 +517,12 @@ xdr_NC_var(XDR *xdrs, NC_var **vpp) if (!xdr_NC_array(xdrs, &((*vpp)->attrs))) return (FALSE); - if (!xdr_int(xdrs, &temp_type)) { + if (!h4_xdr_int(xdrs, &temp_type)) { return (FALSE); } (*vpp)->type = (nc_type)temp_type; - if (!xdr_u_int(xdrs, &temp_len)) { + if (!h4_xdr_u_int(xdrs, &temp_len)) { return (FALSE); } (*vpp)->len = (unsigned long)temp_len; @@ -532,7 +532,7 @@ xdr_NC_var(XDR *xdrs, NC_var **vpp) if (xdrs->x_op == XDR_ENCODE) begin = (*vpp)->begin; - if (!xdr_u_int(xdrs, &begin)) + if (!h4_xdr_u_int(xdrs, &begin)) return (FALSE); if (xdrs->x_op == XDR_DECODE) (*vpp)->begin = begin; diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/xdr.c index d5af32ac40..595eb0780e 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/xdr.c @@ -72,8 +72,8 @@ static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0}; /* Forward declarations */ -static bool_t xdr_get32(XDR *xdrs, uint32_t *up); -static bool_t xdr_put32(XDR *xdrs, const uint32_t *up); +static bool_t h4_xdr_get32(XDR *xdrs, uint32_t *up); +static bool_t h4_xdr_put32(XDR *xdrs, const uint32_t *up); /******************/ /* XDR Type Calls */ @@ -88,15 +88,15 @@ static bool_t xdr_put32(XDR *xdrs, const uint32_t *up); * XDR integers */ bool_t -xdr_int(XDR *xdrs, int *ip) +h4_xdr_int(XDR *xdrs, int *ip) { switch (xdrs->x_op) { case XDR_ENCODE: - return xdr_put32(xdrs, (uint32_t *)ip); + return h4_xdr_put32(xdrs, (uint32_t *)ip); case XDR_DECODE: - return xdr_get32(xdrs, (uint32_t *)ip); + return h4_xdr_get32(xdrs, (uint32_t *)ip); case XDR_FREE: return TRUE; @@ -109,15 +109,15 @@ xdr_int(XDR *xdrs, int *ip) * XDR unsigned integers */ bool_t -xdr_u_int(XDR *xdrs, unsigned *up) +h4_xdr_u_int(XDR *xdrs, unsigned *up) { switch (xdrs->x_op) { case XDR_ENCODE: - return xdr_put32(xdrs, up); + return h4_xdr_put32(xdrs, up); case XDR_DECODE: - return xdr_get32(xdrs, up); + return h4_xdr_get32(xdrs, up); case XDR_FREE: return TRUE; @@ -133,7 +133,7 @@ xdr_u_int(XDR *xdrs, unsigned *up) * cp points to the opaque object and cnt gives the byte length. */ bool_t -xdr_opaque(XDR *xdrs, char *cp, unsigned cnt) +h4_xdr_opaque(XDR *xdrs, char *cp, unsigned cnt) { unsigned rndup; static int crud[BYTES_PER_XDR_UNIT]; @@ -152,19 +152,19 @@ xdr_opaque(XDR *xdrs, char *cp, unsigned cnt) rndup = BYTES_PER_XDR_UNIT - rndup; if (xdrs->x_op == XDR_DECODE) { - if (!xdr_getbytes(xdrs, cp, cnt)) + if (!h4_xdr_getbytes(xdrs, cp, cnt)) return FALSE; if (rndup == 0) return TRUE; - return xdr_getbytes(xdrs, (char *)crud, rndup); + return h4_xdr_getbytes(xdrs, (char *)crud, rndup); } if (xdrs->x_op == XDR_ENCODE) { - if (!xdr_putbytes(xdrs, cp, cnt)) + if (!h4_xdr_putbytes(xdrs, cp, cnt)) return FALSE; if (rndup == 0) return TRUE; - return xdr_putbytes(xdrs, xdr_zero, rndup); + return h4_xdr_putbytes(xdrs, xdr_zero, rndup); } if (xdrs->x_op == XDR_FREE) @@ -185,7 +185,7 @@ xdr_opaque(XDR *xdrs, char *cp, unsigned cnt) * If *cpp is NULL maxsize bytes are allocated */ bool_t -xdr_bytes(XDR *xdrs, char **cpp, unsigned *sizep, unsigned maxsize) +h4_xdr_bytes(XDR *xdrs, char **cpp, unsigned *sizep, unsigned maxsize) { char *sp = *cpp; /* sp is the actual string pointer */ unsigned nodesize; @@ -195,7 +195,7 @@ xdr_bytes(XDR *xdrs, char **cpp, unsigned *sizep, unsigned maxsize) /* * first deal with the length since xdr bytes are counted */ - if (!xdr_u_int(xdrs, sizep)) + if (!h4_xdr_u_int(xdrs, sizep)) return FALSE; nodesize = *sizep; if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) @@ -214,13 +214,13 @@ xdr_bytes(XDR *xdrs, char **cpp, unsigned *sizep, unsigned maxsize) allocated = TRUE; } if (sp == NULL) { - fprintf(stderr, "xdr_bytes: out of memory\n"); + fprintf(stderr, "h4_xdr_bytes: out of memory\n"); return FALSE; } /* FALLTHROUGH */ case XDR_ENCODE: - ret = xdr_opaque(xdrs, sp, nodesize); + ret = h4_xdr_opaque(xdrs, sp, nodesize); if ((xdrs->x_op == XDR_DECODE) && (ret == FALSE)) { if (allocated == TRUE) { free(sp); @@ -244,15 +244,15 @@ xdr_bytes(XDR *xdrs, char **cpp, unsigned *sizep, unsigned maxsize) * XDR 4-byte floats */ bool_t -xdr_float(XDR *xdrs, float *fp) +h4_xdr_float(XDR *xdrs, float *fp) { switch (xdrs->x_op) { case XDR_ENCODE: - return xdr_int(xdrs, (int *)fp); + return h4_xdr_int(xdrs, (int *)fp); case XDR_DECODE: - return xdr_int(xdrs, (int *)fp); + return h4_xdr_int(xdrs, (int *)fp); case XDR_FREE: return TRUE; @@ -267,7 +267,7 @@ xdr_float(XDR *xdrs, float *fp) * I/O operation. */ bool_t -xdr_double(XDR *xdrs, double *dp) +h4_xdr_double(XDR *xdrs, double *dp) { int *ip; bool_t rv; @@ -279,15 +279,15 @@ xdr_double(XDR *xdrs, double *dp) case XDR_ENCODE: ip = (int *)(void *)dp; #ifdef H4_WORDS_BIGENDIAN - rv = xdr_int(xdrs, ip); + rv = h4_xdr_int(xdrs, ip); if (!rv) return rv; - rv = xdr_int(xdrs, ip + 1); + rv = h4_xdr_int(xdrs, ip + 1); #else - rv = xdr_int(xdrs, ip + 1); + rv = h4_xdr_int(xdrs, ip + 1); if (!rv) return rv; - rv = xdr_int(xdrs, ip); + rv = h4_xdr_int(xdrs, ip); #endif return rv; break; @@ -295,15 +295,15 @@ xdr_double(XDR *xdrs, double *dp) case XDR_DECODE: ip = (int *)(void *)dp; #ifdef H4_WORDS_BIGENDIAN - rv = xdr_int(xdrs, ip); + rv = h4_xdr_int(xdrs, ip); if (!rv) return rv; - rv = xdr_int(xdrs, ip + 1); + rv = h4_xdr_int(xdrs, ip + 1); #else - rv = xdr_int(xdrs, ip + 1); + rv = h4_xdr_int(xdrs, ip + 1); if (!rv) return rv; - rv = xdr_int(xdrs, ip); + rv = h4_xdr_int(xdrs, ip); #endif return rv; break; @@ -527,7 +527,7 @@ bio_write(biobuf *biop, unsigned char *ptr, int nbytes) */ static bool_t -xdr_get32(XDR *xdrs, uint32_t *up) +h4_xdr_get32(XDR *xdrs, uint32_t *up) { uint8_t *p = (uint8_t *)up; @@ -543,7 +543,7 @@ xdr_get32(XDR *xdrs, uint32_t *up) } static bool_t -xdr_put32(XDR *xdrs, const uint32_t *up) +h4_xdr_put32(XDR *xdrs, const uint32_t *up) { uint8_t *p = (uint8_t *)up; @@ -562,11 +562,11 @@ xdr_put32(XDR *xdrs, const uint32_t *up) /* * Read/Write a bunch of bytes to/from an XDR file * - * NOTE: These deal with raw bytes, not "counted bytes", like xdr_bytes() does! + * NOTE: These deal with raw bytes, not "counted bytes", like h4_xdr_bytes() does! */ bool_t -xdr_getbytes(XDR *xdrs, char *addr, unsigned len) +h4_xdr_getbytes(XDR *xdrs, char *addr, unsigned len) { if ((len != 0) && (bio_read((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) return FALSE; @@ -574,7 +574,7 @@ xdr_getbytes(XDR *xdrs, char *addr, unsigned len) } bool_t -xdr_putbytes(XDR *xdrs, const char *addr, unsigned len) +h4_xdr_putbytes(XDR *xdrs, const char *addr, unsigned len) { if ((len != 0) && (bio_write((biobuf *)xdrs->x_private, (unsigned char *)addr, (int)len) != len)) return FALSE; @@ -586,14 +586,14 @@ xdr_putbytes(XDR *xdrs, const char *addr, unsigned len) */ unsigned -xdr_getpos(XDR *xdrs) +h4_xdr_getpos(XDR *xdrs) { biobuf *biop = (biobuf *)xdrs->x_private; return BIOBUFSIZ * biop->page + CNT(biop); } bool_t -xdr_setpos(XDR *xdrs, unsigned pos) +h4_xdr_setpos(XDR *xdrs, unsigned pos) { biobuf *biop = (biobuf *)xdrs->x_private; if (biop != NULL) { @@ -634,7 +634,7 @@ xdr_setpos(XDR *xdrs, unsigned pos) * up the file. */ void -xdr_setup_nofile(XDR *xdrs, int ncop) +h4_xdr_setup_nofile(XDR *xdrs, int ncop) { biobuf *biop = bio_get_new(-1, 0); @@ -654,7 +654,7 @@ xdr_setup_nofile(XDR *xdrs, int ncop) * Operation flag is initialized to op */ int -xdr_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) +h4_xdr_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) { biobuf *biop = bio_get_new(fd, fmode); xdrs->x_op = op; @@ -674,7 +674,7 @@ xdr_create(XDR *xdrs, int fd, int fmode, enum xdr_op op) * Flush the I/O buffer to the file */ int -xdr_sync(XDR *xdrs) +h4_xdr_sync(XDR *xdrs) { biobuf *biop = (biobuf *)xdrs->x_private; if (biop->isdirty) { @@ -695,10 +695,10 @@ xdr_sync(XDR *xdrs) /* * Destroy a POSIX XDR stream * - * Cleans up after xdr_create() + * Cleans up after h4_xdr_create() */ void -xdr_destroy(XDR *xdrs) +h4_xdr_destroy(XDR *xdrs) { /* Flush */ biobuf *biop = (biobuf *)xdrs->x_private; diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/xdr.h index fdbb5dc0d3..561e312ff6 100644 --- a/mfhdf/libsrc/xdr.h +++ b/mfhdf/libsrc/xdr.h @@ -100,31 +100,31 @@ extern "C" { /* * Operations defined on an XDR handle */ -HDFLIBAPI bool_t xdr_getbytes(XDR *, char *, unsigned); -HDFLIBAPI bool_t xdr_putbytes(XDR *, const char *, unsigned); +HDFLIBAPI bool_t h4_xdr_getbytes(XDR *, char *, unsigned); +HDFLIBAPI bool_t h4_xdr_putbytes(XDR *, const char *, unsigned); -HDFLIBAPI unsigned xdr_getpos(XDR *); -HDFLIBAPI bool_t xdr_setpos(XDR *, unsigned); +HDFLIBAPI unsigned h4_xdr_getpos(XDR *); +HDFLIBAPI bool_t h4_xdr_setpos(XDR *, unsigned); /* * "Data type" XDR routines that read/write/free depending on the op * parameter of the XDR struct */ -HDFLIBAPI bool_t xdr_int(XDR *, int *); -HDFLIBAPI bool_t xdr_u_int(XDR *, unsigned *); +HDFLIBAPI bool_t h4_xdr_int(XDR *, int *); +HDFLIBAPI bool_t h4_xdr_u_int(XDR *, unsigned *); -HDFLIBAPI bool_t xdr_bytes(XDR *, char **, unsigned *, unsigned); -HDFLIBAPI bool_t xdr_opaque(XDR *, char *, unsigned); +HDFLIBAPI bool_t h4_xdr_bytes(XDR *, char **, unsigned *, unsigned); +HDFLIBAPI bool_t h4_xdr_opaque(XDR *, char *, unsigned); -HDFLIBAPI bool_t xdr_float(XDR *, float *); -HDFLIBAPI bool_t xdr_double(XDR *, double *); +HDFLIBAPI bool_t h4_xdr_float(XDR *, float *); +HDFLIBAPI bool_t h4_xdr_double(XDR *, double *); /* XDR file manipulation */ -HDFLIBAPI int xdr_create(XDR *xdrs, int fd, int fmode, enum xdr_op op); -HDFLIBAPI int xdr_sync(XDR *xdrs); -HDFLIBAPI void xdr_destroy(XDR *); +HDFLIBAPI int h4_xdr_create(XDR *xdrs, int fd, int fmode, enum xdr_op op); +HDFLIBAPI int h4_xdr_sync(XDR *xdrs); +HDFLIBAPI void h4_xdr_destroy(XDR *); -HDFLIBAPI void xdr_setup_nofile(XDR *xdrs, int ncop); +HDFLIBAPI void h4_xdr_setup_nofile(XDR *xdrs, int ncop); #ifdef __cplusplus } From 6a7a0118d05e5c92df81dc53d6ab8bdd76b21016 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Tue, 6 Feb 2024 03:40:53 -0800 Subject: [PATCH 51/52] Renamed XDR files w/ h4 prefix --- mfhdf/libsrc/CMakeLists.txt | 4 ++-- mfhdf/libsrc/Makefile.am | 2 +- mfhdf/libsrc/{xdr.c => h4_xdr.c} | 2 +- mfhdf/libsrc/{xdr.h => h4_xdr.h} | 0 mfhdf/libsrc/local_nc.h | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) rename mfhdf/libsrc/{xdr.c => h4_xdr.c} (99%) rename mfhdf/libsrc/{xdr.h => h4_xdr.h} (100%) diff --git a/mfhdf/libsrc/CMakeLists.txt b/mfhdf/libsrc/CMakeLists.txt index 2d8bde9b51..b3bf90d17d 100644 --- a/mfhdf/libsrc/CMakeLists.txt +++ b/mfhdf/libsrc/CMakeLists.txt @@ -31,7 +31,7 @@ set (HDF4_MFHDF_LIBSRC_CSRCS ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/sharray.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/string.c ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/var.c - ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdr.c + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/h4_xdr.c ) set (HDF4_MFHDF_LIBSRC_INSTALL_CHDRS @@ -46,7 +46,7 @@ set (HDF4_MFHDF_LIBSRC_CHDRS ${HDF4_MFHDF_LIBSRC_INSTALL_CHDRS} ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/error.h ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/mfprivate.h - ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/xdr.h + ${HDF4_MFHDF_LIBSRC_SOURCE_DIR}/h4_xdr.h ) if (HDF4_ENABLE_NETCDF) diff --git a/mfhdf/libsrc/Makefile.am b/mfhdf/libsrc/Makefile.am index bd51e66f94..64862de8a5 100644 --- a/mfhdf/libsrc/Makefile.am +++ b/mfhdf/libsrc/Makefile.am @@ -19,7 +19,7 @@ lib_LTLIBRARIES = libmfhdf.la ## Information for building the "libmfhdf.la" library CSOURCES = array.c attr.c cdf.c dim.c file.c hdfsds.c iarray.c error.c \ globdef.c mfsd.c mfdatainfo.c nssdc.c putget.c putgetg.c \ - sharray.c string.c var.c xdr.c + sharray.c string.c var.c h4_xdr.c if HDF_BUILD_NETCDF FSOURCES = $(top_builddir)/mfhdf/fortran/jackets.c $(top_srcdir)/mfhdf/fortran/mfsdf.c $(top_srcdir)/mfhdf/fortran/mfsdff.f diff --git a/mfhdf/libsrc/xdr.c b/mfhdf/libsrc/h4_xdr.c similarity index 99% rename from mfhdf/libsrc/xdr.c rename to mfhdf/libsrc/h4_xdr.c index 595eb0780e..8e53036dba 100644 --- a/mfhdf/libsrc/xdr.c +++ b/mfhdf/libsrc/h4_xdr.c @@ -59,7 +59,7 @@ #endif #include "mfhdf.h" -#include "xdr.h" +#include "h4_xdr.h" /* * This is the number of bytes per unit of external data. diff --git a/mfhdf/libsrc/xdr.h b/mfhdf/libsrc/h4_xdr.h similarity index 100% rename from mfhdf/libsrc/xdr.h rename to mfhdf/libsrc/h4_xdr.h diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index 060f3ab775..50388e388b 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -30,7 +30,8 @@ #define FILENAME_MAX 255 #endif -#include "xdr.h" +/* HDF4's stripped-down XDR implementation */ +#include "h4_xdr.h" #ifdef H4_HAVE_NETCDF #include "netcdf.h" /* needed for defs of nc_type, ncvoid, ... */ From b335b9f65e71dc5388a9ada6dfb1e298b6f329ff Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 6 Feb 2024 11:41:38 +0000 Subject: [PATCH 52/52] Committing clang-format changes --- mfhdf/libsrc/local_nc.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mfhdf/libsrc/local_nc.h b/mfhdf/libsrc/local_nc.h index 50388e388b..4c261327c2 100644 --- a/mfhdf/libsrc/local_nc.h +++ b/mfhdf/libsrc/local_nc.h @@ -145,14 +145,14 @@ typedef struct { unsigned long recsize; /* length of 'record' */ int redefid; /* below gets xdr'd */ - unsigned numrecs; /* number of 'records' allocated */ - NC_array *dims; - NC_array *attrs; - NC_array *vars; - int32 hdf_file; - int file_type; - int32 vgid; - int hdf_mode; /* mode we are attached for */ + unsigned numrecs; /* number of 'records' allocated */ + NC_array *dims; + NC_array *attrs; + NC_array *vars; + int32 hdf_file; + int file_type; + int32 vgid; + int hdf_mode; /* mode we are attached for */ hdf_file_t cdf_fp; /* file pointer used for CDF files */ } NC;