Last active
May 29, 2018 13:33
-
-
Save hfm/fecc933d5b68a1f200854e16fe85a3f4 to your computer and use it in GitHub Desktop.
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 <dirent.h> | |
#include <fstream> | |
#include <libgen.h> | |
#include <stdio.h> | |
int main(void) { | |
int maxidx = 0; | |
DIR *dir; | |
struct dirent *ent; | |
const char *base_filename = "queries.log"; | |
const char *datadir = "log"; | |
size_t efl = strlen(base_filename); | |
if ((dir = opendir(datadir)) != NULL) { | |
while ((ent = readdir(dir)) != NULL) { | |
if (strlen(ent->d_name) == efl + 9) { | |
if (strncmp(ent->d_name, base_filename, efl) == 0) { | |
if (ent->d_name[efl] == '.') { | |
int idx = atoi(ent->d_name + efl + 1); | |
if (idx > maxidx) | |
maxidx = idx; | |
} | |
} | |
} | |
} | |
closedir(dir); | |
} else { | |
/* could not open directory */ | |
printf("Unable to open datadir: %s\n", datadir); | |
exit(EXIT_FAILURE); | |
} | |
printf("Current ID is %i\n", maxidx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment