Use a char array to map a number to a base36 digit.
This commit is contained in:
@@ -137,11 +137,12 @@ io_nextid(char *iolog_dir, char sessid[7])
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char buf[32], *ep;
|
char buf[32], *ep;
|
||||||
int fd, i, ch;
|
int fd, i;
|
||||||
unsigned long id = 0;
|
unsigned long id = 0;
|
||||||
int len;
|
int len;
|
||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
char pathbuf[PATH_MAX];
|
char pathbuf[PATH_MAX];
|
||||||
|
static const char b36char[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create I/O log directory if it doesn't already exist.
|
* 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.
|
* Note that that least significant digits go at the end of the string.
|
||||||
*/
|
*/
|
||||||
for (i = 5; i >= 0; i--) {
|
for (i = 5; i >= 0; i--) {
|
||||||
ch = id % 36;
|
buf[i] = b36char[id % 36];
|
||||||
id /= 36;
|
id /= 36;
|
||||||
buf[i] = ch < 10 ? ch + '0' : ch - 10 + 'A';
|
|
||||||
}
|
}
|
||||||
buf[6] = '\n';
|
buf[6] = '\n';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user