--- previous/src/file.c 2018/04/24 19:25:10 1.1 +++ previous/src/file.c 2018/04/24 19:31:06 1.1.1.4 @@ -134,19 +134,6 @@ const char *File_RemoveFileNameDrive(con /*-----------------------------------------------------------------------*/ /** - * Check if given filename is an existing directory - * - * Return TRUE if directory, else give FALSE - */ -bool File_DirExists(const char *path) -{ - struct stat filestat; - return (stat(path, &filestat) == 0 && S_ISDIR(filestat.st_mode)); -} - - -/*-----------------------------------------------------------------------*/ -/** * Check if filename end with a '/' * * Return TRUE if filename ends with '/' @@ -170,7 +157,7 @@ bool File_DoesFileNameEndWithSlash(char * or NULL for error. If pFileSize is non-NULL, read file size * is set to that. */ -Uint8 *File_Read(const char *pszFileName, long *pFileSize, const char * const ppszExts[]) +Uint8 *File_Load(const char *pszFileName, long *pFileSize, const char * const ppszExts[]) { char *filepath = NULL; Uint8 *pFile = NULL; @@ -339,14 +326,10 @@ bool File_Exists(const char *filename) /** * Return TRUE if directory exists. */ -bool File_DirectoryExists(const char *psDirName) +bool File_DirExists(const char *path) { struct stat buf; - if (stat(psDirName, &buf) == 0 && (buf.st_mode & S_IFDIR)) - { - return true; - } - return false; + return (stat(path, &buf) == 0 && S_ISDIR(buf.st_mode)); } @@ -570,8 +553,10 @@ FILE *File_Open(const char *path, const /* Open a normal log file */ fp = fopen(path, mode); if (!fp) - fprintf(stderr, "Can't open file '%s':\n %s\n", path, strerror(errno)); - /* printf("'%s' opened in mode '%s'\n", path, mode, fp); */ + fprintf(stderr, "Can't open file '%s' (wr=%i, rd=%i):\n %s\n", + path, wr, rd, strerror(errno)); + + /* printf("'%s' opened in mode '%s'\n", path, mode, fp); */ return fp; } @@ -593,6 +578,46 @@ FILE *File_Close(FILE *fp) /*-----------------------------------------------------------------------*/ /** + * Read data from given FILE pointer to buffer and return status + */ +bool File_Read(Uint8 *data, Uint32 size, Uint64 offset, FILE *fp) +{ + if (fseek(fp, offset, SEEK_SET)) + { + fprintf(stderr, "File seek failed:\n %s\n", strerror(errno)); + return false; + } + if (fread(data, size, 1, fp) != 1) + { + fprintf(stderr, "Error occured while reading file.\n"); + return false; + } + return true; +} + + +/*-----------------------------------------------------------------------*/ +/** + * Write data to given FILE pointer and return status + */ +bool File_Write(Uint8 *data, Uint32 size, Uint64 offset, FILE *fp) +{ + if (fseek(fp, offset, SEEK_SET)) + { + fprintf(stderr, "File seek failed:\n %s\n", strerror(errno)); + return false; + } + if (fwrite(data, size, 1, fp) != 1) + { + fprintf(stderr, "Error occured while writing file.\n"); + return false; + } + return true; +} + + +/*-----------------------------------------------------------------------*/ +/** * Check if input is available at the specified file descriptor. */ bool File_InputAvailable(FILE *fp) @@ -652,11 +677,6 @@ void File_MakeAbsoluteName(char *pFileNa char *pTempName; int inpos, outpos; -#if defined (__AMIGAOS4__) - /* This function does not work on Amiga OS */ - return; -#endif - inpos = 0; pTempName = malloc(FILENAME_MAX); if (!pTempName)