mirror of
https://github.com/adtools/clib2.git
synced 2026-09-25 10:30:26 +00:00
- Folded duplicate code stdio_init_exit.c into a common function.
- Simplified the code in time_asctime_r.c which builds the time string. It gracefully handles buffer sizes which are too short by returning an empty string. - Moved the tm->tm_wday initialization out of the hook function in time_strftime.c since it was to be called only once anyway. - Lost a few compiler warnings in unistd_time_delay.c and time_gettimeofday.c. - Folded duplicate code in time_mktime.c; also, errno is no longer modified unless the library is built with the CHECK_FOR_NULL_POINTERS option. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14818 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
+21
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: time_strftime.c,v 1.5 2005-01-29 18:05:14 obarthel Exp $
|
||||
* $Id: time_strftime.c,v 1.6 2005-01-30 09:37:59 obarthel Exp $
|
||||
*
|
||||
* :ts=4
|
||||
*
|
||||
@@ -105,25 +105,12 @@ store_string_via_hook(const char * string,int len,struct Hook * hook)
|
||||
static void
|
||||
format_date(const char *format,const struct tm *tm,struct Hook * hook)
|
||||
{
|
||||
struct tm copy_tm;
|
||||
char buffer[40];
|
||||
const char * str;
|
||||
char c;
|
||||
|
||||
assert( format != NULL && tm != NULL && hook != NULL);
|
||||
|
||||
/* Fill in the week day if it's not in proper range. */
|
||||
if(tm->tm_wday < 0 || tm->tm_wday > 6)
|
||||
{
|
||||
/* We use a peculiar algorithm rather than falling back onto
|
||||
mktime() here in order to avoid trouble with skewed results
|
||||
owing to time zone influence. */
|
||||
copy_tm = (*tm);
|
||||
copy_tm.tm_wday = __calculate_weekday(tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday);
|
||||
|
||||
tm = ©_tm;
|
||||
}
|
||||
|
||||
while((c = (*format++)) != '\0')
|
||||
{
|
||||
/* This is the simple case. */
|
||||
@@ -224,7 +211,6 @@ format_date(const char *format,const struct tm *tm,struct Hook * hook)
|
||||
assert( 0 <= tm->tm_hour && tm->tm_hour <= 23 );
|
||||
|
||||
__number_to_string((unsigned int)((tm->tm_hour > 12) ? (tm->tm_hour - 12) : tm->tm_hour),buffer,sizeof(buffer),2);
|
||||
|
||||
store_string_via_hook(buffer,2,hook);
|
||||
break;
|
||||
|
||||
@@ -374,8 +360,6 @@ size_t
|
||||
strftime(char *s, size_t maxsize, const char *format, const struct tm *tm)
|
||||
{
|
||||
DECLARE_LOCALEBASE();
|
||||
struct format_hook_data data;
|
||||
struct Hook hook;
|
||||
size_t result = 0;
|
||||
|
||||
ENTER();
|
||||
@@ -400,10 +384,12 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *tm)
|
||||
}
|
||||
#endif /* CHECK_FOR_NULL_POINTERS */
|
||||
|
||||
data.len = 0;
|
||||
|
||||
if(maxsize > 0)
|
||||
{
|
||||
struct format_hook_data data;
|
||||
struct Hook hook;
|
||||
|
||||
data.len = 0;
|
||||
data.buffer = s;
|
||||
data.max_size = maxsize-1;
|
||||
|
||||
@@ -452,15 +438,29 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *tm)
|
||||
}
|
||||
else
|
||||
{
|
||||
struct tm copy_tm;
|
||||
|
||||
/* Fill in the week day if it's not in proper range. */
|
||||
if(tm->tm_wday < 0 || tm->tm_wday > 6)
|
||||
{
|
||||
/* We use a peculiar algorithm rather than falling back onto
|
||||
mktime() here in order to avoid trouble with skewed results
|
||||
owing to time zone influence. */
|
||||
copy_tm = (*tm);
|
||||
copy_tm.tm_wday = __calculate_weekday(tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday);
|
||||
|
||||
tm = ©_tm;
|
||||
}
|
||||
|
||||
format_date(format,tm,&hook);
|
||||
}
|
||||
|
||||
(*data.buffer) = '\0';
|
||||
|
||||
SHOWSTRING(s);
|
||||
}
|
||||
|
||||
result = data.len;
|
||||
result = data.len;
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user