Back to index

glibc  2.9
Defines | Functions | Variables
asctime.c File Reference
#include "../locale/localeinfo.h"
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <time.h>

Go to the source code of this file.


#define ab_day_name(DAY)   (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)+(DAY)].string)
#define ab_month_name(MON)   (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)+(MON)].string)


static char * asctime_internal (const struct tm *tp, char *buf, size_t buflen)
char * __asctime_r (const struct tm *tp, char *buf)
 weak_alias (__asctime_r, asctime_r)


static const char format [] = "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n"
static char result [3+1+3+1+20+1+20+1+20+1+20+1+20+1+1]

Define Documentation

#define ab_day_name (   DAY)    (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABDAY_1)+(DAY)].string)

Definition at line 28 of file asctime.c.

#define ab_month_name (   MON)    (_nl_C_LC_TIME.values[_NL_ITEM_INDEX (ABMON_1)+(MON)].string)

Definition at line 29 of file asctime.c.

Function Documentation

char* __asctime_r ( const struct tm tp,
char *  buf 

Definition at line 77 of file asctime.c.

  return asctime_internal (tp, buf, 26);

Here is the call graph for this function:

static char* asctime_internal ( const struct tm tp,
char *  buf,
size_t  buflen 
) [static]

Definition at line 36 of file asctime.c.

  if (tp == NULL)
      __set_errno (EINVAL);
      return NULL;

  /* We limit the size of the year which can be printed.  Using the %d
     format specifier used the addition of 1900 would overflow the
     number and a negative vaue is printed.  For some architectures we
     could in theory use %ld or an evern larger integer format but
     this would mean the output needs more space.  This would not be a
     problem if the 'asctime_r' interface would be defined sanely and
     a buffer size would be passed.  */
  if (__builtin_expect (tp->tm_year > INT_MAX - 1900, 0))
      __set_errno (EOVERFLOW);
      return NULL;

  int n = __snprintf (buf, buflen, format,
                    (tp->tm_wday < 0 || tp->tm_wday >= 7 ?
                     "???" : ab_day_name (tp->tm_wday)),
                    (tp->tm_mon < 0 || tp->tm_mon >= 12 ?
                     "???" : ab_month_name (tp->tm_mon)),
                    tp->tm_mday, tp->tm_hour, tp->tm_min,
                    tp->tm_sec, 1900 + tp->tm_year);
  if (n < 0)
    return NULL;
  if (n >= buflen)
    goto eoverflow;

  return buf;

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 81 of file asctime.c.

  return asctime_internal (tp, result, sizeof (result));

Here is the call graph for this function:

Variable Documentation

const char format[] = "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n" [static]

Definition at line 31 of file asctime.c.

char result[3+1+3+1+20+1+20+1+20+1+20+1+20+1+1] [static]

Definition at line 32 of file asctime.c.