While contributing to exim, I saw many values where hard-coded :
uschar filebuffer[256];
(void)sprintf(CS filebuffer, "%.256s.db", filename);
rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
"dbm", errmsg);
if (rc < 0) /* stat() failed */
{
(void)sprintf(CS filebuffer, "%.256s.dir", filename);
rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
"dbm", errmsg);
if (rc == 0) /* x.dir was OK */
{
(void)sprintf(CS filebuffer, "%.256s.pag", filename);
rc = lf_check_file(-1, filebuffer, S_IFREG, modemask, owners, owngroups,
"dbm", errmsg);
}
}
}
As the code isn’t windows specific, every256
values should be converted toPATH_MAX
.
I know that expanding macros inside quoted strings isn’t possible, but that string concatenation is trivial :
#define STR "string"
size_t len=strlen("part"STR"part 2");
However, things like :
"%."PATH_MAX".db"
Shouldn’t work becausePATH_MAX
expands to an integer, not a string.
So is there a way to do this without calling a function that convert integers to C strings ?