/* File handling utility code V1.03 10/2/08
   Copyright 2008 Jeffrey Lee
   This file is part of WOUM.
   WOUM is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   WOUM is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   along with WOUM.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _FUTIL_H
#define _FUTIL_H

#include <stdio.h>

typedef struct {
	int type; /* Type of file: 0=not found, 1=file, 2=directory, 3=image file */
	unsigned int load; /* Load address of file */
	unsigned int exec; /* Execution address of file */
	unsigned int length; /* Length of file */
	unsigned int attrib; /* Attributes of file */
	int filetype; /* File type decoded from load and exec addresses, or -1 for none */
	unsigned long long time; /* Timestamp, or 0 if none */
} futil_iblock;

extern int futil_readword(FILE *f);
/* Read a word from FILE *f
   Returns EOF on error (Although this may actually be an input which is equal to EOF)
*/

extern int futil_putword(FILE *f,int a);
/* Write a word to FILE *f
   Returns EOF on failure, else 0
*/

extern int futil_readstring(char *str,int len,FILE *f);
/* Read a null-terminated string from FILE *f into str
   Returns EOF on failure (e.g. EOF or string too long), else 0
*/

extern void futil_ginfo(char *name,futil_iblock *info);
/* Fill 'info' with information about the file 'name'
*/

extern int futil_lfile(char *name,void *ptr);
/* Load file 'name' into the block of memory pointed to by 'ptr'.
  Returns !0 on failure
*/

extern int futil_sfile(char *name,void *ptr,int len,int type);
/* Save the block of memory 'ptr' (of length 'len' bytes inclusive) to the file names 'name', with a file type of 'type'
   Returns !0 on failure
*/

#endif
