From 286af66cfb787b76ee7289c920a75a3dd21ce795 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 26 Dec 2004 12:45:22 +0100 Subject: Made several functions threadsafe (cont'd) --- videodir.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'videodir.c') diff --git a/videodir.c b/videodir.c index 94e7141a..f0e54fe7 100644 --- a/videodir.c +++ b/videodir.c @@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: videodir.c 1.10 2003/08/02 13:43:28 kls Exp $ + * $Id: videodir.c 1.11 2004/12/26 11:52:12 kls Exp $ */ #include "videodir.h" @@ -197,27 +197,23 @@ int VideoDiskSpace(int *FreeMB, int *UsedMB) return (free + used) ? used * 100 / (free + used) : 0; } -const char *PrefixVideoFileName(const char *FileName, char Prefix) +cString PrefixVideoFileName(const char *FileName, char Prefix) { - static char *PrefixedName = NULL; - - if (!PrefixedName || strlen(PrefixedName) <= strlen(FileName)) - PrefixedName = (char *)realloc(PrefixedName, strlen(FileName) + 2); - if (PrefixedName) { - const char *p = FileName + strlen(FileName); // p points at the terminating 0 - int n = 2; - while (p-- > FileName && n > 0) { - if (*p == '/') { - if (--n == 0) { - int l = p - FileName + 1; - strncpy(PrefixedName, FileName, l); - PrefixedName[l] = Prefix; - strcpy(PrefixedName + l + 1, p + 1); - return PrefixedName; - } + char PrefixedName[strlen(FileName) + 2]; + + const char *p = FileName + strlen(FileName); // p points at the terminating 0 + int n = 2; + while (p-- > FileName && n > 0) { + if (*p == '/') { + if (--n == 0) { + int l = p - FileName + 1; + strncpy(PrefixedName, FileName, l); + PrefixedName[l] = Prefix; + strcpy(PrefixedName + l + 1, p + 1); + return PrefixedName; } } - } + } return NULL; } -- cgit v1.2.3