blob: 283376d1f99f636d485d432031c28755bb4302fe [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}
akmhoqued79438d2012-08-27 13:31:42 -050073
74
75long int
76get_current_time_microsec(void)
77{
78 struct timeval now;
79 gettimeofday(&now, NULL);
80 long int microSec=1000000*now.tv_sec+now.tv_usec;
81 return microSec;
82
83}