mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Split the reentrant functions from the non-reentrant ones.
git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14774 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: GNUmakefile.68k,v 1.16 2004-11-14 11:43:30 obarthel Exp $
|
||||
# $Id: GNUmakefile.68k,v 1.17 2004-11-18 09:40:37 obarthel Exp $
|
||||
#
|
||||
# :ts=8
|
||||
#
|
||||
@ -354,15 +354,20 @@ C_LIB = \
|
||||
string_strspn.o \
|
||||
string_strstr.o \
|
||||
string_strtok.o \
|
||||
string_strtok_r.o \
|
||||
string_strxfrm.o \
|
||||
time_asctime.o \
|
||||
time_asctime_r.o \
|
||||
time_clock.o \
|
||||
time_converttime.o \
|
||||
time_ctime.o \
|
||||
time_ctime_r.o \
|
||||
time_data.o \
|
||||
time_gettimeofday.o \
|
||||
time_gmtime.o \
|
||||
time_gmtime_r.o \
|
||||
time_localtime.o \
|
||||
time_localtime_r.o \
|
||||
time_mktime.o \
|
||||
time_numbertostring.o \
|
||||
time_strftime.o \
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: GNUmakefile.os4,v 1.14 2004-11-14 11:06:27 obarthel Exp $
|
||||
# $Id: GNUmakefile.os4,v 1.15 2004-11-18 09:40:37 obarthel Exp $
|
||||
#
|
||||
# :ts=8
|
||||
#
|
||||
@ -352,15 +352,20 @@ C_LIB = \
|
||||
string_strspn.o \
|
||||
string_strstr.o \
|
||||
string_strtok.o \
|
||||
string_strtok_r.o \
|
||||
string_strxfrm.o \
|
||||
time_asctime.o \
|
||||
time_asctime_r.o \
|
||||
time_clock.o \
|
||||
time_converttime.o \
|
||||
time_ctime.o \
|
||||
time_ctime_r.o \
|
||||
time_data.o \
|
||||
time_gettimeofday.o \
|
||||
time_gmtime.o \
|
||||
time_gmtime_r.o \
|
||||
time_localtime.o \
|
||||
time_localtime_r.o \
|
||||
time_mktime.o \
|
||||
time_numbertostring.o \
|
||||
time_strftime.o \
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#
|
||||
# $Id: smakefile,v 1.11 2004-11-14 11:06:27 obarthel Exp $
|
||||
# $Id: smakefile,v 1.12 2004-11-18 09:40:37 obarthel Exp $
|
||||
#
|
||||
# :ts=8
|
||||
#
|
||||
@ -457,6 +457,7 @@ STRING_OBJ = \
|
||||
string_strspn.o \
|
||||
string_strstr.o \
|
||||
string_strtok.o \
|
||||
string_strtok_r.o \
|
||||
string_strxfrm.o
|
||||
|
||||
STRINGS_OBJ = \
|
||||
@ -465,14 +466,18 @@ STRINGS_OBJ = \
|
||||
|
||||
TIME_OBJ = \
|
||||
time_asctime.o \
|
||||
time_asctime_r.o \
|
||||
time_clock.o \
|
||||
time_converttime.o \
|
||||
time_ctime.o \
|
||||
time_ctime_r.o \
|
||||
time_data.o \
|
||||
time_difftime.o \
|
||||
time_gettimeofday.o \
|
||||
time_gmtime.o \
|
||||
time_gmtime_r.o \
|
||||
time_localtime.o \
|
||||
time_localtime_r.o \
|
||||
time_mktime.o \
|
||||
time_numbertostring.o \
|
||||
time_strftime.o \
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: string_strtok.c,v 1.3 2004-11-17 19:07:22 obarthel Exp $
|
||||
* $Id: string_strtok.c,v 1.4 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -43,76 +43,6 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
strtok_r(char *str, const char *separator_set,char ** state_ptr)
|
||||
{
|
||||
char * result = NULL;
|
||||
char * last;
|
||||
size_t size;
|
||||
|
||||
assert( separator_set != NULL && state_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(separator_set == NULL || state_ptr == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
last = (*state_ptr);
|
||||
|
||||
/* Did we get called before? Restart at the last valid position. */
|
||||
if(str == NULL)
|
||||
{
|
||||
str = last;
|
||||
|
||||
/* However, we may have hit the end of the
|
||||
string already. */
|
||||
if(str == NULL)
|
||||
goto out;
|
||||
}
|
||||
|
||||
last = NULL;
|
||||
|
||||
/* Skip the characters which count as
|
||||
separators. */
|
||||
str += strspn(str, separator_set);
|
||||
if((*str) == '\0')
|
||||
goto out;
|
||||
|
||||
/* Count the number of characters which aren't
|
||||
separators. */
|
||||
size = strcspn(str, separator_set);
|
||||
if(size == 0)
|
||||
goto out;
|
||||
|
||||
/* This is where the search can resume later. */
|
||||
last = &str[size];
|
||||
|
||||
/* If we didn't hit the end of the string already,
|
||||
skip the separator. */
|
||||
if((*last) != '\0')
|
||||
last++;
|
||||
|
||||
/* This is the token we found; make sure that
|
||||
it looks like a valid string. */
|
||||
str[size] = '\0';
|
||||
|
||||
result = str;
|
||||
|
||||
out:
|
||||
|
||||
if(state_ptr != NULL)
|
||||
(*state_ptr) = last;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
strtok(char *str, const char *separator_set)
|
||||
{
|
||||
|
||||
112
library/string_strtok_r.c
Normal file
112
library/string_strtok_r.c
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* $Id: string_strtok_r.c,v 1.1 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
||||
* Copyright (c) 2002-2004 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* 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.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of 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 OWNER 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.
|
||||
*/
|
||||
|
||||
#ifndef _STDLIB_NULL_POINTER_CHECK_H
|
||||
#include "stdlib_null_pointer_check.h"
|
||||
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _STRING_HEADERS_H
|
||||
#include "string_headers.h"
|
||||
#endif /* _STRING_HEADERS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
strtok_r(char *str, const char *separator_set,char ** state_ptr)
|
||||
{
|
||||
char * result = NULL;
|
||||
char * last;
|
||||
size_t size;
|
||||
|
||||
assert( separator_set != NULL && state_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(separator_set == NULL || state_ptr == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
last = (*state_ptr);
|
||||
|
||||
/* Did we get called before? Restart at the last valid position. */
|
||||
if(str == NULL)
|
||||
{
|
||||
str = last;
|
||||
|
||||
/* However, we may have hit the end of the
|
||||
string already. */
|
||||
if(str == NULL)
|
||||
goto out;
|
||||
}
|
||||
|
||||
last = NULL;
|
||||
|
||||
/* Skip the characters which count as
|
||||
separators. */
|
||||
str += strspn(str, separator_set);
|
||||
if((*str) == '\0')
|
||||
goto out;
|
||||
|
||||
/* Count the number of characters which aren't
|
||||
separators. */
|
||||
size = strcspn(str, separator_set);
|
||||
if(size == 0)
|
||||
goto out;
|
||||
|
||||
/* This is where the search can resume later. */
|
||||
last = &str[size];
|
||||
|
||||
/* If we didn't hit the end of the string already,
|
||||
skip the separator. */
|
||||
if((*last) != '\0')
|
||||
last++;
|
||||
|
||||
/* This is the token we found; make sure that
|
||||
it looks like a valid string. */
|
||||
str[size] = '\0';
|
||||
|
||||
result = str;
|
||||
|
||||
out:
|
||||
|
||||
if(state_ptr != NULL)
|
||||
(*state_ptr) = last;
|
||||
|
||||
return(result);
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_asctime.c,v 1.2 2004-11-17 19:07:22 obarthel Exp $
|
||||
* $Id: time_asctime.c,v 1.3 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -43,169 +43,6 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static void
|
||||
add_to_string(char * to,int to_size,const char * string,int * offset_ptr)
|
||||
{
|
||||
int offset;
|
||||
int len;
|
||||
|
||||
assert( to != NULL && to_size > 0 && string != NULL && offset_ptr != NULL );
|
||||
|
||||
offset = (*offset_ptr);
|
||||
|
||||
assert( offset < to_size );
|
||||
|
||||
len = strlen(string);
|
||||
if(offset + len > (to_size-1))
|
||||
len = (to_size-1) - offset;
|
||||
|
||||
if(len > 0)
|
||||
{
|
||||
memmove(&to[offset],string,(size_t)len);
|
||||
offset += len;
|
||||
|
||||
assert( offset < to_size );
|
||||
|
||||
to[offset] = '\0';
|
||||
|
||||
(*offset_ptr) = offset;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static char *
|
||||
__asctime_r(const struct tm *tm,char * buffer,size_t buffer_size)
|
||||
{
|
||||
struct tm copy_tm;
|
||||
char number[16];
|
||||
char * result = NULL;
|
||||
const char * b;
|
||||
int offset = 0;
|
||||
|
||||
ENTER();
|
||||
|
||||
SHOWPOINTER(tm);
|
||||
|
||||
assert( tm != NULL || buffer == NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(tm == NULL || buffer == NULL )
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
/* Fill in the week day if it's not in proper range. */
|
||||
if(tm->tm_wday < 0 || tm->tm_wday > 6)
|
||||
{
|
||||
struct tm other_tm;
|
||||
time_t seconds;
|
||||
|
||||
other_tm = (*tm);
|
||||
|
||||
seconds = mktime(&other_tm);
|
||||
if(seconds != (time_t)-1)
|
||||
{
|
||||
__convert_time(seconds,0,&other_tm);
|
||||
|
||||
copy_tm = (*tm);
|
||||
copy_tm.tm_wday = other_tm.tm_wday;
|
||||
|
||||
tm = ©_tm;
|
||||
}
|
||||
}
|
||||
|
||||
if(0 <= tm->tm_wday && tm->tm_wday <= 6)
|
||||
b = __abbreviated_week_day_names[tm->tm_wday];
|
||||
else
|
||||
b = "---";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size," ", &offset);
|
||||
|
||||
if(0 <= tm->tm_mon && tm->tm_mon <= 11)
|
||||
b = __abbreviated_month_names[tm->tm_mon];
|
||||
else
|
||||
b = "---";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size," ", &offset);
|
||||
|
||||
if(1 <= tm->tm_mday && tm->tm_mday <= 31)
|
||||
b = __number_to_string((unsigned int)tm->tm_mday,number,sizeof(number),2);
|
||||
else
|
||||
b = "--";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size," ", &offset);
|
||||
|
||||
if(0 <= tm->tm_hour && tm->tm_hour <= 23)
|
||||
b = __number_to_string((unsigned int)tm->tm_hour,number,sizeof(number),2);
|
||||
else
|
||||
b = "--";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size,":", &offset);
|
||||
|
||||
if(0 <= tm->tm_min && tm->tm_min <= 59)
|
||||
b = __number_to_string((unsigned int)tm->tm_min,number,sizeof(number),2);
|
||||
else
|
||||
b = "--";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size,":", &offset);
|
||||
|
||||
if(0 <= tm->tm_sec && tm->tm_sec <= 59)
|
||||
b = __number_to_string((unsigned int)tm->tm_sec,number,sizeof(number),2);
|
||||
else
|
||||
b = "--";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size," ", &offset);
|
||||
|
||||
if(0 <= tm->tm_year)
|
||||
b = __number_to_string((unsigned int)1900 + tm->tm_year,number,sizeof(number),0);
|
||||
else
|
||||
b = "----";
|
||||
|
||||
add_to_string(buffer,buffer_size,b,&offset);
|
||||
|
||||
SHOWSTRING(buffer);
|
||||
|
||||
add_to_string(buffer,buffer_size,"\n",&offset);
|
||||
|
||||
assert( offset < buffer_size );
|
||||
assert( strlen(buffer) < buffer_size );
|
||||
|
||||
result = buffer;
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
asctime_r(const struct tm *tm,char * buffer)
|
||||
{
|
||||
char * result;
|
||||
|
||||
ENTER();
|
||||
|
||||
result = __asctime_r(tm,buffer,40);
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
asctime(const struct tm *tm)
|
||||
{
|
||||
|
||||
205
library/time_asctime_r.c
Normal file
205
library/time_asctime_r.c
Normal file
@ -0,0 +1,205 @@
|
||||
/*
|
||||
* $Id: time_asctime_r.c,v 1.1 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
||||
* Copyright (c) 2002-2004 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* 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.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of 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 OWNER 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.
|
||||
*/
|
||||
|
||||
#ifndef _STDLIB_NULL_POINTER_CHECK_H
|
||||
#include "stdlib_null_pointer_check.h"
|
||||
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _TIME_HEADERS_H
|
||||
#include "time_headers.h"
|
||||
#endif /* _TIME_HEADERS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
static void
|
||||
add_to_string(char * to,int to_size,const char * string,int * offset_ptr)
|
||||
{
|
||||
int offset;
|
||||
int len;
|
||||
|
||||
assert( to != NULL && to_size > 0 && string != NULL && offset_ptr != NULL );
|
||||
|
||||
offset = (*offset_ptr);
|
||||
|
||||
assert( offset < to_size );
|
||||
|
||||
len = strlen(string);
|
||||
if(offset + len > (to_size-1))
|
||||
len = (to_size-1) - offset;
|
||||
|
||||
if(len > 0)
|
||||
{
|
||||
memmove(&to[offset],string,(size_t)len);
|
||||
offset += len;
|
||||
|
||||
assert( offset < to_size );
|
||||
|
||||
to[offset] = '\0';
|
||||
|
||||
(*offset_ptr) = offset;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
__asctime_r(const struct tm *tm,char * buffer,size_t buffer_size)
|
||||
{
|
||||
struct tm copy_tm;
|
||||
char number[16];
|
||||
char * result = NULL;
|
||||
const char * b;
|
||||
int offset = 0;
|
||||
|
||||
ENTER();
|
||||
|
||||
SHOWPOINTER(tm);
|
||||
|
||||
assert( tm != NULL || buffer == NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(tm == NULL || buffer == NULL )
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
/* Fill in the week day if it's not in proper range. */
|
||||
if(tm->tm_wday < 0 || tm->tm_wday > 6)
|
||||
{
|
||||
struct tm other_tm;
|
||||
time_t seconds;
|
||||
|
||||
other_tm = (*tm);
|
||||
|
||||
seconds = mktime(&other_tm);
|
||||
if(seconds != (time_t)-1)
|
||||
{
|
||||
__convert_time(seconds,0,&other_tm);
|
||||
|
||||
copy_tm = (*tm);
|
||||
copy_tm.tm_wday = other_tm.tm_wday;
|
||||
|
||||
tm = ©_tm;
|
||||
}
|
||||
}
|
||||
|
||||
if(0 <= tm->tm_wday && tm->tm_wday <= 6)
|
||||
b = __abbreviated_week_day_names[tm->tm_wday];
|
||||
else
|
||||
b = "---";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size," ", &offset);
|
||||
|
||||
if(0 <= tm->tm_mon && tm->tm_mon <= 11)
|
||||
b = __abbreviated_month_names[tm->tm_mon];
|
||||
else
|
||||
b = "---";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size," ", &offset);
|
||||
|
||||
if(1 <= tm->tm_mday && tm->tm_mday <= 31)
|
||||
b = __number_to_string((unsigned int)tm->tm_mday,number,sizeof(number),2);
|
||||
else
|
||||
b = "--";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size," ", &offset);
|
||||
|
||||
if(0 <= tm->tm_hour && tm->tm_hour <= 23)
|
||||
b = __number_to_string((unsigned int)tm->tm_hour,number,sizeof(number),2);
|
||||
else
|
||||
b = "--";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size,":", &offset);
|
||||
|
||||
if(0 <= tm->tm_min && tm->tm_min <= 59)
|
||||
b = __number_to_string((unsigned int)tm->tm_min,number,sizeof(number),2);
|
||||
else
|
||||
b = "--";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size,":", &offset);
|
||||
|
||||
if(0 <= tm->tm_sec && tm->tm_sec <= 59)
|
||||
b = __number_to_string((unsigned int)tm->tm_sec,number,sizeof(number),2);
|
||||
else
|
||||
b = "--";
|
||||
|
||||
add_to_string(buffer,buffer_size,b, &offset);
|
||||
add_to_string(buffer,buffer_size," ", &offset);
|
||||
|
||||
if(0 <= tm->tm_year)
|
||||
b = __number_to_string((unsigned int)1900 + tm->tm_year,number,sizeof(number),0);
|
||||
else
|
||||
b = "----";
|
||||
|
||||
add_to_string(buffer,buffer_size,b,&offset);
|
||||
|
||||
SHOWSTRING(buffer);
|
||||
|
||||
add_to_string(buffer,buffer_size,"\n",&offset);
|
||||
|
||||
assert( offset < buffer_size );
|
||||
assert( strlen(buffer) < buffer_size );
|
||||
|
||||
result = buffer;
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
asctime_r(const struct tm *tm,char * buffer)
|
||||
{
|
||||
char * result;
|
||||
|
||||
ENTER();
|
||||
|
||||
result = __asctime_r(tm,buffer,40);
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_ctime.c,v 1.2 2004-11-17 19:07:22 obarthel Exp $
|
||||
* $Id: time_ctime.c,v 1.3 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -43,36 +43,6 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
ctime_r(const time_t *tptr,char * buffer)
|
||||
{
|
||||
char * result = NULL;
|
||||
struct tm tm;
|
||||
|
||||
ENTER();
|
||||
|
||||
assert( tptr != NULL && buffer != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(tptr == NULL || buffer == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
result = asctime_r(localtime_r(tptr,&tm),buffer);
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
ctime(const time_t *tptr)
|
||||
{
|
||||
|
||||
72
library/time_ctime_r.c
Normal file
72
library/time_ctime_r.c
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* $Id: time_ctime_r.c,v 1.1 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
||||
* Copyright (c) 2002-2004 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* 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.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of 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 OWNER 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.
|
||||
*/
|
||||
|
||||
#ifndef _STDLIB_NULL_POINTER_CHECK_H
|
||||
#include "stdlib_null_pointer_check.h"
|
||||
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _TIME_HEADERS_H
|
||||
#include "time_headers.h"
|
||||
#endif /* _TIME_HEADERS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
ctime_r(const time_t *tptr,char * buffer)
|
||||
{
|
||||
char * result = NULL;
|
||||
struct tm tm;
|
||||
|
||||
ENTER();
|
||||
|
||||
assert( tptr != NULL && buffer != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(tptr == NULL || buffer == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
result = asctime_r(localtime_r(tptr,&tm),buffer);
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_gmtime.c,v 1.2 2004-11-17 19:07:22 obarthel Exp $
|
||||
* $Id: time_gmtime.c,v 1.3 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -43,35 +43,6 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
gmtime_r(const time_t *t,struct tm * tm_ptr)
|
||||
{
|
||||
struct tm * result = NULL;
|
||||
|
||||
ENTER();
|
||||
|
||||
assert( t != NULL && tm_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(t == NULL || tm_ptr == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
result = __convert_time((*t), 0, tm_ptr);
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
gmtime(const time_t *t)
|
||||
{
|
||||
|
||||
71
library/time_gmtime_r.c
Normal file
71
library/time_gmtime_r.c
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* $Id: time_gmtime_r.c,v 1.1 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
||||
* Copyright (c) 2002-2004 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* 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.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of 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 OWNER 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.
|
||||
*/
|
||||
|
||||
#ifndef _STDLIB_NULL_POINTER_CHECK_H
|
||||
#include "stdlib_null_pointer_check.h"
|
||||
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _TIME_HEADERS_H
|
||||
#include "time_headers.h"
|
||||
#endif /* _TIME_HEADERS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
gmtime_r(const time_t *t,struct tm * tm_ptr)
|
||||
{
|
||||
struct tm * result = NULL;
|
||||
|
||||
ENTER();
|
||||
|
||||
assert( t != NULL && tm_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(t == NULL || tm_ptr == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
result = __convert_time((*t), 0, tm_ptr);
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_headers.h,v 1.3 2004-11-14 11:06:27 obarthel Exp $
|
||||
* $Id: time_headers.h,v 1.4 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -91,6 +91,7 @@ extern const char * const NOCOMMON __month_names[12];
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern char * __asctime_r(const struct tm *tm,char * buffer,size_t buffer_size);
|
||||
extern char * __number_to_string(unsigned int number,char * string,size_t max_len,size_t min_len);
|
||||
extern struct tm * __convert_time(ULONG seconds, LONG gmt_offset, struct tm * tm);
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_localtime.c,v 1.2 2004-11-17 19:07:22 obarthel Exp $
|
||||
* $Id: time_localtime.c,v 1.3 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -47,46 +47,6 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
localtime_r(const time_t *t,struct tm * tm_ptr)
|
||||
{
|
||||
struct tm * result = NULL;
|
||||
LONG gmt_offset;
|
||||
|
||||
ENTER();
|
||||
|
||||
assert( t != NULL && tm_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(t == NULL || tm_ptr == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
/* The time parameter given represents local time and
|
||||
* must be converted to UTC before we proceed.
|
||||
*/
|
||||
if(__default_locale != NULL)
|
||||
gmt_offset = 60 * __default_locale->loc_GMTOffset;
|
||||
else
|
||||
gmt_offset = 0;
|
||||
|
||||
SHOWVALUE(gmt_offset);
|
||||
|
||||
result = __convert_time((*t), gmt_offset, tm_ptr);
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
localtime(const time_t *t)
|
||||
{
|
||||
|
||||
86
library/time_localtime_r.c
Normal file
86
library/time_localtime_r.c
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* $Id: time_localtime_r.c,v 1.1 2004-11-18 09:40:37 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
* Portable ISO 'C' (1994) runtime library for the Amiga computer
|
||||
* Copyright (c) 2002-2004 by Olaf Barthel <olsen@sourcery.han.de>
|
||||
* 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.
|
||||
*
|
||||
* - Neither the name of Olaf Barthel nor the names of 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 OWNER 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.
|
||||
*/
|
||||
|
||||
#ifndef _STDLIB_NULL_POINTER_CHECK_H
|
||||
#include "stdlib_null_pointer_check.h"
|
||||
#endif /* _STDLIB_NULL_POINTER_CHECK_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef _TIME_HEADERS_H
|
||||
#include "time_headers.h"
|
||||
#endif /* _TIME_HEADERS_H */
|
||||
|
||||
#ifndef _LOCALE_HEADERS_H
|
||||
#include "locale_headers.h"
|
||||
#endif /* _LOCALE_HEADERS_H */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
localtime_r(const time_t *t,struct tm * tm_ptr)
|
||||
{
|
||||
struct tm * result = NULL;
|
||||
LONG gmt_offset;
|
||||
|
||||
ENTER();
|
||||
|
||||
assert( t != NULL && tm_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(t == NULL || tm_ptr == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
/* The time parameter given represents local time and
|
||||
* must be converted to UTC before we proceed.
|
||||
*/
|
||||
if(__default_locale != NULL)
|
||||
gmt_offset = 60 * __default_locale->loc_GMTOffset;
|
||||
else
|
||||
gmt_offset = 0;
|
||||
|
||||
SHOWVALUE(gmt_offset);
|
||||
|
||||
result = __convert_time((*t), gmt_offset, tm_ptr);
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
Reference in New Issue
Block a user