Create different IDs for each bar (+test)

This commit is contained in:
Michael Stapelberg
2011-10-19 19:57:39 +01:00
parent 063b124e35
commit 15bface10d
3 changed files with 47 additions and 3 deletions

View File

@ -934,7 +934,14 @@ bar:
{
printf("\t new bar configuration finished, saving.\n");
/* Generate a unique ID for this bar */
current_bar.id = sstrdup("foo"); /* TODO */
current_bar.id = sstrdup("bar-XXXXXX");
/* This works similar to mktemp in that it replaces the last six X with
* random letters, but without the restriction that the given buffer
* has to contain a valid path name. */
char *x = current_bar.id + strlen("bar-");
while (*x != '\0') {
*(x++) = (rand() % 26) + 'a';
}
/* Copy the current (static) structure into a dynamically allocated
* one, then cleanup our static one. */

View File

@ -217,6 +217,8 @@ int main(int argc, char *argv[]) {
if (!isatty(fileno(stdout)))
setbuf(stdout, NULL);
srand(time(NULL));
init_logging();
start_argv = argv;