18#include "../dlib/dlib.h"
39 rdlen = read(socket, &c, 1);
40 if (rdlen == -1 && errno != EINTR)
46 perror(
"a_Misc_rdtag");
67 tag = (
char *)
dMalloc(tagmem + 1);
68 for (i = 0; (rdln = read(sock, &c, 1)) != 0; i++) {
71 tag = (
char *)
dRealloc(tag, tagmem + 1);
81 ERRMSG(
"a_Misc_readtag",
"read", errno);
149 char *tmp =
template + strlen(
template) - 6;
152 struct stat stat_buf;
156 for (i = 0; i < 6; ++i)
162 srand((
uint_t)(time(0) ^ getpid()));
165 random = (unsigned) rand();
166 for (i = 0; i < 6; ++i) {
167 int hexdigit = (random >> (i * 5)) & 0x1f;
169 tmp[i] = hexdigit > 9 ? hexdigit +
'a' - 10 : hexdigit +
'0';
171 if (stat(
template, &stat_buf) == -1 && errno == ENOENT)
174 MSG_ERR(
"a_Misc_mkfname: another round for %s \n",
template);
185 char *secret =
dNew(
char, nchar + 1);
187 srand((
uint_t)(time(0) ^ getpid()));
188 random = (unsigned) rand();
189 for (i = 0; i < nchar; ++i) {
190 int hexdigit = (random >> (i * 5)) & 0x0f;
192 secret[i] = hexdigit > 9 ? hexdigit +
'a' - 10 : hexdigit +
'0';
195 MSG(
"a_Misc_mksecret: %s\n", secret);
Dstr * dStr_sized_new(int sz)
Create a new string with a given size.
void * dMalloc(size_t size)
void dStr_free(Dstr *ds, int all)
Free a dillo string.
void dStr_append_c(Dstr *ds, int c)
Append one character.
void * dRealloc(void *mem, size_t size)
#define dNew(type, count)
#define ERRMSG(CALLER, CALLED, ERR)
static void error(char *msg)
char * a_Misc_mkdtemp(char *template)
Alternative to mkdtemp().
char * a_Misc_readtag(int sock)
char * a_Misc_mksecret(int nchar)
Return a new, random hexadecimal string of 'nchar' characters.
Dstr * a_Misc_rdtag(int socket)
char * a_Misc_mkfname(char *template)
Return a new, nonexistent file name from a template.