Use a char array to map a number to a base36 digit.

This commit is contained in:
Todd C. Miller
2011-02-01 14:54:08 -05:00
parent 6fd9d853a8
commit af2ac7ccc6

View File

@@ -137,11 +137,12 @@ io_nextid(char *iolog_dir, char sessid[7])
{
struct stat sb;
char buf[32], *ep;
int fd, i, ch;
int fd, i;
unsigned long id = 0;
int len;
ssize_t nread;
char pathbuf[PATH_MAX];
static const char b36char[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/*
* Create I/O log directory if it doesn't already exist.
@@ -184,9 +185,8 @@ io_nextid(char *iolog_dir, char sessid[7])
* Note that that least significant digits go at the end of the string.
*/
for (i = 5; i >= 0; i--) {
ch = id % 36;
buf[i] = b36char[id % 36];
id /= 36;
buf[i] = ch < 10 ? ch + '0' : ch - 10 + 'A';
}
buf[6] = '\n';