1 /* vim: set noexpandtab tabstop=4 shiftwidth=4:
2 *----------------------------------------------------------------------------
4 *----------------------------------------------------------------------------
5 * This file is part of emufs.
7 * emufs is free software; you can redistribute it and/or modify it under the
8 * terms of the GNU General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option) any later
12 * emufs is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along
18 * with emufs; if not, write to the Free Software Foundation, Inc., 59 Temple
19 * Place, Suite 330, Boston, MA 02111-1307 USA
20 *----------------------------------------------------------------------------
21 * Creado: jue abr 8 18:07:57 ART 2004
22 * Autores: Nicolás Dimov <sagardua@uolsinectis.com.ar>
23 *----------------------------------------------------------------------------
31 * Manejo de archivos de índices de registros borrados (reutilizables).
33 * Implementación del manejo de archivos de índices de registros borrados
42 int emufs_did_get_last(EMUFS *emu)
48 strcpy(name_f_did, emu->nombre);
49 strcat(name_f_did, EMUFS_DID_EXT);
51 if ( (f_did = fopen(name_f_did,"r")) == NULL) return -1; /*ERROR*/
52 fseek(f_did, 0, SEEK_END);
54 if (ftell(f_did) > 0){
55 /* si el archivo no esta vacio es porque hay un nro disponible*/
56 fseek(f_did, -sizeof(int),SEEK_END);
57 /* leo el ultimo numero */
58 fread(&id,sizeof(int),1,f_did);
60 fseek(f_did, 0, SEEK_END);
61 /* mido el tamaño del archivo*/
62 offset = ftell(f_did);
65 truncate(name_f_did, offset - sizeof(int));
68 /* si el archivo esta vacio */
74 /*agrego un elemento al archivo */
75 int emufs_did_agregar(EMUFS *emu, int ID)
80 strcpy(name_f_did, emu->nombre);
81 strcat(name_f_did, EMUFS_DID_EXT);
83 if ( (f_did = fopen(name_f_did,"a+")) == NULL) return -1;
84 fwrite(&ID, sizeof(int), 1, f_did);