[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:
Al
2017-03-10 13:39:43 -05:00
parent 3b33325c1a
commit b85ed70674
3 changed files with 8 additions and 4 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;