Esempio n. 1
0
static char * ATTRIBUTE_WARN_UNUSED_RESULT
human_time (struct timespec t)
{
  /* STR must be at least this big, either because localtime_rz fails,
     or because the time zone is truly outlandish so that %z expands
     to a long string.  */
  enum { intmax_bufsize = INT_BUFSIZE_BOUND (intmax_t) };

  static char str[intmax_bufsize
                  + INT_STRLEN_BOUND (int) /* YYYY */
                  + 1 /* because YYYY might equal INT_MAX + 1900 */
                  + sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +"];
  static timezone_t tz;
  if (!tz)
    tz = tzalloc (getenv ("TZ"));
  struct tm tm;
  int ns = t.tv_nsec;
  if (localtime_rz (tz, &t.tv_sec, &tm))
    nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", &tm, tz, ns);
  else
    {
      char secbuf[INT_BUFSIZE_BOUND (intmax_t)];
      sprintf (str, "%s.%09d", timetostr (t.tv_sec, secbuf), ns);
    }
  return str;
}
Esempio n. 2
0
int
main (void)
{
  int fail = 0;
  unsigned int i;

  for (i = 0; T[i].fmt; i++)
    {
      char buf[1000];
      time_t t = T[i].in;
      struct tm *tm = gmtime (&t);
      size_t n;
      int utc = 1;

      ASSERT (tm);

      n = nstrftime (buf, sizeof buf, T[i].fmt, tm, utc, T[i].in_ns);
      if (n == 0)
        {
          fail = 1;
          printf ("nstrftime failed with format %s\n", T[i].fmt);
        }

      if (! STREQ (buf, T[i].exp))
        {
          fail = 1;
          printf ("%s: result mismatch: got %s, expected %s\n",
                  T[i].fmt, buf, T[i].exp);
        }
    }

  return fail;
}
Esempio n. 3
0
static char * ATTRIBUTE_WARN_UNUSED_RESULT
human_time (struct timespec t)
{
  static char str[MAX (INT_BUFSIZE_BOUND (intmax_t),
                       (INT_STRLEN_BOUND (int) /* YYYY */
                        + 1 /* because YYYY might equal INT_MAX + 1900 */
                        + sizeof "-MM-DD HH:MM:SS.NNNNNNNNN +ZZZZ"))];
  struct tm const *tm = localtime (&t.tv_sec);
  if (tm == NULL)
    return timetostr (t.tv_sec, str);
  nstrftime (str, sizeof str, "%Y-%m-%d %H:%M:%S.%N %z", tm, 0, t.tv_nsec);
  return str;
}
Esempio n. 4
0
static void
print_context_label (char const *mark,
		     struct file_data *inf,
		     char const *label)
{
  if (label)
    fprintf (outfile, "%s %s\n", mark, label);
  else
    {
      char buf[MAX (INT_STRLEN_BOUND (int) + 32,
		    INT_STRLEN_BOUND (time_t) + 11)];
      struct tm const *tm = localtime (&inf->stat.st_mtime);
      int nsec = TIMESPEC_NS (inf->stat.st_mtim);
      if (! (tm && nstrftime (buf, sizeof buf, time_format, tm, 0, nsec)))
	{
	  long sec = inf->stat.st_mtime;
	  verify (info_preserved, sizeof inf->stat.st_mtime <= sizeof sec);
	  sprintf (buf, "%ld.%.9d", sec, nsec);
	}
      fprintf (outfile, "%s %s\t%s\n", mark, inf->name, buf);
    }
}
Esempio n. 5
0
static void
print_context_label (char const *mark,
		     struct file_data *inf,
		     char const *name,
		     char const *label)
{
  if (label)
    fprintf (outfile, "%s %s\n", mark, label);
  else
    {
      char buf[MAX (INT_STRLEN_BOUND (int) + 32,
		    INT_STRLEN_BOUND (time_t) + 11)];
      struct tm const *tm = localtime (&inf->stat.st_mtime);
      int nsec = get_stat_mtime_ns (&inf->stat);
      if (! (tm && nstrftime (buf, sizeof buf, time_format, tm, 0, nsec)))
	{
	  verify (TYPE_IS_INTEGER (time_t));
	  if (LONG_MIN <= TYPE_MINIMUM (time_t)
	      && TYPE_MAXIMUM (time_t) <= LONG_MAX)
	    {
	      long int sec = inf->stat.st_mtime;
	      sprintf (buf, "%ld.%.9d", sec, nsec);
	    }
	  else if (TYPE_MAXIMUM (time_t) <= INTMAX_MAX)
	    {
	      intmax_t sec = inf->stat.st_mtime;
	      sprintf (buf, "%"PRIdMAX".%.9d", sec, nsec);
	    }
	  else
	    {
	      uintmax_t sec = inf->stat.st_mtime;
	      sprintf (buf, "%"PRIuMAX".%.9d", sec, nsec);
	    }
	}
      fprintf (outfile, "%s %s\t%s\n", mark, name, buf);
    }
}
Esempio n. 6
0
void
CoordWinSetCoord(int x, int y)
{
  struct objlist *obj;
  int i, num, type;
  char *argv[3];
  double a;
  char *name;
  struct SubWin *d;
  static GString *str = NULL;
  static int lock = FALSE;

  d = &(NgraphApp.CoordWin);

  obj = chkobject("axis");

  if (d->Win == NULL ||
      obj == NULL ||
      d->data.text == NULL) {
    return;
  }

  num = chkobjlastinst(obj) + 1;

  if (lock) {
    return;
  }
  lock = TRUE;

  if (str == NULL) {
    str = g_string_new("");
    gtk_label_set_text(GTK_LABEL(d->data.text), "");
    if (str == NULL) {
      lock = FALSE;
      return;
    }
  }

  g_string_printf(str, "(X:%6.2f  Y:%6.2f)", x / 100.0, y / 100.0);
  argv[0] = (char *) &x;
  argv[1] = (char *) &y;
  argv[2] = NULL;
  for (i = 0; i < num; i++) {
    if (getobj(obj, "coordinate", i, 2, argv, &a) == -1) {
      continue;
    }
    getobj(obj, "group", i, 0, NULL, &name);
    getobj(obj, "type", i, 0, NULL, &type);
    g_string_append_printf(str, "\n%2d %5s %+.7e", i, name, a);
    if (type == AXIS_TYPE_MJD) {
      char *s;

      s = nstrftime("\n        %F %T", a);
      if (s) {
	g_string_append(str, s);
	g_free(s);
      }
    }
  }

  gtk_label_set_text(GTK_LABEL(d->data.text), str->str);

  lock = FALSE;
}
Esempio n. 7
0
static int
tzalloc_test (void)
{
    int fail = 0;
    int i;

    for (i = 0; LT[i].tza; i++)
    {
        struct tzalloc_test *tza = LT[i].tza;
        long lt = LT[i].t;
        timezone_t tz = tza->tz;
        char const *setting;
        static char const format[] = "%Y-%m-%d %H:%M:%S %z (%Z)";
        char buf[1000];
        struct tm tm;
        size_t n;

        if (!tz && tza->setting)
        {
            tz = tzalloc (tza->setting);
            if (!tz)
            {
                fail = 1;
                printf ("%s: tzalloc: %s\n", TZ[i].setting, strerror (errno));
                continue;
            }
            tza->tz = tz;
        }

        setting = tza->setting ? tza->setting : "UTC0";

        if (!localtime_rz (tz, &LT[i].t, &tm))
        {
            fail = 1;
            printf ("%s: %ld: localtime_rz: %s\n", setting, lt,
                    strerror (errno));
            continue;
        }

        n = nstrftime (buf, sizeof buf, format, &tm, tz, 0);
        if (n == 0)
        {
            fail = 1;
            printf ("%s: %ld: nstrftime failed\n", setting, lt);
            continue;
        }

        if (! (STREQ (buf, LT[i].exp)
                || (!tz && n == strlen (LT[i].exp)
                    && memcmp (buf, LT[i].exp, n - sizeof "(GMT)" + 1) == 0
                    && STREQ (buf + n - sizeof "(GMT)" + 1, "(GMT)"))))
        {
            /* Don't fail for unhandled dst in ahistorical entries,
               as gnulib doesn't currently fix that issue, seen on Darwin 14.  */
            if (!LT[i].ahistorical || tm.tm_isdst)
                fail = 1;
            printf ("%s: expected \"%s\", got \"%s\"\n",
                    setting, LT[i].exp, buf);
        }
    }

    return fail;
}