{
Eina_File_Map *map;
- if (file->refcount != 0) return;
-
- eina_hash_free(file->rmap);
- eina_hash_free(file->map);
-
EINA_LIST_FREE(file->dead_map, map)
{
munmap(map->map, map->length);
munmap(file->global_map, file->length);
if (file->fd != -1) close(file->fd);
-
- free(file);
}
static void
{
file->delete_me = EINA_TRUE;
eina_hash_del(_eina_file_cache, file->filename, file);
- eina_file_real_close(file);
+ eina_file_clean_close(file);
file = NULL;
}
n->shared = shared;
eina_lock_new(&n->lock);
eina_hash_direct_add(_eina_file_cache, n->filename, n);
+
+ EINA_MAGIC_SET(n, EINA_FILE_MAGIC);
}
else
{
return file;
}
+void
+eina_file_clean_close(Eina_File *file)
+{
+ // Generic destruction of the file
+ eina_hash_free(file->rmap); file->rmap = NULL;
+ eina_hash_free(file->map); file->map = NULL;
+
+ // Backend specific file resource close
+ eina_file_real_close(file);
+
+ // Final death
+ EINA_MAGIC_SET(file, 0);
+ free(file);
+}
+
EAPI void
eina_file_close(Eina_File *file)
{
eina_hash_del(_eina_file_cache, file->filename, file);
- // Backend specific file resource close
- eina_file_real_close(file);
-
+ eina_file_clean_close(file);
end:
eina_lock_release(&_eina_file_lock_cache);
}
#include "eina_lock.h"
#include "eina_list.h"
+#define EINA_FILE_MAGIC 0xFEEDBEEF
+
typedef struct _Eina_File_Map Eina_File_Map;
typedef struct _Eina_Lines_Iterator Eina_Lines_Iterator;
struct _Eina_File
{
+ EINA_MAGIC;
const char *filename;
Eina_Hash *map;
Eina_Bool eina_file_path_relative(const char *path);
Eina_Tmpstr *eina_file_current_directory_get(const char *path, size_t len);
char *eina_file_cleanup(Eina_Tmpstr *path);
+void eina_file_clean_close(Eina_File *file);
void eina_file_real_close(Eina_File *file);
void eina_file_flush(Eina_File *file, unsigned long int length);
void eina_file_common_map_free(Eina_File *file, void *map,
{
Eina_File_Map *map;
- eina_hash_free(file->rmap);
- eina_hash_free(file->map);
-
EINA_LIST_FREE(file->dead_map, map)
{
UnmapViewOfFile(map->map);
if (file->fm) CloseHandle(file->fm);
if (file->handle) CloseHandle(file->handle);
-
- free(file);
}
static void
{
file->delete_me = EINA_TRUE;
eina_hash_del(_eina_file_cache, file->filename, file);
- eina_file_real_close(file);
+ eina_file_clean_close(file);
file = NULL;
}
n->shared = shared;
eina_lock_new(&n->lock);
eina_hash_direct_add(_eina_file_cache, n->filename, n);
+
+ EINA_MAGIC_SET(n, EINA_FILE_MAGIC);
}
else
{