akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
akmhoque | 0476dc4 | 2012-08-13 09:59:08 -0500 | [diff] [blame] | 7 | #include <time.h> |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 8 | #include <assert.h> |
| 9 | #ifdef HAVE_CONFIG_H |
| 10 | #include <config.h> |
| 11 | #endif |
| 12 | |
| 13 | #include "utility.h" |
| 14 | |
| 15 | |
| 16 | char * 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(<ime); |
| 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 | |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 30 | char * 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(>ime); |
| 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 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 45 | char * |
| 46 | nth_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 | |
| 64 | |
| 65 | |
| 66 | } |