*/
#include "idx.h"
+#include <stdlib.h>
+#include <strings.h>
+
+FILE* emufs_idx_abrir(EMUFS* efs, const char* mode)
+{
+ FILE* f;
+ char* filename;
+
+ filename = (char*) malloc(sizeof(char) * (strlen(efs->nombre)
+ + strlen(EMUFS_IDX_EXT) + 1));
+ if (filename == NULL) {
+ /* TODO Manejo de errores */
+ return NULL;
+ }
+ strcpy(filename, efs->nombre);
+ strcat(filename, EMUFS_IDX_EXT);
+ f = fopen(filename, mode);
+ free(filename);
+ return f;
+}
int emufs_idx_buscar_mayor_id(EMUFS *emu)
{
strcat(name_f_idx, EMUFS_IDX_EXT);
if ( (f_idx = fopen(name_f_idx,"r")) == NULL) return -1; /*ERROR*/
+ reg.id_reg = -1;
+ reg.block = -1;
while ( !feof(f_idx) ){
if (fread(®,sizeof(EMUFS_IDX),1,f_idx) != 1) continue;
if ( reg.id_reg == ID ){
- fclose(f_idx);
- return reg.block;
+ break;
}
}
fclose(f_idx);
- return -1; /*no existe el registro*/
+ return reg.block;
}
/* agrega un registro al final del archivo */
strcpy(name_f_idx,emu->nombre);
strcat(name_f_idx, EMUFS_IDX_EXT);
- if ( (f_idx = fopen(name_f_idx,"ab+"))==NULL ) return -1;
+ if ( (f_idx = fopen(name_f_idx,"a+"))==NULL ) return -1;
reg.block = num_bloque;
reg.id_reg = ID_aux;
fclose(f_idx);
return 0;
}
+