diff options
| author | Lars Hjemli | 2007-01-12 00:24:35 +0100 |
|---|---|---|
| committer | Lars Hjemli | 2007-01-12 00:24:35 +0100 |
| commit | 2c2047ff67a1e0053f95776e5079e432f69cea54 (patch) | |
| tree | 0572bd25c3f7ef43494664cca750c940c9e93ef1 /cache.c | |
| parent | 83a5f35a2724ee60bfd8c5679b98da7008272254 (diff) | |
| download | cgit-2c2047ff67a1e0053f95776e5079e432f69cea54.tar.gz cgit-2c2047ff67a1e0053f95776e5079e432f69cea54.tar.bz2 cgit-2c2047ff67a1e0053f95776e5079e432f69cea54.zip | |
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>
Diffstat (limited to 'cache.c')
| -rw-r--r-- | cache.c | 16 |
1 files changed, 16 insertions, 0 deletions
| @@ -10,6 +10,22 @@ | |||
| 10 | 10 | ||
| 11 | const int NOLOCK = -1; | 11 | const int NOLOCK = -1; |
| 12 | 12 | ||
| 13 | char *cache_safe_filename(const char *unsafe) | ||
| 14 | { | ||
| 15 | static char buf[PATH_MAX]; | ||
| 16 | char *s = buf; | ||
| 17 | char c; | ||
| 18 | |||
| 19 | while(unsafe && (c = *unsafe++) != 0) { | ||
| 20 | if (c == '/' || c == ' ' || c == '&' || c == '|' || | ||
| 21 | c == '>' || c == '<' || c == '.') | ||
| 22 | c = '_'; | ||
| 23 | *s++ = c; | ||
| 24 | } | ||
| 25 | *s = '\0'; | ||
| 26 | return buf; | ||
| 27 | } | ||
| 28 | |||
| 13 | int cache_exist(struct cacheitem *item) | 29 | int cache_exist(struct cacheitem *item) |
| 14 | { | 30 | { |
| 15 | if (stat(item->name, &item->st)) { | 31 | if (stat(item->name, &item->st)) { |
