/* ** fr_open ** ** open a file ** ** INPUT : filename - file to be opened ** mode - open method (r,w,a,r+,w+,a+) ** RETURN: pointer to a file descriptor or 0 on error */ F_FILE * fr_open ( const char * filename, const char * mode ) { F_FILE * rc; if( xSemaphoreTake( fs_lock_semaphore, F_MAX_LOCK_WAIT_TICKS ) == pdPASS ) { rc = fn_open( filename, mode ); xSemaphoreGive( fs_lock_semaphore ); } else { rc = NULL; } return rc; }
/* Tries to detect whether FILE is a given type of file, by opening the file and passing it to DETECT, and returns a detect_result. */ static enum detect_result try_detect (const char *file_name, bool (*detect) (FILE *)) { FILE *file; bool is_type; file = fn_open (file_name, "rb"); if (file == NULL) { msg (ME, _("An error occurred while opening `%s': %s."), file_name, strerror (errno)); return ANY_ERROR; } is_type = detect (file); fn_close (file_name, file); return is_type ? ANY_YES : ANY_NO; }
/**************************************************************************** * * fn_truncate * * Open a file and set end of file * * INPUT: filename - name of the file * filesize - required new size * RETURN: NULL on error, otherwise file pointer * ***************************************************************************/ F_FILE * fn_truncate ( const char * filename, long filesize ) { F_FILE * f = fn_open( filename, "r+" ); unsigned char rc; if ( f != NULL ) { rc = _f_fseek( (long)gl_file.filesize ); if ( rc == F_NO_ERROR ) { rc = _f_seteof( f, filesize ); } if ( rc ) { fn_close( f ); f = NULL; } } return f; } /* fn_truncate */