[utils] adding a function for checking if files exists (yay C), or at least the closest agreed-upon method for it (may return false if the user doesn't have permissions, but that's ok for our purposes here)
This commit is contained in:
@@ -31,7 +31,6 @@ bool crf_trainer_hash_feature_to_id_exists(crf_trainer_t *self, char *feature, u
|
||||
bool crf_trainer_hash_prev_tag_feature_to_id(crf_trainer_t *self, char *feature, uint32_t *feature_id);
|
||||
bool crf_trainer_hash_prev_tag_feature_to_id_exists(crf_trainer_t *self, char *feature, uint32_t *feature_id, bool *exists);
|
||||
|
||||
|
||||
bool crf_trainer_get_feature_id(crf_trainer_t *self, char *feature, uint32_t *feature_id);
|
||||
bool crf_trainer_get_prev_tag_feature_id(crf_trainer_t *self, char *feature, uint32_t *feature_id);
|
||||
|
||||
|
||||
@@ -32,6 +32,13 @@ char *file_getline(FILE * f)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool file_exists(char *filename) {
|
||||
FILE *f = fopen(filename, "r");
|
||||
bool exists = f != NULL;
|
||||
if (exists) fclose(f);
|
||||
return exists;
|
||||
}
|
||||
|
||||
bool is_relative_path(struct dirent *ent) {
|
||||
return strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0;
|
||||
}
|
||||
|
||||
@@ -47,11 +47,9 @@ bool shuffle_file_chunked(char *filename, size_t parts) {
|
||||
}
|
||||
|
||||
// Make sure the input file exists
|
||||
FILE *f = fopen(filename, "r");
|
||||
if (f == NULL) {
|
||||
if (!file_exists(filename)) {
|
||||
return false;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
// This is an in-place shuffle to keep the API simple
|
||||
char *outfile = filename;
|
||||
|
||||
Reference in New Issue
Block a user