X-Git-Url: https://git.llucax.com/z.facultad/75.06/emufs.git/blobdiff_plain/67c6b07f6bd9d779f3314b5ce3de40ea4aa9dd51..f5f9e412009380bc5aea316c9ff48ea379f17f0c:/emufs/idx.c diff --git a/emufs/idx.c b/emufs/idx.c index f465d20..7e48545 100644 --- a/emufs/idx.c +++ b/emufs/idx.c @@ -233,8 +233,10 @@ EMUFS_REG_ID emufs_idx_get_count(EMUFS *emu) strcpy(name_f_idx,emu->nombre); strcat(name_f_idx, EMUFS_IDX_EXT); - fp = fopen(name_f_idx, "rb"); - if (fp == NULL) return 0; + if ( (fp = fopen(name_f_idx, "rb"))==NULL){ + PERR("No se pudo abrir el archvo"); + return -1; + } fseek(fp, 0l, SEEK_END); tam = ftell(fp); @@ -252,8 +254,10 @@ EMUFS_REG_ID emufs_idx_get_id_at(EMUFS *emu, long pos) strcpy(name_f_idx,emu->nombre); strcat(name_f_idx, EMUFS_IDX_EXT); - fp = fopen(name_f_idx, "rb"); - if (fp == NULL) return EMUFS_NOT_FOUND; + if ( (fp = fopen(name_f_idx, "rb")) == NULL){ + PERR("No se pudo abrir el archivo"); + return -1; + } fseek(fp, pos*sizeof(EMUFS_IDX), SEEK_SET); fread(&id, sizeof(EMUFS_IDX), 1, fp); @@ -261,3 +265,28 @@ EMUFS_REG_ID emufs_idx_get_id_at(EMUFS *emu, long pos) return id.id_reg; } + +int emufs_idx_existe_id(EMUFS *emu, int ID) +{ + FILE *fp; + char name_f_idx[255]; + EMUFS_IDX id; + + strcpy(name_f_idx,emu->nombre); + strcat(name_f_idx, EMUFS_IDX_EXT); + + if ( (fp = fopen(name_f_idx, "rb")) == NULL){ + PERR("No se pudo abrir el archivo"); + return -1; + } + + while ( !feof(fp) ){ + fread(&id, sizeof(EMUFS_IDX), 1, fp); + if ( id.id_reg == ID ){ + fclose(fp); + return 0; + } + } + fclose(fp); + return -1; +}