code cleanup: move strncpy0 to common.c

This commit is contained in:
Juho Hiltunen
2022-09-04 07:12:39 +03:00
parent c4d8976fbc
commit b52d1f3afd
11 changed files with 19 additions and 20 deletions
+6
View File
@@ -51,4 +51,10 @@ int GetFileLength(const char *filename)
return statbuf.st_size; return statbuf.st_size;
} }
void strncpy0(char *to, const char *from, int size)
{
// strcpy with limit, ensures a zero terminator
strncpy(to, from, size);
to[size-1] = 0;
}
#pragma GCC visibility pop #pragma GCC visibility pop
+1
View File
@@ -23,6 +23,7 @@
#include "espeak-ng/espeak_ng.h" #include "espeak-ng/espeak_ng.h"
extern ESPEAK_NG_API int GetFileLength(const char *filename); extern ESPEAK_NG_API int GetFileLength(const char *filename);
extern ESPEAK_NG_API void strncpy0(char *to, const char *from, int size);
#ifdef __cplusplus #ifdef __cplusplus
} }
+1 -2
View File
@@ -35,8 +35,7 @@
#include <espeak-ng/speak_lib.h> #include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "common.h" // for GetFileLength #include "common.h" // for GetFileLength, strncpy0
#include "dictionary.h" // for strncpy0
#include "error.h" // for create_file_error_context #include "error.h" // for create_file_error_context
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB #include "mnemonics.h" // for LookupMnemName, MNEM_TAB
#include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST #include "phoneme.h" // for PHONEME_TAB, PHONEME_TAB_LIST
+2 -1
View File
@@ -33,8 +33,9 @@
#include <espeak-ng/speak_lib.h> #include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "common.h" // for strncpy0
#include "compiledict.h" #include "compiledict.h"
#include "dictionary.h" // for EncodePhonemes, strncpy0, HashDicti... #include "dictionary.h" // for EncodePhonemes, HashDicti...
#include "error.h" // for create_file_error_context #include "error.h" // for create_file_error_context
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB #include "mnemonics.h" // for LookupMnemName, MNEM_TAB
#include "phoneme.h" // for PHONEME_TAB_LIST, phonSWITCH, phone... #include "phoneme.h" // for PHONEME_TAB_LIST, phonSWITCH, phone...
+1 -10
View File
@@ -32,7 +32,7 @@
#include <espeak-ng/speak_lib.h> #include <espeak-ng/speak_lib.h>
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "common.h" // for GetFileLength #include "common.h" // for GetFileLength, strncpy0
#include "dictionary.h" #include "dictionary.h"
#include "numbers.h" // for LookupAccentedLetter, Look... #include "numbers.h" // for LookupAccentedLetter, Look...
#include "phoneme.h" // for PHONEME_TAB, phVOWEL, phon... #include "phoneme.h" // for PHONEME_TAB, phVOWEL, phon...
@@ -91,15 +91,6 @@ static unsigned char remove_accent[N_REMOVE_ACCENT] = {
'a', 'a', 'a', 'b', 'o', 'c', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e' 'a', 'a', 'a', 'b', 'o', 'c', 'd', 'd', 'e', 'e', 'e', 'e', 'e', 'e'
}; };
#pragma GCC visibility push(default)
void strncpy0(char *to, const char *from, int size)
{
// strcpy with limit, ensures a zero terminator
strncpy(to, from, size);
to[size-1] = 0;
}
#pragma GCC visibility pop
static int Reverse4Bytes(int word) static int Reverse4Bytes(int word)
{ {
// reverse the order of bytes from little-endian to big-endian // reverse the order of bytes from little-endian to big-endian
-1
View File
@@ -31,7 +31,6 @@ extern "C"
{ {
#endif #endif
extern ESPEAK_NG_API void strncpy0(char *to, const char *from, int size);
int LoadDictionary(Translator *tr, const char *name, int no_error); int LoadDictionary(Translator *tr, const char *name, int no_error);
int HashDictionary(const char *string); int HashDictionary(const char *string);
const char *EncodePhonemes(const char *p, char *outptr, int *bad_phoneme); const char *EncodePhonemes(const char *p, char *outptr, int *bad_phoneme);
+1 -1
View File
@@ -27,7 +27,7 @@
#include <espeak-ng/espeak_ng.h> #include <espeak-ng/espeak_ng.h>
#include "error.h" #include "error.h"
#include "dictionary.h" // for strncpy0 #include "common.h" // for strncpy0
espeak_ng_STATUS espeak_ng_STATUS
create_file_error_context(espeak_ng_ERROR_CONTEXT *context, create_file_error_context(espeak_ng_ERROR_CONTEXT *context,
+1 -1
View File
@@ -37,7 +37,7 @@
#include <ucd/ucd.h> #include <ucd/ucd.h>
#include "readclause.h" #include "readclause.h"
#include "common.h" // for GetFileLength #include "common.h" // for GetFileLength, strncpy0
#include "config.h" // for HAVE_MKSTEMP #include "config.h" // for HAVE_MKSTEMP
#include "dictionary.h" // for LookupDictList, DecodePhonemes, Set... #include "dictionary.h" // for LookupDictList, DecodePhonemes, Set...
#include "error.h" // for create_file_error_context #include "error.h" // for create_file_error_context
+1 -1
View File
@@ -40,7 +40,7 @@
#include <ucd/ucd.h> #include <ucd/ucd.h>
#include "ssml.h" #include "ssml.h"
#include "dictionary.h" // for strncpy0 #include "common.h" // for strncpy0
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB, #include "mnemonics.h" // for LookupMnemName, MNEM_TAB,
#include "readclause.h" // for PARAM_STACK, param_stack, AddNameData #include "readclause.h" // for PARAM_STACK, param_stack, AddNameData
#include "soundicon.h" // for LoadSoundFile2 #include "soundicon.h" // for LoadSoundFile2
+3 -1
View File
@@ -34,6 +34,8 @@
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "translate.h" #include "translate.h"
#include "translateword.h"
#include "common.h" // for strncpy0
#include "dictionary.h" // for TranslateRules, LookupDictList, Cha... #include "dictionary.h" // for TranslateRules, LookupDictList, Cha...
#include "numbers.h" // for SetSpellingStress, ... #include "numbers.h" // for SetSpellingStress, ...
#include "phoneme.h" // for phonSWITCH, PHONEME_TAB, phonPAUSE_... #include "phoneme.h" // for phonSWITCH, PHONEME_TAB, phonPAUSE_...
@@ -41,7 +43,7 @@
#include "synthdata.h" // for SelectPhonemeTable, LookupPhonemeTable #include "synthdata.h" // for SelectPhonemeTable, LookupPhonemeTable
#include "ucd/ucd.h" // for ucd_toupper #include "ucd/ucd.h" // for ucd_toupper
#include "voice.h" // for voice, voice_t #include "voice.h" // for voice, voice_t
#include "translateword.h"
static void addPluralSuffixes(int flags, Translator *tr, char last_char, char *word_phonemes); static void addPluralSuffixes(int flags, Translator *tr, char last_char, char *word_phonemes);
static int CheckDottedAbbrev(char *word1); static int CheckDottedAbbrev(char *word1);
+2 -2
View File
@@ -39,8 +39,8 @@
#include <espeak-ng/encoding.h> #include <espeak-ng/encoding.h>
#include "voice.h" // for voice_t, DoVoiceChange, N_PEAKS #include "voice.h" // for voice_t, DoVoiceChange, N_PEAKS
#include "common.h" // for GetFileLength #include "common.h" // for GetFileLength, strncpy0
#include "dictionary.h" // for strncpy0, LoadDictionary #include "dictionary.h" // for LoadDictionary
#include "mnemonics.h" // for LookupMnemName, MNEM_TAB #include "mnemonics.h" // for LookupMnemName, MNEM_TAB
#include "phoneme.h" // for REPLACE_PHONEMES, n_replace_pho... #include "phoneme.h" // for REPLACE_PHONEMES, n_replace_pho...
#include "speech.h" // for PATHSEP #include "speech.h" // for PATHSEP