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 #define EMUFS_DID_EXT ".did"
44 int emufs_did_get_last(EMUFS *emu)
50 strcpy(name_f_did, emu->nombre);
51 strcat(name_f_did, EMUFS_DID_EXT);
53 if ( (f_did = fopen(name_f_did,"r")) == NULL) return -1; /*ERROR*/
54 fseek(f_did, 0, SEEK_END);
56 if (ftell(f_did) > 0){
57 /* si el archivo no esta vacio es porque hay un nro disponible*/
58 fseek(f_did, -sizeof(int),SEEK_END);
59 /* leo el ultimo numero */
60 fread(&id,sizeof(int),1,f_did);
62 fseek(f_did, 0, SEEK_END);
63 /* mido el tamaño del archivo*/
64 offset = ftell(f_did);
67 truncate(name_f_did, offset - sizeof(int));
70 /* si el archivo esta vacio */
76 /*agrego un elemento al archivo */
77 int emufs_did_agregar(EMUFS *emu, int ID)
82 strcpy(name_f_did, emu->nombre);
83 strcat(name_f_did, EMUFS_DID_EXT);
85 if ( (f_did = fopen(name_f_did,"a+")) == NULL) return -1;
86 fwrite(&ID, sizeof(int), 1, f_did);