Skip to content

Commit d7d2795

Browse files
committed
Get a timestamp string.
1 parent a1fdd86 commit d7d2795

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

unix.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,20 @@ ttyinput(Tty *tty, char *c)
5151
}
5252
return 0;
5353
}
54+
55+
int
56+
timestamp(char *buffer, size_t n)
57+
{
58+
struct tm *tm;
59+
time_t t;
60+
61+
t = time(NULL);
62+
if (t == (time_t)-1)
63+
return -1;
64+
tm = localtime(&t);
65+
if (tm == NULL)
66+
return -1;
67+
if(strftime(buffer, n, "%Y%m%d%H%M%S", tm) == 0)
68+
return -1;
69+
return 0;
70+
}

unix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ int dial(char *host, int port);
2424
void serve(int port, void (*handlecon)(int, void*), void *arg);
2525
void nodelay(int fd);
2626
void sleep_ms (uint32 ms);
27+
int timestamp(char *buffer, size_t n);
2728

2829
#define xmain main
2930

0 commit comments

Comments
 (0)