示例#1
0
文件: support.c 项目: netdna/proftpd
const char *pr_strtime2(time_t t, int use_gmtime) {
  static char buf[64];
  static char *mons[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
    "Aug", "Sep", "Oct", "Nov", "Dec" };
  static char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  struct tm *tr;

  memset(buf, '\0', sizeof(buf));

  if (use_gmtime) {
    tr = pr_gmtime(NULL, &t);

  } else {
    tr = pr_localtime(NULL, &t);
  }

  if (tr != NULL) {
    snprintf(buf, sizeof(buf), "%s %s %02d %02d:%02d:%02d %d",
      days[tr->tm_wday], mons[tr->tm_mon], tr->tm_mday, tr->tm_hour,
      tr->tm_min, tr->tm_sec, tr->tm_year + 1900);

  } else {
    buf[0] = '\0';
  }

  buf[sizeof(buf)-1] = '\0';

  return buf;
}
示例#2
0
文件: misc.c 项目: predever/proftpd
END_TEST

START_TEST (gmtime_test) {
  struct tm *res;
  time_t now;

  mark_point();
  res = pr_gmtime(NULL, NULL); 
  fail_unless(res == NULL, "Failed to handle null arguments");
  fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
    strerror(errno), errno);

  time(&now);

  mark_point();
  res = pr_gmtime(NULL, &now);
  fail_unless(res != NULL, "Failed to handle %lu: %s", (unsigned long) now,
    strerror(errno));

  mark_point();
  res = pr_gmtime(p, &now);
  fail_unless(res != NULL, "Failed to handle %lu: %s", (unsigned long) now,
    strerror(errno));
}