diff --git a/.github/workflows/build_macos.yml b/.github/workflows/build_macos.yml new file mode 100644 index 0000000..c0d808d --- /dev/null +++ b/.github/workflows/build_macos.yml @@ -0,0 +1,37 @@ +# Build from source. +name: build_macos +on: [push, pull_request] +permissions: read-all +jobs: + build_ubuntu: + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: macos-12 + configure_options: '' + - os: macos-13 + configure_options: '' + - os: macos-14 + configure_options: '' + - os: macos-15 + configure_options: '' + steps: + - uses: actions/checkout@v4 + - name: Install build dependencies + run: | + brew update -q + brew install -q autoconf automake gettext gnu-sed libtool pkg-config || true + brew link --force gettext + ln -s /usr/local/bin/glibtoolize /usr/local/bin/libtoolize + - name: Download test data + run: | + if test -x "synctestdata.sh"; then ./synctestdata.sh; fi + - name: Building from source + env: + CC: ${{ matrix.compiler }} + run: | + tests/build.sh ${{ matrix.configure_options }} + - name: Run tests + run: | + tests/runtests.sh diff --git a/acinclude.m4 b/acinclude.m4 index a679681..3c725c8 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -1,6 +1,6 @@ dnl Checks for required headers and functions dnl -dnl Version: 20240413 +dnl Version: 20240518 dnl Function to detect if libfdatetime dependencies are available AC_DEFUN([AX_LIBFDATETIME_CHECK_LOCAL], diff --git a/appveyor.yml b/appveyor.yml index bfe6013..6062ebc 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -72,7 +72,7 @@ environment: PYTHON_PATH: "C:\\Python311" - TARGET: macos-x64-clang BUILD_ENVIRONMENT: xcode - APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey + APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma HOMEBREW_NO_INSTALL_CLEANUP: 1 CC: clang CFLAGS: "-I/usr/local/include" @@ -80,7 +80,7 @@ environment: CONFIGURE_OPTIONS: "" - TARGET: macos-x64-gcc BUILD_ENVIRONMENT: xcode - APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey + APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma HOMEBREW_NO_INSTALL_CLEANUP: 1 CC: gcc CFLAGS: "-I/usr/local/include" @@ -88,7 +88,7 @@ environment: CONFIGURE_OPTIONS: "" - TARGET: macos-pkgbuild BUILD_ENVIRONMENT: xcode - APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey + APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma HOMEBREW_NO_INSTALL_CLEANUP: 1 CONFIGURE_OPTIONS: "--disable-dependency-tracking --prefix=/usr/local --with-pyprefix" - TARGET: cygwin64-gcc diff --git a/autogen.ps1 b/autogen.ps1 index fd3f68b..f39c5f1 100644 --- a/autogen.ps1 +++ b/autogen.ps1 @@ -1,12 +1,12 @@ # Script to generate the necessary files for a msvscpp build # -# Version: 20240306 +# Version: 20241014 $WinFlex = "..\win_flex_bison\win_flex.exe" $WinBison = "..\win_flex_bison\win_bison.exe" -$Library = Get-Content -Path configure.ac | select -skip 3 -first 1 | % { $_ -Replace " \[","" } | % { $_ -Replace "\],","" } -$Version = Get-Content -Path configure.ac | select -skip 4 -first 1 | % { $_ -Replace " \[","" } | % { $_ -Replace "\],","" } +$Library = Get-Content -Path configure.ac | select -skip 3 -first 1 | % { $_ -Replace " \[","" } | % { $_ -Replace "\],","" } +$Version = Get-Content -Path configure.ac | select -skip 4 -first 1 | % { $_ -Replace " \[","" } | % { $_ -Replace "\],","" } $Prefix = ${Library}.Substring(3) Get-Content -Path "include\${Library}.h.in" | Out-File -Encoding ascii "include\${Library}.h" diff --git a/autogen.sh b/autogen.sh index 83f54ea..bd307d2 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,32 +1,38 @@ #!/bin/sh -# Script to generate ./configure using the autotools +# Script to generate configure and Makefile using the autotools. # -# Version: 20230405 +# Version: 20241013 EXIT_SUCCESS=0; EXIT_FAILURE=1; -BINDIR="/usr/bin"; +BINDIR=`which aclocal`; +BINDIR=`dirname ${BINDIR}`; -if ! test -x "${BINDIR}/aclocal"; +if ! test -x "${BINDIR}/aclocal" && test "${BINDIR}" != "/usr/bin"; then - BINDIR="/usr/local/bin"; + BINDIR="/usr/bin"; fi -if ! test -x "${BINDIR}/aclocal"; +if ! test -x "${BINDIR}/aclocal" && test "${BINDIR}" != "/usr/local/bin"; then BINDIR="/usr/local/bin"; fi -if ! test -x "${BINDIR}/aclocal"; +if ! test -x "${BINDIR}/aclocal" && test "${BINDIR}" != "/opt/local/bin"; then # Default location of MacPorts installed binaries. BINDIR="/opt/local/bin"; fi -if ! test -x "${BINDIR}/aclocal"; +if ! test -x "${BINDIR}/aclocal" && test "${BINDIR}" != "/opt/homebrew/bin"; +then + # Default location of Homebrew installed binaries. + BINDIR="/opt/homebrew/bin"; +fi +if ! test -x "${BINDIR}/aclocal" && test "${BINDIR}" != "/mingw32/bin"; then # Default location of 32-bit MSYS2-MinGW installed binaries. BINDIR="/mingw32/bin"; fi -if ! test -x "${BINDIR}/aclocal"; +if ! test -x "${BINDIR}/aclocal" && test "${BINDIR}" != "/mingw64/bin"; then # Default location of 64-bit MSYS2-MinGW installed binaries. BINDIR="/mingw64/bin"; @@ -91,35 +97,30 @@ else exit ${EXIT_FAILURE}; fi - if ! test -x "${AUTOCONF}"; then echo "Unable to find: autoconf"; exit ${EXIT_FAILURE}; fi - if ! test -x "${AUTOHEADER}"; then echo "Unable to find: autoheader"; exit ${EXIT_FAILURE}; fi - if ! test -x "${AUTOMAKE}"; then echo "Unable to find: automake"; exit ${EXIT_FAILURE}; fi - if ! test -x "${AUTOPOINT}"; then echo "Unable to find: autopoint"; exit ${EXIT_FAILURE}; fi - if ! test -x "${LIBTOOLIZE}"; then echo "Unable to find: libtoolize"; diff --git a/configure.ac b/configure.ac index 1af4522..ffe7492 100644 --- a/configure.ac +++ b/configure.ac @@ -1,12 +1,12 @@ AC_PREREQ([2.71]) AC_INIT( - [libfdatetime], - [20240518], - [joachim.metz@gmail.com]) + [libfdatetime], + [20241214], + [joachim.metz@gmail.com]) AC_CONFIG_SRCDIR( - [include/libfdatetime.h.in]) + [include/libfdatetime.h.in]) AM_INIT_AUTOMAKE([gnu 1.6 tar-ustar]) AM_EXTRA_RECURSIVE_TARGETS([sources splint]) @@ -71,21 +71,21 @@ CFLAGS="$CFLAGS -Wall"; dnl Check if requires and build requires should be set in spec file AS_IF( - [test "x$ac_cv_libcerror" = xyes], - [AC_SUBST( - [libfdatetime_spec_requires], - [Requires:]) - ]) + [test "x$ac_cv_libcerror" = xyes], + [AC_SUBST( + [libfdatetime_spec_requires], + [Requires:]) + ]) dnl Set the date for the dpkg files AC_SUBST( - [DPKG_DATE], - [`date -R 2> /dev/null`]) + [DPKG_DATE], + [`date -R 2> /dev/null`]) dnl Set the date for the spec file AC_SUBST( - [SPEC_DATE], - [`date +"%a %b %e %Y" 2> /dev/null`]) + [SPEC_DATE], + [`date +"%a %b %e %Y" 2> /dev/null`]) dnl Generate Makefiles AC_CONFIG_FILES([Makefile]) diff --git a/libfdatetime/libfdatetime_posix_time.c b/libfdatetime/libfdatetime_posix_time.c index c2fb0e2..e33859a 100644 --- a/libfdatetime/libfdatetime_posix_time.c +++ b/libfdatetime/libfdatetime_posix_time.c @@ -576,6 +576,8 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( { static char *function = "libfdatetime_internal_posix_time_copy_to_date_time_values"; uint64_t posix_timestamp = 0; + uint64_t remaining_years = 0; + uint32_t days_in_century = 0; uint16_t days_in_year = 0; uint8_t days_in_month = 0; uint8_t is_signed = 0; @@ -627,7 +629,21 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( { is_signed = (uint8_t) ( posix_timestamp >> 31 ); - posix_timestamp &= 0x7fffffffUL; + if( is_signed != 0 ) + { + if( ( posix_timestamp & 0x7fffffffUL ) == 0 ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: unsupported timestamp.", + function ); + + return( -1 ); + } + posix_timestamp = -( (int32_t) posix_timestamp ); + } } else if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_SIGNED ) || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_SECONDS_64BIT_UNSIGNED ) @@ -638,23 +654,25 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( { is_signed = (uint8_t) ( posix_timestamp >> 63 ); + if( is_signed != 0 ) + { #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 ) - posix_timestamp &= 0x7fffffffffffffffUL; + if( ( posix_timestamp & 0x7fffffffffffffffUL ) == 0 ) #else - posix_timestamp &= 0x7fffffffffffffffULL; + if( ( posix_timestamp & 0x7fffffffffffffffULL ) == 0 ) #endif - } - if( ( is_signed != 0 ) - && ( posix_timestamp == 0 ) ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_RUNTIME, - LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, - "%s: unsupported timestamp.", - function ); - - return( -1 ); + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_RUNTIME, + LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, + "%s: unsupported timestamp.", + function ); + + return( -1 ); + } + posix_timestamp = -( (int64_t) posix_timestamp ); + } } date_time_values->nano_seconds = 0; @@ -663,15 +681,14 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( { /* The timestamp is in units of nano seconds correct the value to seconds */ - if( is_signed == 0 ) - { - date_time_values->nano_seconds = posix_timestamp % 1000; - } - else + date_time_values->nano_seconds = posix_timestamp % 1000; + posix_timestamp /= 1000; + + if( ( is_signed != 0 ) + && ( date_time_values->nano_seconds > 0 ) ) { - date_time_values->nano_seconds = 1000 - ( posix_timestamp % 1000 ); + date_time_values->nano_seconds = 999 - date_time_values->nano_seconds; } - posix_timestamp /= 1000; } if( ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_SIGNED ) || ( internal_posix_time->value_type == LIBFDATETIME_POSIX_TIME_VALUE_TYPE_MICRO_SECONDS_64BIT_UNSIGNED ) @@ -680,31 +697,32 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( { /* The timestamp is in units of micro seconds correct the value to seconds */ - if( is_signed == 0 ) - { - date_time_values->micro_seconds = posix_timestamp % 1000; - } - else - { - date_time_values->micro_seconds = 1000 - ( posix_timestamp % 1000 ); - } + date_time_values->micro_seconds = posix_timestamp % 1000; posix_timestamp /= 1000; - if( is_signed == 0 ) + if( ( is_signed != 0 ) + && ( date_time_values->micro_seconds > 0 ) ) { - date_time_values->milli_seconds = posix_timestamp % 1000; + date_time_values->micro_seconds = 999 - date_time_values->micro_seconds; } - else + date_time_values->milli_seconds = posix_timestamp % 1000; + posix_timestamp /= 1000; + + if( ( is_signed != 0 ) + && ( date_time_values->milli_seconds > 0 ) ) { - date_time_values->milli_seconds = 1000 - ( posix_timestamp % 1000 ); + date_time_values->milli_seconds = 999 - date_time_values->milli_seconds; } - posix_timestamp /= 1000; } else { date_time_values->micro_seconds = 0; date_time_values->milli_seconds = 0; } + if( is_signed != 0 ) + { + posix_timestamp -= 1; + } /* There are 60 seconds in a minute correct the value to minutes */ date_time_values->seconds = posix_timestamp % 60; @@ -713,7 +731,7 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( if( ( is_signed != 0 ) && ( date_time_values->seconds > 0 ) ) { - date_time_values->seconds = 60 - date_time_values->seconds; + date_time_values->seconds = 59 - date_time_values->seconds; } /* There are 60 minutes in an hour correct the value to hours */ @@ -723,7 +741,7 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( if( ( is_signed != 0 ) && ( date_time_values->minutes > 0 ) ) { - date_time_values->minutes = 60 - date_time_values->minutes; + date_time_values->minutes = 59 - date_time_values->minutes; } /* There are 24 hours in a day correct the value to days */ @@ -733,7 +751,7 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( if( ( is_signed != 0 ) && ( date_time_values->hours > 0 ) ) { - date_time_values->hours = 24 - date_time_values->hours; + date_time_values->hours = 23 - date_time_values->hours; } /* Determine the number of years starting at 'Jan 1, 1970 00:00:00' * correct the value to days within the year @@ -757,11 +775,70 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( } else { - /* Remove 1 day to compensate that Jan 1, 1970 is represented as 0 + date_time_values->year = 1969; + } + remaining_years = posix_timestamp % 100; + + while( remaining_years > 0 ) + { + /* Check for a leap year + * The year is ( ( dividable by 4 ) and ( not dividable by 100 ) ) or ( dividable by 400 ) + */ + if( ( ( ( date_time_values->year % 4 ) == 0 ) + && ( ( date_time_values->year % 100 ) != 0 ) ) + || ( ( date_time_values->year % 400 ) == 0 ) ) + { + days_in_year = 366; + } + else + { + days_in_year = 365; + } + if( posix_timestamp <= days_in_year ) + { + break; + } + posix_timestamp -= days_in_year; + + if( is_signed == 0 ) + { + date_time_values->year += 1; + } + else + { + date_time_values->year -= 1; + } + remaining_years -= 1; + } + while( posix_timestamp > 0 ) + { + /* Check for a leap year + * The year is ( ( dividable by 4 ) and ( not dividable by 100 ) ) or ( dividable by 400 ) */ - posix_timestamp -= 1; + if( ( ( ( date_time_values->year % 4 ) == 0 ) + && ( ( date_time_values->year % 100 ) != 0 ) ) + || ( ( date_time_values->year % 400 ) == 0 ) ) + { + days_in_century = 36525; + } + else + { + days_in_century = 36524; + } + if( posix_timestamp <= days_in_century ) + { + break; + } + posix_timestamp -= days_in_century; - date_time_values->year = 1969; + if( is_signed == 0 ) + { + date_time_values->year += 100; + } + else + { + date_time_values->year -= 100; + } } while( posix_timestamp > 0 ) { @@ -793,7 +870,6 @@ int libfdatetime_internal_posix_time_copy_to_date_time_values( date_time_values->year -= 1; } } - /* Determine the month correct the value to days within the month */ if( is_signed == 0 ) diff --git a/m4/common.m4 b/m4/common.m4 index c2ea816..c229b79 100644 --- a/m4/common.m4 +++ b/m4/common.m4 @@ -1,6 +1,6 @@ dnl Checks for common headers and functions dnl -dnl Version: 20240513 +dnl Version: 20241013 dnl Function to test if a certain feature was disabled AC_DEFUN([AX_COMMON_ARG_DISABLE], @@ -113,7 +113,7 @@ AC_DEFUN([AX_COMMON_CHECK_ENABLE_VERBOSE_OUTPUT], ac_cv_enable_verbose_output=yes]) ]) -dnl Function to detect whether static executables support should be enabled +dnl Function to detect whether wide character type support should be enabled AC_DEFUN([AX_COMMON_CHECK_ENABLE_WIDE_CHARACTER_TYPE], [AX_COMMON_ARG_ENABLE( [wide-character-type], diff --git a/tests/pkgbuild.sh b/tests/pkgbuild.sh index fddfd6e..67b8bb3 100755 --- a/tests/pkgbuild.sh +++ b/tests/pkgbuild.sh @@ -1,7 +1,7 @@ #!/bin/sh # Script to build a MacOS pkg # -# Version: 20201121 +# Version: 20241015 set -e @@ -9,6 +9,6 @@ make install DESTDIR=${PWD}/osx-pkg mkdir -p ${PWD}/osx-pkg/usr/share/doc/libfdatetime cp AUTHORS COPYING COPYING.LESSER NEWS README ${PWD}/osx-pkg/usr/share/doc/libfdatetime -VERSION=`sed '5!d; s/^ \[//;s/\],$//' configure.ac` +VERSION=`sed '5!d; s/^ \[//;s/\],$//' configure.ac` pkgbuild --root osx-pkg --identifier com.github.libyal.libfdatetime --version ${VERSION} --ownership recommended ../libfdatetime-${VERSION}.pkg