blob: 2de07c92df86a61b50529dfc85d3ce73b6fc7f16 [file] [log] [blame]
akmhoque59980a52012-08-09 12:36:09 -05001#include<stdio.h>
2#include<string.h>
3#include<stdlib.h>
4#include <unistd.h>
5#include <getopt.h>
6#include <sys/time.h>
akmhoque0476dc42012-08-13 09:59:08 -05007#include <time.h>
akmhoque59980a52012-08-09 12:36:09 -05008#include <assert.h>
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include "utility.h"
14
15
16char * getLocalTimeStamp(void)
17{
18 char *timestamp = (char *)malloc(sizeof(char) * 16);
19 time_t ltime;
20 ltime=time(NULL);
21 struct tm *tm;
22 tm=localtime(&ltime);
23
24 sprintf(timestamp, "%04d%02d%02d%02d%02d%02d", tm->tm_year+1900, tm->tm_mon+1,
25 tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
26
27 return timestamp;
28}
29
30char *
31nth_named_component(const char *name_prefix, int n)
32{
33
34 int i;
35 char * seps="/";
36 char *rem=NULL;
37 char *component;
38
39 char *prefix=(char *)malloc(strlen(name_prefix)+1);
40 memcpy(prefix,name_prefix,strlen(name_prefix)+1);
41
42 component=strtok_r(prefix,seps,&rem);
43
44 for(i=1;i<n;i++)
45 component=strtok_r(NULL,seps,&rem);
46
47 return component;
48
49
50
51}