1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Replaced strncpy() and strn0cpy() with Utf8Strn0Cpy() where necessary

This commit is contained in:
Klaus Schmidinger 2007-06-16 10:41:21 +02:00
parent 81e44bce19
commit b532dc8229
8 changed files with 48 additions and 23 deletions

View File

@ -5240,3 +5240,4 @@ Video Disk Recorder Revision History
Thomas Günther). The codeset names in 'libsi/si.c' have been changed to the Thomas Günther). The codeset names in 'libsi/si.c' have been changed to the
canonical spelling with '-' (thanks to Ludwig Nussel for pointing this out). canonical spelling with '-' (thanks to Ludwig Nussel for pointing this out).
- Modified handling invalid characters in VFAT mode. - Modified handling invalid characters in VFAT mode.
- Replaced strn0cpy() with Utf8Strn0Cpy() where necessary.

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: config.c 1.151 2007/06/02 11:21:40 kls Exp $ * $Id: config.c 1.152 2007/06/16 09:30:22 kls Exp $
*/ */
#include "config.h" #include "config.h"
@ -385,8 +385,8 @@ bool cSetup::ParseLanguages(const char *Value, int *Values)
bool cSetup::Parse(const char *Name, const char *Value) bool cSetup::Parse(const char *Name, const char *Value)
{ {
if (!strcasecmp(Name, "OSDLanguage")) OSDLanguage = atoi(Value); if (!strcasecmp(Name, "OSDLanguage")) OSDLanguage = atoi(Value);
else if (!strcasecmp(Name, "OSDSkin")) strn0cpy(OSDSkin, Value, MaxSkinName); else if (!strcasecmp(Name, "OSDSkin")) Utf8Strn0Cpy(OSDSkin, Value, MaxSkinName);
else if (!strcasecmp(Name, "OSDTheme")) strn0cpy(OSDTheme, Value, MaxThemeName); else if (!strcasecmp(Name, "OSDTheme")) Utf8Strn0Cpy(OSDTheme, Value, MaxThemeName);
else if (!strcasecmp(Name, "PrimaryDVB")) PrimaryDVB = atoi(Value); else if (!strcasecmp(Name, "PrimaryDVB")) PrimaryDVB = atoi(Value);
else if (!strcasecmp(Name, "ShowInfoOnChSwitch")) ShowInfoOnChSwitch = atoi(Value); else if (!strcasecmp(Name, "ShowInfoOnChSwitch")) ShowInfoOnChSwitch = atoi(Value);
else if (!strcasecmp(Name, "TimeoutRequChInfo")) TimeoutRequChInfo = atoi(Value); else if (!strcasecmp(Name, "TimeoutRequChInfo")) TimeoutRequChInfo = atoi(Value);
@ -394,7 +394,7 @@ bool cSetup::Parse(const char *Name, const char *Value)
else if (!strcasecmp(Name, "MenuScrollWrap")) MenuScrollWrap = atoi(Value); else if (!strcasecmp(Name, "MenuScrollWrap")) MenuScrollWrap = atoi(Value);
else if (!strcasecmp(Name, "MenuKeyCloses")) MenuKeyCloses = atoi(Value); else if (!strcasecmp(Name, "MenuKeyCloses")) MenuKeyCloses = atoi(Value);
else if (!strcasecmp(Name, "MarkInstantRecord")) MarkInstantRecord = atoi(Value); else if (!strcasecmp(Name, "MarkInstantRecord")) MarkInstantRecord = atoi(Value);
else if (!strcasecmp(Name, "NameInstantRecord")) strn0cpy(NameInstantRecord, Value, MaxFileName); else if (!strcasecmp(Name, "NameInstantRecord")) Utf8Strn0Cpy(NameInstantRecord, Value, MaxFileName);
else if (!strcasecmp(Name, "InstantRecordTime")) InstantRecordTime = atoi(Value); else if (!strcasecmp(Name, "InstantRecordTime")) InstantRecordTime = atoi(Value);
else if (!strcasecmp(Name, "LnbSLOF")) LnbSLOF = atoi(Value); else if (!strcasecmp(Name, "LnbSLOF")) LnbSLOF = atoi(Value);
else if (!strcasecmp(Name, "LnbFrequLo")) LnbFrequLo = atoi(Value); else if (!strcasecmp(Name, "LnbFrequLo")) LnbFrequLo = atoi(Value);
@ -435,9 +435,9 @@ bool cSetup::Parse(const char *Name, const char *Value)
else if (!strcasecmp(Name, "OSDMessageTime")) OSDMessageTime = atoi(Value); else if (!strcasecmp(Name, "OSDMessageTime")) OSDMessageTime = atoi(Value);
else if (!strcasecmp(Name, "UseSmallFont")) UseSmallFont = atoi(Value); else if (!strcasecmp(Name, "UseSmallFont")) UseSmallFont = atoi(Value);
else if (!strcasecmp(Name, "AntiAlias")) AntiAlias = atoi(Value); else if (!strcasecmp(Name, "AntiAlias")) AntiAlias = atoi(Value);
else if (!strcasecmp(Name, "FontOsd")) strn0cpy(FontOsd, Value, MAXFONTNAME); else if (!strcasecmp(Name, "FontOsd")) Utf8Strn0Cpy(FontOsd, Value, MAXFONTNAME);
else if (!strcasecmp(Name, "FontSml")) strn0cpy(FontSml, Value, MAXFONTNAME); else if (!strcasecmp(Name, "FontSml")) Utf8Strn0Cpy(FontSml, Value, MAXFONTNAME);
else if (!strcasecmp(Name, "FontFix")) strn0cpy(FontFix, Value, MAXFONTNAME); else if (!strcasecmp(Name, "FontFix")) Utf8Strn0Cpy(FontFix, Value, MAXFONTNAME);
else if (!strcasecmp(Name, "FontOsdSize")) FontOsdSize = atoi(Value); else if (!strcasecmp(Name, "FontOsdSize")) FontOsdSize = atoi(Value);
else if (!strcasecmp(Name, "FontSmlSize")) FontSmlSize = atoi(Value); else if (!strcasecmp(Name, "FontSmlSize")) FontSmlSize = atoi(Value);
else if (!strcasecmp(Name, "FontFixSize")) FontFixSize = atoi(Value); else if (!strcasecmp(Name, "FontFixSize")) FontFixSize = atoi(Value);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: device.c 1.140 2007/04/30 09:34:00 kls Exp $ * $Id: device.c 1.141 2007/06/16 09:31:32 kls Exp $
*/ */
#include "device.h" #include "device.h"
@ -859,7 +859,7 @@ bool cDevice::SetAvailableTrack(eTrackType Type, int Index, uint16_t Id, const c
if (Language) if (Language)
strn0cpy(availableTracks[t].language, Language, sizeof(availableTracks[t].language)); strn0cpy(availableTracks[t].language, Language, sizeof(availableTracks[t].language));
if (Description) if (Description)
strn0cpy(availableTracks[t].description, Description, sizeof(availableTracks[t].description)); Utf8Strn0Cpy(availableTracks[t].description, Description, sizeof(availableTracks[t].description));
if (Id) { if (Id) {
availableTracks[t].id = Id; // setting 'id' last to avoid the need for extensive locking availableTracks[t].id = Id; // setting 'id' last to avoid the need for extensive locking
int numAudioTracks = NumAudioTracks(); int numAudioTracks = NumAudioTracks();

12
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menu.c 1.451 2007/06/09 14:36:46 kls Exp $ * $Id: menu.c 1.452 2007/06/16 09:33:21 kls Exp $
*/ */
#include "menu.h" #include "menu.h"
@ -2239,14 +2239,14 @@ eOSState cMenuSetupOSD::ProcessKey(eKeys Key)
if (skinIndex != originalSkinIndex) { if (skinIndex != originalSkinIndex) {
cSkin *Skin = Skins.Get(skinIndex); cSkin *Skin = Skins.Get(skinIndex);
if (Skin) { if (Skin) {
strn0cpy(data.OSDSkin, Skin->Name(), sizeof(data.OSDSkin)); Utf8Strn0Cpy(data.OSDSkin, Skin->Name(), sizeof(data.OSDSkin));
Skins.SetCurrent(Skin->Name()); Skins.SetCurrent(Skin->Name());
ModifiedApperance = true; ModifiedApperance = true;
} }
} }
if (themes.NumThemes() && Skins.Current()->Theme()) { if (themes.NumThemes() && Skins.Current()->Theme()) {
Skins.Current()->Theme()->Load(themes.FileName(themeIndex)); Skins.Current()->Theme()->Load(themes.FileName(themeIndex));
strn0cpy(data.OSDTheme, themes.Name(themeIndex), sizeof(data.OSDTheme)); Utf8Strn0Cpy(data.OSDTheme, themes.Name(themeIndex), sizeof(data.OSDTheme));
ModifiedApperance |= themeIndex != originalThemeIndex; ModifiedApperance |= themeIndex != originalThemeIndex;
} }
if (data.OSDLeft != Setup.OSDLeft || data.OSDTop != Setup.OSDTop || data.OSDWidth != Setup.OSDWidth || data.OSDHeight != Setup.OSDHeight) { if (data.OSDLeft != Setup.OSDLeft || data.OSDTop != Setup.OSDTop || data.OSDWidth != Setup.OSDWidth || data.OSDHeight != Setup.OSDHeight) {
@ -2256,9 +2256,9 @@ eOSState cMenuSetupOSD::ProcessKey(eKeys Key)
if (data.UseSmallFont != Setup.UseSmallFont || data.AntiAlias != Setup.AntiAlias) if (data.UseSmallFont != Setup.UseSmallFont || data.AntiAlias != Setup.AntiAlias)
ModifiedApperance = true; ModifiedApperance = true;
if (fontNames.Size()) { if (fontNames.Size()) {
strn0cpy(data.FontOsd, fontNames[fontOsdIndex], sizeof(data.FontOsd)); Utf8Strn0Cpy(data.FontOsd, fontNames[fontOsdIndex], sizeof(data.FontOsd));
strn0cpy(data.FontSml, fontNames[fontSmlIndex], sizeof(data.FontSml)); Utf8Strn0Cpy(data.FontSml, fontNames[fontSmlIndex], sizeof(data.FontSml));
strn0cpy(data.FontFix, fontNames[fontFixIndex], sizeof(data.FontFix)); Utf8Strn0Cpy(data.FontFix, fontNames[fontFixIndex], sizeof(data.FontFix));
} }
if (strcmp(data.FontOsd, Setup.FontOsd) || data.FontOsdSize != Setup.FontOsdSize) { if (strcmp(data.FontOsd, Setup.FontOsd) || data.FontOsdSize != Setup.FontOsdSize) {
cFont::SetFont(fontOsd, data.FontOsd, data.FontOsdSize); cFont::SetFont(fontOsd, data.FontOsd, data.FontOsdSize);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: recording.c 1.152 2007/06/16 08:57:22 kls Exp $ * $Id: recording.c 1.153 2007/06/16 09:36:08 kls Exp $
*/ */
#include "recording.h" #include "recording.h"
@ -480,7 +480,7 @@ cRecording::cRecording(cTimer *Timer, const cEvent *Event)
Subtitle = " "; Subtitle = " ";
else if (strlen(Subtitle) > MAX_SUBTITLE_LENGTH) { else if (strlen(Subtitle) > MAX_SUBTITLE_LENGTH) {
// let's make sure the Subtitle doesn't produce too long a file name: // let's make sure the Subtitle doesn't produce too long a file name:
strn0cpy(SubtitleBuffer, Subtitle, MAX_SUBTITLE_LENGTH); Utf8Strn0Cpy(SubtitleBuffer, Subtitle, MAX_SUBTITLE_LENGTH);
Subtitle = SubtitleBuffer; Subtitle = SubtitleBuffer;
} }
char *macroTITLE = strstr(Timer->File(), TIMERMACRO_TITLE); char *macroTITLE = strstr(Timer->File(), TIMERMACRO_TITLE);

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: timers.c 1.66 2007/06/03 13:48:57 kls Exp $ * $Id: timers.c 1.67 2007/06/16 10:41:21 kls Exp $
*/ */
#include "timers.h" #include "timers.h"
@ -78,7 +78,7 @@ cTimer::cTimer(const cEvent *Event)
*file = 0; *file = 0;
const char *Title = Event->Title(); const char *Title = Event->Title();
if (!isempty(Title)) if (!isempty(Title))
strn0cpy(file, Event->Title(), sizeof(file)); Utf8Strn0Cpy(file, Event->Title(), sizeof(file));
aux = NULL; aux = NULL;
event = NULL; // let SetEvent() be called to get a log message event = NULL; // let SetEvent() be called to get a log message
} }
@ -286,7 +286,7 @@ bool cTimer::Parse(const char *s)
} }
//TODO add more plausibility checks //TODO add more plausibility checks
result = ParseDay(daybuffer, day, weekdays); result = ParseDay(daybuffer, day, weekdays);
strn0cpy(file, filebuffer, MaxFileName); Utf8Strn0Cpy(file, filebuffer, MaxFileName);
strreplace(file, '|', ':'); strreplace(file, '|', ':');
if (isnumber(channelbuffer)) if (isnumber(channelbuffer))
channel = Channels.GetByNumber(atoi(channelbuffer)); channel = Channels.GetByNumber(atoi(channelbuffer));
@ -358,7 +358,7 @@ time_t cTimer::SetTime(time_t t, int SecondsFromMidnight)
char *cTimer::SetFile(const char *File) char *cTimer::SetFile(const char *File)
{ {
if (!isempty(File)) if (!isempty(File))
strn0cpy(file, File, sizeof(file)); Utf8Strn0Cpy(file, File, sizeof(file));
return file; return file;
} }

21
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.c 1.127 2007/06/16 09:05:11 kls Exp $ * $Id: tools.c 1.128 2007/06/16 09:22:40 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -661,6 +661,25 @@ int Utf8StrLen(const char *s)
return n; return n;
} }
char *Utf8Strn0Cpy(char *Dest, const char *Src, int n)
{
if (cCharSetConv::SystemCharacterTable())
return strn0cpy(Dest, Src, n);
char *d = Dest;
while (*Src) {
int sl = Utf8CharLen(Src);
n -= sl;
if (n > 0) {
while (sl--)
*d++ = *Src++;
}
else
break;
}
*d = 0;
return Dest;
}
int Utf8ToArray(const char *s, uint *a, int Size) int Utf8ToArray(const char *s, uint *a, int Size)
{ {
int n = 0; int n = 0;

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.h 1.100 2007/06/16 09:05:22 kls Exp $ * $Id: tools.h 1.101 2007/06/16 09:15:40 kls Exp $
*/ */
#ifndef __TOOLS_H #ifndef __TOOLS_H
@ -96,6 +96,11 @@ int Utf8SymChars(const char *s, int Symbols);
int Utf8StrLen(const char *s); int Utf8StrLen(const char *s);
///< Returns the number of UTF-8 symbols formed by the given string of ///< Returns the number of UTF-8 symbols formed by the given string of
///< character bytes. ///< character bytes.
char *Utf8Strn0Cpy(char *Dest, const char *Src, int n);
///< Copies at most n character bytes from Src to Dst, making sure that the
///< resulting copy ends with a complete UTF-8 symbol. The copy is guaranteed
///< to be zero terminated.
///< Returns a pointer to Dest.
int Utf8ToArray(const char *s, uint *a, int Size); int Utf8ToArray(const char *s, uint *a, int Size);
///< Converts the given character bytes (including the terminating 0) into an ///< Converts the given character bytes (including the terminating 0) into an
///< array of UTF-8 symbols of the given Size. Returns the number of symbols ///< array of UTF-8 symbols of the given Size. Returns the number of symbols