Mercurial > dillo_port1.3
changeset 88:f1eca1aba94a
- Removed a warning in dpi by adding a mkfname function.
author | jcid |
---|---|
date | Wed, 02 Jan 2008 14:50:36 +0100 |
parents | 091c76905e74 |
children | 2fddc4143a4c |
files | dpid/dpid.c dpid/misc_new.c dpid/misc_new.h |
diffstat | 3 files changed, 24 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/dpid/dpid.c Wed Jan 02 14:22:49 2008 +0100 +++ b/dpid/dpid.c Wed Jan 02 14:50:36 2008 +0100 @@ -608,7 +608,7 @@ dpi_nm = get_basename(dpi_attr->path); dpi_attr->sockpath = dStrconcat(sockdir, "/", dpi_nm, "-XXXXXX", NULL); - mktemp(dpi_attr->sockpath); + a_Misc_mkfname(dpi_attr->sockpath); if (strlen(dpi_attr->sockpath) > sp_len) { ERRMSG("init_all_dpi_sockets", "socket path is too long", 0); MSG_ERR("\n - it should be <= %lu chars", (ulong_t)sp_len);
--- a/dpid/misc_new.c Wed Jan 02 14:22:49 2008 +0100 +++ b/dpid/misc_new.c Wed Jan 02 14:50:36 2008 +0100 @@ -138,13 +138,29 @@ /* * Alternative to mkdtemp(). * Not as strong as mkdtemp, but enough for creating a directory. - * (adapted from dietlibc) */ char *a_Misc_mkdtemp(char *template) { + for (;;) { + if (a_Misc_mkfname(template) && mkdir(template, 0700) == 0) + break; + if (errno == EEXIST) + continue; + return 0; + } + return template; +} + +/* + * Return a new, non-existent file name from a template + * (adapted from dietlibc; alternative to mkdtemp()) + */ +char *a_Misc_mkfname(char *template) +{ char *tmp = template + strlen(template) - 6; int i; unsigned int random; + struct stat stat_buf; if (tmp < template) goto error; @@ -155,6 +171,7 @@ return 0; } srand((uint_t)(time(0) ^ getpid())); + for (;;) { random = (unsigned) rand(); for (i = 0; i < 6; ++i) { @@ -162,11 +179,9 @@ tmp[i] = hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0'; } - if (mkdir(template, 0700) == 0) - break; - if (errno == EEXIST) - continue; - return 0; + if (stat(template, &stat_buf) == -1 && errno == ENOENT) + return template; + + MSG_ERR("a_Misc_mkfname: another round for %s \n", template); } - return template; }