blob: ed22483249e12932cc9f82d7223f88b0e4d8d320 [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
akmhoquec9286692012-08-16 09:57:58 -050030char * getGmTimeStamp(void)
31{
32 char *timestamp = (char *)malloc(sizeof(char) * 16);
33 time_t gtime;
34 gtime=time(NULL);
35 struct tm *tm;
36 tm=gmtime(&gtime);
37
38 sprintf(timestamp, "%04d%02d%02d%02d%02d%02d", tm->tm_year+1900, tm->tm_mon+1,
39 tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
40
41 return timestamp;
42}
43
44
akmhoque59980a52012-08-09 12:36:09 -050045char *
46nth_named_component(const char *name_prefix, int n)
47{
48
49 int i;
50 char * seps="/";
51 char *rem=NULL;
52 char *component;
53
54 char *prefix=(char *)malloc(strlen(name_prefix)+1);
55 memcpy(prefix,name_prefix,strlen(name_prefix)+1);
56
57 component=strtok_r(prefix,seps,&rem);
58
59 for(i=1;i<n;i++)
60 component=strtok_r(NULL,seps,&rem);
61
62 return component;
63
akmhoquef71d9082012-08-22 12:51:53 -040064}
akmhoque59980a52012-08-09 12:36:09 -050065
akmhoquef71d9082012-08-22 12:51:53 -040066long int
67get_current_time_sec(void)
68{
69 struct timeval now;
70 gettimeofday(&now,NULL);
71 return now.tv_sec;
akmhoque59980a52012-08-09 12:36:09 -050072}