mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-02 06:01:53 +00:00
Use -EISDIR instead of -2 in GetFileLength for directories.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user