Created
August 28, 2013 16:58
-
-
Save TrilbyWhite/6368411 to your computer and use it in GitHub Desktop.
Example of parsing a local maildir.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/stat.h> | |
#include <dirent.h> | |
int main(int argc, const char **argv) { | |
if (argc < 2) return 1; | |
DIR *dir; | |
struct dirent *de; | |
struct stat info; | |
time_t cur = 0,new = 0; | |
char *dname = NULL; | |
chdir(argv[1]); | |
if ( !(dir=opendir("cur")) ) return 2; | |
while ( (de=readdir(dir)) ) | |
if (de->d_name[0] != '.') dname = de->d_name; | |
if (dname) { | |
chdir("cur"); | |
stat(dname,&info); | |
cur = info.st_mtime; | |
chdir("../"); | |
} | |
closedir(dir); | |
dname = NULL; | |
if ( !(dir=opendir("new")) ) return 3; | |
while ( (de=readdir(dir)) ) | |
if (de->d_name[0] != '.') dname = de->d_name; | |
if (dname) { | |
chdir("new"); | |
stat(dname,&info); | |
new = info.st_mtime; | |
chdir("../"); | |
} | |
closedir(dir); | |
if (difftime(new,cur) > 0) printf("newest"); | |
else if (new) printf("new"); | |
else if (cur) printf("old"); | |
else printf("none"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment