blob: 5ad352947c7ee506fe4d9f5c00c4f606c23d166f [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>
7#include <assert.h>
8#ifdef HAVE_CONFIG_H
9#include <config.h>
10#endif
11
12#include "utility.h"
13
14
15char * getLocalTimeStamp(void)
16{
17 char *timestamp = (char *)malloc(sizeof(char) * 16);
18 time_t ltime;
19 ltime=time(NULL);
20 struct tm *tm;
21 tm=localtime(&ltime);
22
23 sprintf(timestamp, "%04d%02d%02d%02d%02d%02d", tm->tm_year+1900, tm->tm_mon+1,
24 tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec);
25
26 return timestamp;
27}
28
29char *
30nth_named_component(const char *name_prefix, int n)
31{
32
33 int i;
34 char * seps="/";
35 char *rem=NULL;
36 char *component;
37
38 char *prefix=(char *)malloc(strlen(name_prefix)+1);
39 memcpy(prefix,name_prefix,strlen(name_prefix)+1);
40
41 component=strtok_r(prefix,seps,&rem);
42
43 for(i=1;i<n;i++)
44 component=strtok_r(NULL,seps,&rem);
45
46 return component;
47
48
49
50}