From: Paul Park Date: Mon, 21 Aug 1995 21:10:37 +0000 (+0000) Subject: Add timestamp_to_sfstring() X-Git-Tag: krb5-1.0-beta6~1287 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1f302c8c6783051d9b350debd8c36ea6c3b7245e;p=krb5.git Add timestamp_to_sfstring() git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6553 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/kadm/ChangeLog b/src/lib/kadm/ChangeLog index a1d2adb6c..1582c8583 100644 --- a/src/lib/kadm/ChangeLog +++ b/src/lib/kadm/ChangeLog @@ -1,4 +1,11 @@ +Mon Aug 21 17:07:56 EDT 1995 Paul Park (pjpark@mit.edu) + * str_conv.c - Add krb5_timestamp_to_sfstring(). This converts time + to a short string, potentially filled. Use strftime() for + krb5_timestamp_to_string() if present so that locale-dependent + time format is used. + + Tue Aug 8 17:35:10 EDT 1995 Paul Park (pjpark@mit.edu) * str_conv.c - Fix Purify complaint. diff --git a/src/lib/kadm/str_conv.c b/src/lib/kadm/str_conv.c index 1a994b529..2d91d9511 100644 --- a/src/lib/kadm/str_conv.c +++ b/src/lib/kadm/str_conv.c @@ -47,6 +47,7 @@ * krb5_cksumtype_to_string() - Convert krb5_cksumtype to string. * krb5_flags_to_string() - Convert krb5_flags to string. * krb5_timestamp_to_string() - Convert krb5_timestamp to string. + * krb5_timestamp_to_sfstring() - Convert krb5_timestamp to short filled string * krb5_deltat_to_string() - Convert krb5_deltat to string. */ @@ -194,6 +195,14 @@ static const char ascan_rel_hm[] = "%02d%02d"; static const char ascan_rel_col_hms[] = "%02d:%02d:%02d"; static const char ascan_rel_col_hm[] = "%02d:%02d"; #endif /* !HAVE_STRPTIME */ +#ifdef HAVE_STRFTIME +static const char sftime_ldep_time[] = "%c"; +static const char sftime_med_fmt[] = "%d %b %y %T"; +static const char sftime_short_fmt[] = "%x %X"; +static const char sftime_last_fmt[] = "%d/%m/%y %R"; +#endif /* HAVE_STRFTIME */ +static const char sftime_default_fmt[] = "%02d/%02d/%02d %02d:%02d"; +static const int sftime_default_len = 2+1+2+1+2+1+2+1+2+1; /* Delta time strings */ static const char dtscan_dhms_notext[] = "%d-%02d:%02d:%02d"; @@ -297,6 +306,15 @@ atime_full_text_nos /* dd-month-yyyy:hh:mm */ static const int atime_format_table_nents = sizeof(atime_format_table)/ sizeof(atime_format_table[0]); +static const char * const sftime_format_table[] = { +sftime_ldep_time, /* Default locale-dependent date and time */ +sftime_med_fmt, /* dd mon yy hh:mm:ss */ +sftime_short_fmt, /* locale-dependent short format */ +sftime_last_fmt /* dd/mm/yy hh:mm */ +}; +static const int sftime_format_table_nents = sizeof(sftime_format_table)/ + sizeof(sftime_format_table[0]); + static const struct deltat_match_entry deltat_table[] = { /* scan format nmatch daypos hourpos minpos secpos */ /*--------------------- ------- ------- ------- ------- --------*/ @@ -771,15 +789,57 @@ krb5_timestamp_to_string(timestamp, buffer, buflen) char * buffer; size_t buflen; { +#if HAVE_STRFTIME + if (strftime(buffer, buflen, "%c", localtime((time_t *) ×tamp))) + return(0); + else + return(ENOMEM); +#else /* HAVE_STRFTIME */ if (strlen(ctime((time_t *) ×tamp)) <= buflen) { strcpy(buffer, ctime((time_t *) ×tamp)); /* ctime returns \n\0 */ buffer[strlen(buffer)-1] = '\0'; return(0); } +#endif /* HAVE_STRFTIME */ return(ENOMEM); } +krb5_error_code +krb5_timestamp_to_sfstring(timestamp, buffer, buflen, pad) + krb5_timestamp timestamp; + char * buffer; + size_t buflen; + char * pad; +{ + struct tm *tmp; + int i; + size_t ndone; + + tmp = localtime((time_t *) ×tamp); + ndone = 0; +#if HAVE_STRFTIME + for (i=0; i= sftime_default_len) { + sprintf(buffer, sftime_default_fmt, + tmp->tm_mday, tmp->tm_mon+1, tmp->tm_year, + tmp->tm_hour, tmp->tm_min, tmp->tm_sec); + ndone = strlen(buffer); + } + } + if (ndone && pad) { + for (i=ndone; i