From 24ea9161a752d2b91cb26b076b5b38182aa90196 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Thu, 18 Nov 2004 09:40:37 +0000 Subject: [PATCH] - 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 --- library/GNUmakefile.68k | 7 +- library/GNUmakefile.os4 | 7 +- library/smakefile | 7 +- library/string_strtok.c | 72 +------------ library/string_strtok_r.c | 112 ++++++++++++++++++++ library/time_asctime.c | 165 +---------------------------- library/time_asctime_r.c | 205 +++++++++++++++++++++++++++++++++++++ library/time_ctime.c | 32 +----- library/time_ctime_r.c | 72 +++++++++++++ library/time_gmtime.c | 31 +----- library/time_gmtime_r.c | 71 +++++++++++++ library/time_headers.h | 3 +- library/time_localtime.c | 42 +------- library/time_localtime_r.c | 86 ++++++++++++++++ 14 files changed, 571 insertions(+), 341 deletions(-) create mode 100644 library/string_strtok_r.c create mode 100644 library/time_asctime_r.c create mode 100644 library/time_ctime_r.c create mode 100644 library/time_gmtime_r.c create mode 100644 library/time_localtime_r.c diff --git a/library/GNUmakefile.68k b/library/GNUmakefile.68k index 65d9a1b..ec6a635 100644 --- a/library/GNUmakefile.68k +++ b/library/GNUmakefile.68k @@ -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 \ diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index 93d713e..09cc416 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -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 \ diff --git a/library/smakefile b/library/smakefile index 174f0fe..2176355 100644 --- a/library/smakefile +++ b/library/smakefile @@ -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 \ diff --git a/library/string_strtok.c b/library/string_strtok.c index 64b49b0..ba2ddbd 100644 --- a/library/string_strtok.c +++ b/library/string_strtok.c @@ -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) { diff --git a/library/string_strtok_r.c b/library/string_strtok_r.c new file mode 100644 index 0000000..d77e7e6 --- /dev/null +++ b/library/string_strtok_r.c @@ -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 + * 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); +} diff --git a/library/time_asctime.c b/library/time_asctime.c index c790aae..054a3d4 100644 --- a/library/time_asctime.c +++ b/library/time_asctime.c @@ -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) { diff --git a/library/time_asctime_r.c b/library/time_asctime_r.c new file mode 100644 index 0000000..7b13bdd --- /dev/null +++ b/library/time_asctime_r.c @@ -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 + * 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); +} diff --git a/library/time_ctime.c b/library/time_ctime.c index 9770ec6..f40e75c 100644 --- a/library/time_ctime.c +++ b/library/time_ctime.c @@ -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) { diff --git a/library/time_ctime_r.c b/library/time_ctime_r.c new file mode 100644 index 0000000..2038c06 --- /dev/null +++ b/library/time_ctime_r.c @@ -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 + * 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); +} diff --git a/library/time_gmtime.c b/library/time_gmtime.c index 6b6de7f..16ddceb 100644 --- a/library/time_gmtime.c +++ b/library/time_gmtime.c @@ -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) { diff --git a/library/time_gmtime_r.c b/library/time_gmtime_r.c new file mode 100644 index 0000000..7b631b5 --- /dev/null +++ b/library/time_gmtime_r.c @@ -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 + * 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); +} diff --git a/library/time_headers.h b/library/time_headers.h index 6ba2d11..b02ed8b 100644 --- a/library/time_headers.h +++ b/library/time_headers.h @@ -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); diff --git a/library/time_localtime.c b/library/time_localtime.c index 680e675..7b08d56 100644 --- a/library/time_localtime.c +++ b/library/time_localtime.c @@ -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) { diff --git a/library/time_localtime_r.c b/library/time_localtime_r.c new file mode 100644 index 0000000..ad40765 --- /dev/null +++ b/library/time_localtime_r.c @@ -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 + * 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); +}