Skip to content

Instantly share code, notes, and snippets.

@TrilbyWhite
Created August 28, 2013 16:58
Show Gist options
  • Save TrilbyWhite/6368411 to your computer and use it in GitHub Desktop.
Save TrilbyWhite/6368411 to your computer and use it in GitHub Desktop.
Example of parsing a local maildir.
#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