mirror of
https://github.com/adtools/clib2.git
synced 2025-12-08 14:59:05 +00:00
- Added asctime_r(), ctime_r(), gmtime_r(), localtime_r() and strtok_r().
git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14773 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
- Added asctime_r(), ctime_r(), gmtime_r(), localtime_r() and strtok_r().
|
||||
|
||||
- Added stubs for the Rexx Variables Interface code that used to
|
||||
be part of amiga.lib. While comparable functionality is available
|
||||
in rexxsyslib.library V45, the new stubs might be helpful during
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: string.h,v 1.4 2004-11-14 11:06:29 obarthel Exp $
|
||||
* $Id: string.h,v 1.5 2004-11-17 19:07:26 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -127,6 +127,10 @@ extern size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern char * strtok_r(char *str, const char *separator_set,char ** state_ptr);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time.h,v 1.1.1.1 2004-07-26 16:32:56 obarthel Exp $
|
||||
* $Id: time.h,v 1.2 2004-11-17 19:07:26 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -95,6 +95,17 @@ extern size_t strftime(char *s, size_t maxsize, const char *format,
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
/* The following is not part of the ISO 'C' (1994) standard. */
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
extern char * asctime_r(const struct tm *tm,char * buffer);
|
||||
extern char * ctime_r(const time_t *tptr,char * buffer);
|
||||
extern struct tm * gmtime_r(const time_t *t,struct tm * tm_ptr);
|
||||
extern struct tm * localtime_r(const time_t *t,struct tm * tm_ptr);
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: string_strtok.c,v 1.2 2004-10-25 19:53:15 obarthel Exp $
|
||||
* $Id: string_strtok.c,v 1.3 2004-11-17 19:07:22 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -44,18 +44,17 @@
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
strtok(char *str, const char *separator_set)
|
||||
strtok_r(char *str, const char *separator_set,char ** state_ptr)
|
||||
{
|
||||
static char * last;
|
||||
|
||||
char * result = NULL;
|
||||
char * last;
|
||||
size_t size;
|
||||
|
||||
assert( separator_set != NULL );
|
||||
assert( separator_set != NULL && state_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(separator_set == NULL)
|
||||
if(separator_set == NULL || state_ptr == NULL)
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
@ -63,6 +62,8 @@ strtok(char *str, const char *separator_set)
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
last = (*state_ptr);
|
||||
|
||||
/* Did we get called before? Restart at the last valid position. */
|
||||
if(str == NULL)
|
||||
{
|
||||
@ -104,5 +105,25 @@ strtok(char *str, const char *separator_set)
|
||||
|
||||
out:
|
||||
|
||||
if(state_ptr != NULL)
|
||||
(*state_ptr) = last;
|
||||
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
strtok(char *str, const char *separator_set)
|
||||
{
|
||||
static char * last;
|
||||
|
||||
char * result;
|
||||
|
||||
ENTER();
|
||||
|
||||
result = strtok_r(str,separator_set,&last);
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_asctime.c,v 1.1.1.1 2004-07-26 16:32:21 obarthel Exp $
|
||||
* $Id: time_asctime.c,v 1.2 2004-11-17 19:07:22 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -74,11 +74,9 @@ add_to_string(char * to,int to_size,const char * string,int * offset_ptr)
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
char *
|
||||
asctime(const struct tm *tm)
|
||||
static char *
|
||||
__asctime_r(const struct tm *tm,char * buffer,size_t buffer_size)
|
||||
{
|
||||
static char buffer[40];
|
||||
|
||||
struct tm copy_tm;
|
||||
char number[16];
|
||||
char * result = NULL;
|
||||
@ -89,11 +87,11 @@ asctime(const struct tm *tm)
|
||||
|
||||
SHOWPOINTER(tm);
|
||||
|
||||
assert( tm != NULL );
|
||||
assert( tm != NULL || buffer == NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(tm == NULL)
|
||||
if(tm == NULL || buffer == NULL )
|
||||
{
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
@ -126,62 +124,62 @@ asctime(const struct tm *tm)
|
||||
else
|
||||
b = "---";
|
||||
|
||||
add_to_string(buffer,sizeof(buffer),b, &offset);
|
||||
add_to_string(buffer,sizeof(buffer)," ", &offset);
|
||||
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,sizeof(buffer),b, &offset);
|
||||
add_to_string(buffer,sizeof(buffer)," ", &offset);
|
||||
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,sizeof(buffer),b, &offset);
|
||||
add_to_string(buffer,sizeof(buffer)," ", &offset);
|
||||
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,sizeof(buffer),b, &offset);
|
||||
add_to_string(buffer,sizeof(buffer),":", &offset);
|
||||
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,sizeof(buffer),b, &offset);
|
||||
add_to_string(buffer,sizeof(buffer),":", &offset);
|
||||
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,sizeof(buffer),b, &offset);
|
||||
add_to_string(buffer,sizeof(buffer)," ", &offset);
|
||||
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,sizeof(buffer),b,&offset);
|
||||
add_to_string(buffer,buffer_size,b,&offset);
|
||||
|
||||
SHOWSTRING(buffer);
|
||||
|
||||
add_to_string(buffer,sizeof(buffer),"\n",&offset);
|
||||
add_to_string(buffer,buffer_size,"\n",&offset);
|
||||
|
||||
assert( offset < sizeof(buffer) );
|
||||
assert( strlen(buffer) < sizeof(buffer) );
|
||||
assert( offset < buffer_size );
|
||||
assert( strlen(buffer) < buffer_size );
|
||||
|
||||
result = buffer;
|
||||
|
||||
@ -190,3 +188,35 @@ asctime(const struct tm *tm)
|
||||
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)
|
||||
{
|
||||
static char buffer[40];
|
||||
|
||||
char * result;
|
||||
|
||||
ENTER();
|
||||
|
||||
result = __asctime_r(tm,buffer,sizeof(buffer));
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_ctime.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $
|
||||
* $Id: time_ctime.c,v 1.2 2004-11-17 19:07:22 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -43,6 +43,36 @@
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_gmtime.c,v 1.1.1.1 2004-07-26 16:32:22 obarthel Exp $
|
||||
* $Id: time_gmtime.c,v 1.2 2004-11-17 19:07:22 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -44,31 +44,44 @@
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
gmtime(const time_t *t)
|
||||
gmtime_r(const time_t *t,struct tm * tm_ptr)
|
||||
{
|
||||
static struct tm tm;
|
||||
struct tm * result = NULL;
|
||||
|
||||
ENTER();
|
||||
|
||||
assert( t != NULL );
|
||||
assert( t != NULL && tm_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(t == NULL)
|
||||
if(t == NULL || tm_ptr == NULL)
|
||||
{
|
||||
SHOWMSG("invalid t parameter");
|
||||
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
result = __convert_time((*t), 0, &tm);
|
||||
result = __convert_time((*t), 0, tm_ptr);
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
gmtime(const time_t *t)
|
||||
{
|
||||
static struct tm tm;
|
||||
struct tm * result;
|
||||
|
||||
ENTER();
|
||||
|
||||
result = gmtime_r(t,&tm);
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_localtime.c,v 1.1.1.1 2004-07-26 16:32:23 obarthel Exp $
|
||||
* $Id: time_localtime.c,v 1.2 2004-11-17 19:07:22 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@ -48,22 +48,19 @@
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
localtime(const time_t *t)
|
||||
localtime_r(const time_t *t,struct tm * tm_ptr)
|
||||
{
|
||||
static struct tm tm;
|
||||
struct tm * result = NULL;
|
||||
LONG gmt_offset;
|
||||
|
||||
ENTER();
|
||||
|
||||
assert( t != NULL );
|
||||
assert( t != NULL && tm_ptr != NULL );
|
||||
|
||||
#if defined(CHECK_FOR_NULL_POINTERS)
|
||||
{
|
||||
if(t == NULL)
|
||||
if(t == NULL || tm_ptr == NULL)
|
||||
{
|
||||
SHOWMSG("invalid t parameter");
|
||||
|
||||
errno = EFAULT;
|
||||
goto out;
|
||||
}
|
||||
@ -80,10 +77,27 @@ localtime(const time_t *t)
|
||||
|
||||
SHOWVALUE(gmt_offset);
|
||||
|
||||
result = __convert_time((*t), gmt_offset, &tm);
|
||||
result = __convert_time((*t), gmt_offset, tm_ptr);
|
||||
|
||||
out:
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
struct tm *
|
||||
localtime(const time_t *t)
|
||||
{
|
||||
static struct tm tm;
|
||||
|
||||
struct tm * result;
|
||||
|
||||
ENTER();
|
||||
|
||||
result = localtime_r(t,&tm);
|
||||
|
||||
RETURN(result);
|
||||
return(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user