1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00

5 Commits

Author SHA1 Message Date
Jens Maus
c02665938f Merge pull request #13 from sodero/topic/additional_error_codes
Add ENOTSUP error code
2021-05-14 00:38:42 +02:00
Jens Maus
1e2863c5b8 fixed README.md 2021-05-14 00:32:09 +02:00
Jens Maus
e1da3dadfb moved from travis-ci to github actions and retired codeclimate. 2021-05-14 00:31:17 +02:00
ola.soder@axis.com
b51c79577e Add ENOTSUP error code. 2021-01-20 15:34:37 +01:00
obarthel
975f949aa1 Rewritten to handle date ranges better which lie outside the expected time of day, day of month and month.
The 'struct tm' is now properly updated to reflect the time and date information which comes out of the number of seconds calculated.

A bug reported by Andreas Falkenhahn is resolved which had the effect of distorting the number of seconds calculated.
2020-07-06 12:09:51 +02:00
8 changed files with 167 additions and 156 deletions

View File

@@ -1,14 +0,0 @@
---
engines:
duplication:
enabled: false
fixme:
enabled: true
markdownlint:
enabled: true
ratings:
paths:
- "**.c"
- "**.h"
- "**.l"
- "**.md"

54
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,54 @@
name: CI
on:
push:
pull_request:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-20.04
timeout-minutes: 480
strategy:
fail-fast: false
matrix:
platform: [os4, os3]
steps:
- uses: actions/checkout@v2
- name: setup dependencies
run: |
sudo dpkg --add-architecture i386
sudo apt-get update -y -qq || true
sudo apt-get -qq install libc6:i386
sudo ln -s /usr/lib/x86_64-linux-gnu/libmpfr.so.6 /usr/lib/x86_64-linux-gnu/libmpfr.so.4
- name: setup env
run : |
echo "GITHUB_SHA7=$(echo ${GITHUB_SHA::7})" >>$GITHUB_ENV
- name: install adtools build env
run: |
DOWNLOAD_PATH=https://github.com/adtools/adtools/releases/download/20170213
curl -L ${DOWNLOAD_PATH}/adtools-utils.tar.bz2 | sudo tar xj -C /
if [[ ${{ matrix.platform }} =~ os3 ]]; then curl -L ${DOWNLOAD_PATH}/adtools-m68k-amigaos.tar.bz2 | sudo tar xj -C / ; fi
if [[ ${{ matrix.platform }} =~ os4 ]]; then curl -L ${DOWNLOAD_PATH}/adtools-ppc-amigaos.tar.bz2 | sudo tar xj -C / ; fi
if [[ ${{ matrix.platform }} =~ mos ]]; then curl -L ${DOWNLOAD_PATH}/adtools-ppc-morphos.tar.bz2 | sudo tar xj -C / ; fi
if [[ ${{ matrix.platform }} =~ aros-ppc ]]; then curl -L ${DOWNLOAD_PATH}/adtools-ppc-aros.tar.bz2 | sudo tar xj -C / ; fi
if [[ ${{ matrix.platform }} =~ aros-i386 ]]; then curl -L ${DOWNLOAD_PATH}/adtools-i386-aros.tar.bz2 | sudo tar xj -C / ; fi
if [[ ${{ matrix.platform }} =~ aros-x86_64 ]]; then curl -L ${DOWNLOAD_PATH}/adtools-x86_64-aros.tar.bz2 | sudo tar xj -C / ; fi
- name: cleanup old action artifacts
run: .github/workflows/purge_artifacts.sh ${{ secrets.GITHUB_TOKEN }}
#- name: remote debug tmate session
# uses: mxschmitt/action-tmate@v1
# if: matrix.platform == 'os4'
- name: build [${{ matrix.platform }}]
timeout-minutes: 480
run: |
export PATH=/usr/local/amiga/bin:/opt/m68k-amigaos/bin:/opt/ppc-amigaos/bin:/opt/ppc-morphos/bin:${PATH}
if [[ ${{ matrix.platform }} =~ os4 ]]; then make -C library -j1 -f GNUmakefile.os4 OS=os4 ; fi
if [[ ${{ matrix.platform }} =~ os3 ]]; then make -C library -j1 -f GNUmakefile.68k OS=os3 ; fi

55
.github/workflows/purge_artifacts.sh vendored Executable file
View File

@@ -0,0 +1,55 @@
#!/usr/bin/env bash
# Customize those three lines with your repository and credentials:
REPO=https://api.github.com/repos/${GITHUB_REPOSITORY}
GITHUB_USER=${GITHUB_REPOSITORY%%/*}
GITHUB_TOKEN=${1}
# Number of most recent versions to keep for each artifact:
KEEP=4
# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user $GITHUB_USER:$GITHUB_TOKEN "$@"; }
# A temporary file which receives HTTP response headers.
TMPFILE=/tmp/tmp.$$
# An associative array, key: artifact name, value: number of artifacts of that name.
declare -A ARTCOUNT
# Process all artifacts on this repository, loop on returned "pages".
URL=$REPO/actions/artifacts
while [[ -n "$URL" ]]; do
# Get current page, get response headers in a temporary file.
JSON=$(ghapi --dump-header $TMPFILE "$URL")
# Get URL of next page. Will be empty if we are at the last page.
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
rm -f ${TMPFILE}
# Number of artifacts on this page:
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))
# Loop on all artifacts on this page.
for ((i=0; $i < $COUNT; i++)); do
# Get name of artifact and count instances of this name.
STR=$(jq <<<$JSON -r ".artifacts[$i].name?")
name=${STR%%-*}-${STR##*-}
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))
printf "Found '%s' #%d, " $STR ${ARTCOUNT[$name]}
# Check if we must delete this one.
if [[ ${ARTCOUNT[$name]} -gt $KEEP ]]; then
id=$(jq <<<$JSON -r ".artifacts[$i].id?")
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
printf "deleting %d bytes\n" $size
ghapi -X DELETE $REPO/actions/artifacts/$id
else
printf "OK\n"
fi
done
done
exit 0

View File

@@ -1,36 +0,0 @@
sudo: required
dist: trusty
language: c
# download and install our required cross compilers
install:
# Make sure we can install i386 packages as some adtools binaries
# requires i386 libraries being installed to work in the 64bit env
# of Travis
- sudo dpkg --add-architecture i386
- sudo apt-get -qq update || true
- sudo apt-get -qq install libc6:i386
# Install all adtools related stuff we need
- curl -L https://dl.bintray.com/jens-maus/adtools/adtools-utils.tar.bz2 | sudo tar xj -C /
- if [[ ${BUILD} =~ os3|release ]]; then curl -L https://dl.bintray.com/jens-maus/adtools/adtools-m68k-amigaos.tar.bz2 | sudo tar xj -C / ; fi
- if [[ ${BUILD} =~ os4|release ]]; then curl -L https://dl.bintray.com/jens-maus/adtools/adtools-ppc-amigaos.tar.bz2 | sudo tar xj -C / ; fi
- if [[ ${BUILD} =~ mos|release ]]; then curl -L https://dl.bintray.com/jens-maus/adtools/adtools-ppc-morphos.tar.bz2 | sudo tar xj -C / ; fi
- if [[ ${BUILD} =~ aros-ppc|release ]]; then curl -L https://dl.bintray.com/jens-maus/adtools/adtools-ppc-aros.tar.bz2 | sudo tar xj -C / ; fi
- if [[ ${BUILD} =~ aros-i386|release ]]; then curl -L https://dl.bintray.com/jens-maus/adtools/adtools-i386-aros.tar.bz2 | sudo tar xj -C / ; fi
- if [[ ${BUILD} =~ aros-x86_64|release ]]; then curl -L https://dl.bintray.com/jens-maus/adtools/adtools-x86_64-aros.tar.bz2 | sudo tar xj -C / ; fi
- if [[ ${BUILD} =~ mingw32|release ]]; then sudo apt-get -qq install binutils-mingw-w64-i686 gcc-mingw-w64-i686 ; fi
# set the PATH variable to the directories the cross compilers are installed.
before_script:
- export PATH=/usr/local/amiga/bin:/opt/m68k-amigaos/bin:/opt/ppc-amigaos/bin:/opt/ppc-morphos/bin:${PATH}
# specify a list of variables to test (here we test the build for our supported
# list of operating systems).
env:
- BUILD="-f GNUmakefile.68k OS=os3"
- BUILD="-f GNUmakefile.os4 OS=os4"
# the build command to execute for each test
script:
- make -C library -j1 ${BUILD}

View File

@@ -1,9 +1,7 @@
# clib2 An ISO 'C' (1994) compliant runtime library for AmigaOS
[![Build Status](https://travis-ci.org/adtools/clib2.svg?branch=master)](https://travis-ci.org/adtools/clib2)
[![Code Climate](https://codeclimate.com/github/adtools/clib2/badges/gpa.svg)](https://codeclimate.com/github/adtools/clib2)
[![Build](https://github.com/adtools/clib2/workflows/CI/badge.svg)](https://github.com/adtools/clib2/actions)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Github Issues](http://githubbadges.herokuapp.com/adtools/clib2/issues.svg)](https://github.com/adtools/clib2/issues)
## What is this?

View File

@@ -166,6 +166,8 @@ extern int errno;
#define EILSEQ 85 /* Encoding error detected */
#define ENOTSUP 86 /* Not supported */
/****************************************************************************/
#ifdef __cplusplus

View File

@@ -41,7 +41,7 @@
/****************************************************************************/
static const char * error_table[EILSEQ - EPERM + 1] =
static const char * error_table[ENOTSUP - EPERM + 1] =
{
"Operation not permitted",
"No such file or directory",
@@ -127,7 +127,8 @@ static const char * error_table[EILSEQ - EPERM + 1] =
"Identifier removed",
"No message of the desired type.",
"Value too large to be stored in data type.",
"Encoding error detected"
"Encoding error detected",
"Not supported"
};
/****************************************************************************/
@@ -139,7 +140,7 @@ strerror_r(int number,char * buffer,size_t buffer_size)
const char * str;
size_t len;
if(number < EPERM || number > EILSEQ)
if(number < EPERM || number > ENOTSUP)
{
__set_errno(EINVAL);
goto out;

View File

@@ -1,5 +1,5 @@
/*
* $Id: time_mktime.c,v 1.10 2006-01-08 12:04:27 obarthel Exp $
* $Id: time_mktime.c,v 1.11 2015-06-26 11:22:00 obarthel Exp $
*
* :ts=4
*
@@ -52,9 +52,10 @@ mktime(struct tm *tm)
{
DECLARE_UTILITYBASE();
struct ClockData clock_data;
ULONG seconds, delta;
ULONG seconds;
time_t result = (time_t)-1;
int max_month_days;
LONG combined_seconds;
int month, year;
ENTER();
@@ -73,116 +74,63 @@ mktime(struct tm *tm)
}
#endif /* CHECK_FOR_NULL_POINTERS */
/* The month must be valid. */
if(tm->tm_mon < 0 || tm->tm_mon > 11)
/* Normalize the year and month. */
year = tm->tm_year + 1900;
month = tm->tm_mon + 1;
if(month < 0 || month > 12)
{
SHOWVALUE(tm->tm_mon);
SHOWMSG("invalid month");
goto out;
int y;
y = month / 12;
month -= y * 12;
year += y;
}
/* The day of the month must be valid. */
if(tm->tm_mday < 1 || tm->tm_mday > 31)
if(month < 1)
{
SHOWVALUE(tm->tm_mday);
SHOWMSG("invalid day of month");
goto out;
month += 12;
year -= 1;
}
/* The year must be valid. */
if(tm->tm_year < 78)
/* The year must be valid. Amiga time begins with January 1st, 1978. */
if(year < 1978)
{
SHOWVALUE(tm->tm_year);
SHOWVALUE(year);
SHOWMSG("invalid year");
goto out;
}
/* Is this the month of February? */
if(tm->tm_mon == 1)
{
int year;
/* We need to have the full year number for the
leap year calculation below. */
year = tm->tm_year + 1900;
/* Now for the famous leap year calculation rules... In
the given year, how many days are there in the month
of February? */
if((year % 4) != 0)
max_month_days = 28;
else if ((year % 400) == 0)
max_month_days = 29;
else if ((year % 100) == 0)
max_month_days = 28;
else
max_month_days = 29;
}
else
{
static const char days_per_month[12] =
{
31, 0,31,
30,31,30,
31,31,30,
31,30,31
};
max_month_days = days_per_month[tm->tm_mon];
}
/* The day of the month must be valid. */
if(tm->tm_mday < 0 || tm->tm_mday > max_month_days)
{
SHOWVALUE(tm->tm_mday);
SHOWMSG("invalid day of month");
goto out;
}
/* The hour must be valid. */
if(tm->tm_hour < 0 || tm->tm_hour > 23)
{
SHOWVALUE(tm->tm_hour);
SHOWMSG("invalid hour");
goto out;
}
/* The minute must be valid. */
if(tm->tm_min < 0 || tm->tm_min > 59)
{
SHOWVALUE(tm->tm_min);
SHOWMSG("invalid minute");
goto out;
}
/* Note: the number of seconds can be larger than 59
in order to account for leap seconds. */
if(tm->tm_sec < 0 || tm->tm_sec > 60)
{
SHOWVALUE(tm->tm_sec);
SHOWMSG("invalid seconds");
goto out;
}
clock_data.sec = (tm->tm_sec > 59) ? 59 : tm->tm_sec;
clock_data.min = tm->tm_min;
clock_data.hour = tm->tm_hour;
clock_data.mday = tm->tm_mday;
clock_data.month = tm->tm_mon + 1;
clock_data.year = tm->tm_year + 1900;
seconds = Date2Amiga(&clock_data) + (tm->tm_sec - 59);
/* The AmigaOS "epoch" starts with January 1st, 1978, which was
a Sunday. */
tm->tm_wday = (seconds / (24 * 60 * 60)) % 7;
/* Convert the first day of the month in the given year
into the corresponding number of seconds. */
memset(&clock_data, 0, sizeof(clock_data));
clock_data.mday = 1;
clock_data.month = 1;
clock_data.month = month;
clock_data.year = year;
delta = Date2Amiga(&clock_data);
seconds = Date2Amiga(&clock_data);
tm->tm_yday = (seconds - delta) / (24 * 60 * 60);
/* Put the combined number of seconds involved together,
covering the seconds/minutes/hours of the day as well
as the number of days of the month. This will be added
to the number of seconds for the date. */
combined_seconds = tm->tm_sec + 60 * (tm->tm_min + 60 * (tm->tm_hour + 24 * (tm->tm_mday-1)));
/* If the combined number of seconds is negative, adding it
* to the number of seconds for the date should not produce
* a negative value.
*/
if(combined_seconds < 0 && seconds < (ULONG)(-combined_seconds))
{
SHOWVALUE(seconds);
SHOWVALUE(combined_seconds);
SHOWMSG("invalid combined number of seconds");
goto out;
}
seconds += combined_seconds;
__locale_lock();
@@ -193,10 +141,13 @@ mktime(struct tm *tm)
__locale_unlock();
/* Finally, adjust for the difference between the Unix and the
/* Adjust for the difference between the Unix and the
AmigaOS epochs, which differ by 8 years. */
result = seconds + UNIX_TIME_OFFSET;
/* Finally, normalize the provided time and date information. */
localtime_r(&result, tm);
out:
RETURN(result);