From df6a2228b73fcb0b8129498b6f03e2398da68d2a Mon Sep 17 00:00:00 2001 From: "Reece H. Dunn" Date: Sat, 4 Feb 2017 16:02:56 +0000 Subject: [PATCH] Use -EISDIR instead of -2 in GetFileLength for directories. --- src/libespeak-ng/readclause.c | 4 ++++ src/libespeak-ng/speech.c | 6 +++--- src/libespeak-ng/synth_mbrola.c | 2 ++ src/libespeak-ng/synthdata.c | 2 ++ src/libespeak-ng/voices.c | 15 ++++++++------- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/libespeak-ng/readclause.c b/src/libespeak-ng/readclause.c index 2c7135d6..d6f87dbc 100644 --- a/src/libespeak-ng/readclause.c +++ b/src/libespeak-ng/readclause.c @@ -847,6 +847,10 @@ static espeak_ng_STATUS LoadSoundFile(const char *fname, int index, espeak_ng_ER } length = GetFileLength(fname); + if (length < 0) { // length == -errno + fclose(f); + return create_file_error_context(context, -length, fname); + } if (fseek(f, 0, SEEK_SET) == -1) { int error = errno; fclose(f); diff --git a/src/libespeak-ng/speech.c b/src/libespeak-ng/speech.c index bde25f1c..9102a657 100644 --- a/src/libespeak-ng/speech.c +++ b/src/libespeak-ng/speech.c @@ -232,14 +232,14 @@ static int check_data_path(const char *path, int allow_directory) if (!path) return 0; snprintf(path_home, sizeof(path_home), "%s/espeak-ng-data", path); - if (GetFileLength(path_home) == -2) + if (GetFileLength(path_home) == -EISDIR) return 1; if (!allow_directory) return 0; snprintf(path_home, sizeof(path_home), "%s", path); - return GetFileLength(path_home) == -2; + return GetFileLength(path_home) == -EISDIR; } #pragma GCC visibility push(default) @@ -284,7 +284,7 @@ int GetFileLength(const char *filename) return 0; if (S_ISDIR(statbuf.st_mode)) - return -2; // a directory + return -EISDIR; return statbuf.st_size; } diff --git a/src/libespeak-ng/synth_mbrola.c b/src/libespeak-ng/synth_mbrola.c index 8b61e794..2e18646f 100644 --- a/src/libespeak-ng/synth_mbrola.c +++ b/src/libespeak-ng/synth_mbrola.c @@ -101,6 +101,8 @@ espeak_ng_STATUS LoadMbrolaTable(const char *mbrola_voice, const char *phtrans, // read eSpeak's mbrola phoneme translation data, eg. en1_phtrans sprintf(path, "%s/mbrola_ph/%s", path_home, phtrans); size = GetFileLength(path); + if (size < 0) // size == -errno + return -size; if ((f_in = fopen(path, "rb")) == NULL) { int error = errno; close_MBR(); diff --git a/src/libespeak-ng/synthdata.c b/src/libespeak-ng/synthdata.c index f0bd022b..ea02c179 100644 --- a/src/libespeak-ng/synthdata.c +++ b/src/libespeak-ng/synthdata.c @@ -78,6 +78,8 @@ static espeak_ng_STATUS ReadPhFile(void **ptr, const char *fname, int *size, esp sprintf(buf, "%s%c%s", path_home, PATHSEP, fname); length = GetFileLength(buf); + if (length < 0) // length == -errno + return create_file_error_context(context, -length, buf); if ((f_in = fopen(buf, "rb")) == NULL) return create_file_error_context(context, errno, buf); diff --git a/src/libespeak-ng/voices.c b/src/libespeak-ng/voices.c index ce48b68d..83b93570 100644 --- a/src/libespeak-ng/voices.c +++ b/src/libespeak-ng/voices.c @@ -20,6 +20,7 @@ #include "config.h" #include +#include #include #include #include @@ -1190,7 +1191,7 @@ static int SetVoiceScores(espeak_VOICE *voice_select, espeak_VOICE **voices, int } sprintf(buf, "%s/voices/%s", path_home, language); - if (GetFileLength(buf) == -2) { + if (GetFileLength(buf) == -EISDIR) { // A subdirectory name has been specified. List all the voices in that subdirectory language[lang_len++] = PATHSEP; language[lang_len] = 0; @@ -1430,11 +1431,11 @@ static void GetVoices(const char *path) sprintf(fname, "%s%c%s", path, PATHSEP, FindFileData.cFileName); ftype = GetFileLength(fname); - if (ftype == -2) { - // a sub-sirectory + if (ftype == -EISDIR) { + // a sub-directory GetVoices(fname); } else if (ftype > 0) { - // a regular line, add it to the voices list + // a regular file, add it to the voices list if ((f_voice = fopen(fname, "r")) == NULL) continue; @@ -1466,11 +1467,11 @@ static void GetVoices(const char *path) ftype = GetFileLength(fname); - if (ftype == -2) { - // a sub-sirectory + if (ftype == -EISDIR) { + // a sub-directory GetVoices(fname); } else if (ftype > 0) { - // a regular line, add it to the voices list + // a regular file, add it to the voices list if ((f_voice = fopen(fname, "r")) == NULL) continue;