| 1 | #include <string.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <sys/types.h> |
| 4 | #include <sys/stat.h> |
| 5 | |
| 6 | /* http://stackoverflow.com/questions/4021479/getting-file-modification-time-on-unix-using-utime-in-c */ |
| 7 | time_t get_mtime(const char *path) |
| 8 | { |
| 9 | struct stat statbuf; |
| 10 | if (stat(path, &statbuf) == -1) |
| 11 | { |
| 12 | perror(path); |
| 13 | exit(1); |
| 14 | } |
| 15 | return statbuf.st_mtime; |
| 16 | } |
| 17 | |
| 18 | /* just text line parsing */ |
| 19 | char *parse_datafile_line(char *str) |
| 20 | { |
| 21 | char *ptr = strchr(str,' '); |
| 22 | if(!ptr) |
| 23 | { |
| 24 | ptr = strchr(str,'\t'); |
| 25 | } |
| 26 | |
| 27 | if(ptr) |
| 28 | { |
| 29 | *ptr = 0; |
| 30 | ptr++; |
| 31 | while(*ptr == ' ' || *ptr == '\t') |
| 32 | { |
| 33 | ptr++; |
| 34 | } |
| 35 | return ptr; |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | return NULL; |
| 40 | } |
| 41 | } |