X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/1b02a88830b3f4d2bc0e1518cd4c80ac276f7089..92aca5d432abb85476f6c100fb55190cd5947a00:/tipo3/emufs.c diff --git a/tipo3/emufs.c b/tipo3/emufs.c index 49cb4b4..ae302fd 100644 --- a/tipo3/emufs.c +++ b/tipo3/emufs.c @@ -7,10 +7,13 @@ #define EXT_TIPO3_DISP ".fsc" #define EXT_TIPO3_IDS ".ids" +char *str_dup(const char *s); + char *str_dup(const char *s) { + char *tmp; if (s == NULL) return NULL; - char *tmp = (char *)malloc(sizeof(char)*(strlen(s)+1)); + tmp = (char *)malloc(sizeof(char)*(strlen(s)+1)); strcpy(tmp, s); return tmp; } @@ -84,6 +87,8 @@ EMUFS *emufs_abrir(const char *filename) strcpy(name, filename); strcat(name, EXT_TIPO3_DATA); + + /* Trato de determinar el tipo de archivo */ fp = fopen(name, "r"); if (fp == NULL) return NULL; fread(&tipo, sizeof(char), 1, fp); @@ -93,7 +98,10 @@ EMUFS *emufs_abrir(const char *filename) } tmp = (EMUFS *)malloc(sizeof(EMUFS)); - if (tmp == NULL) return NULL; + if (tmp == NULL) { + fclose(fp); + return NULL; + } switch (tipo) { case T1: @@ -145,13 +153,13 @@ int ver_archivo_FS(EMUFS *emu) /* Imprimo la lista de bloques/registros */ strcpy(name_f_block_free,emu->nombre); - strcat(name_f_block_free,".id3"); + strcat(name_f_block_free,".idx"); { BLOCK_REG_T r; f_block_free = fopen(name_f_block_free, "r"); fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free); while (!feof(f_block_free)) { - printf("ID %d en bloque %d\n", r.id_reg, r.block); + printf("ID %ld en bloque %d\n", r.id_reg, r.block); fread(&r, sizeof(BLOCK_REG_T), 1, f_block_free); } fclose(f_block_free);