Blame time/tst-strptime3.c

Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <time.h>
Packit 6c4009
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
do_test (void)
Packit 6c4009
{
Packit 6c4009
  int result = 0;
Packit 6c4009
  struct tm tm;
Packit 6c4009
Packit 6c4009
  memset (&tm, 0xaa, sizeof (tm));
Packit 6c4009
Packit 6c4009
  /* Test we don't crash on uninitialized struct tm.
Packit 6c4009
     Some fields might contain bogus values until everything
Packit 6c4009
     needed is initialized, but we shouldn't crash.  */
Packit 6c4009
  if (strptime ("2007", "%Y", &tm) == NULL
Packit 6c4009
      || strptime ("12", "%d", &tm) == NULL
Packit 6c4009
      || strptime ("Feb", "%b", &tm) == NULL
Packit 6c4009
      || strptime ("13", "%M", &tm) == NULL
Packit 6c4009
      || strptime ("21", "%S", &tm) == NULL
Packit 6c4009
      || strptime ("16", "%H", &tm) == NULL)
Packit 6c4009
    {
Packit 6c4009
      puts ("strptimes failed");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
Packit 6c4009
      || tm.tm_mday != 12 || tm.tm_mon != 1 || tm.tm_year != 107
Packit 6c4009
      || tm.tm_wday != 1 || tm.tm_yday != 42)
Packit 6c4009
    {
Packit 6c4009
      puts ("unexpected tm content");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (strptime ("8", "%d", &tm) == NULL)
Packit 6c4009
    {
Packit 6c4009
      puts ("strptime failed");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (tm.tm_sec != 21 || tm.tm_min != 13 || tm.tm_hour != 16
Packit 6c4009
      || tm.tm_mday != 8 || tm.tm_mon != 1 || tm.tm_year != 107
Packit 6c4009
      || tm.tm_wday != 4 || tm.tm_yday != 38)
Packit 6c4009
    {
Packit 6c4009
      puts ("unexpected tm content");
Packit 6c4009
      result = 1;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_test ()
Packit 6c4009
#include "../test-skeleton.c"