Remove troublesome chars from cachefile names

Add a funtion cache_safe_filename() which replaces possibly bad filename
characters with '_'.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
这个提交包含在:
Lars Hjemli
2007-01-12 00:24:35 +01:00
父节点 83a5f35a27
当前提交 2c2047ff67
共有 3 个文件被更改,包括 18 次插入1 次删除

16
cache.c
查看文件

@@ -10,6 +10,22 @@
const int NOLOCK = -1;
char *cache_safe_filename(const char *unsafe)
{
static char buf[PATH_MAX];
char *s = buf;
char c;
while(unsafe && (c = *unsafe++) != 0) {
if (c == '/' || c == ' ' || c == '&' || c == '|' ||
c == '>' || c == '<' || c == '.')
c = '_';
*s++ = c;
}
*s = '\0';
return buf;
}
int cache_exist(struct cacheitem *item)
{
if (stat(item->name, &item->st)) {