Use epoch time for timestamps

This commit is contained in:
Neale Pickett 2010-09-06 21:39:59 -06:00
parent 8e1dfbd0da
commit c74c457136
2 changed files with 6 additions and 31 deletions

View File

@ -7,25 +7,6 @@
#include <time.h> #include <time.h>
#include "common.h" #include "common.h"
int
timestamp(char *now, size_t nowlen)
{
time_t t;
struct tm tmp;
time(&t);
if (NULL == gmtime_r(&t, &tmp)) {
perror("gmtime_r");
return -1;
}
if (0 == strftime(now, nowlen, "%Y-%m-%dT%H:%M:%SZ", &tmp)) {
return -1;
}
return 0;
}
int int
team_exists(char *teamhash) team_exists(char *teamhash)
{ {
@ -60,23 +41,18 @@ team_exists(char *teamhash)
int int
award_points(char *teamhash, char *category, int points) award_points(char *teamhash, char *category, int points)
{ {
char now[40]; char line[100];
char line[100]; int linelen;
int linelen; int fd;
int fd; int ret;
int ret;
if (! team_exists(teamhash)) { if (! team_exists(teamhash)) {
return -2; return -2;
} }
ret = timestamp(now, sizeof(now));
if (-1 == ret) {
return -3;
}
linelen = snprintf(line, sizeof(line), linelen = snprintf(line, sizeof(line),
"%s %s %s %d\n", "%u %s %s %d\n",
now, teamhash, category, points); time(NULL), teamhash, category, points);
if (sizeof(line) == linelen) { if (sizeof(line) == linelen) {
return -1; return -1;
} }

View File

@ -4,7 +4,6 @@
#define teamdir "/var/lib/ctf/teams" #define teamdir "/var/lib/ctf/teams"
#define pointslog "/var/lib/ctf/points.log" #define pointslog "/var/lib/ctf/points.log"
int timestamp(char *now, size_t nowlen);
int team_exists(char *teamhash); int team_exists(char *teamhash);
int award_points(char *teamhash, char *category, int point); int award_points(char *teamhash, char *category, int point);