1 /* Swap file handling */
3 /* This is a libhed PRIVATE file.
4 * Do not include outside of libhed. Do not install on the system.
8 * hed - Hexadecimal editor
9 * Copyright (C) 2011 Petr Tesarik <petr@tesarici.cz>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef LIBHED__SWAP_H
26 #define LIBHED__SWAP_H
31 /* Prevent polluting linker namespace with internal symbols */
33 #define swp_cpin internal_name(swp_cpin)
34 #define swp_done internal_name(swp_done)
35 #define swp_free internal_name(swp_free)
36 #define swp_init_read internal_name(swp_init_read)
37 #define swp_init_write internal_name(swp_init_write)
38 #define swp_malloc internal_name(swp_malloc)
39 #define swp_private internal_name(swp_private)
40 #define swp_shrink internal_name(swp_shrink)
41 #define swp_write internal_name(swp_write)
42 #define swp_zalloc internal_name(swp_zalloc)
44 #ifdef HED_CONFIG_SWAP
46 #define SWAP_SIGNATURE "HEDSWAP\n"
47 #define SIG_LEN (sizeof(SWAP_SIGNATURE) - 1)
48 #define SWAP_VERSION 2
51 char signature
[SIG_LEN
]; /* = "HEDSWAP\n" */
52 short version
; /* Swap file version */
54 void *addr
; /* Address of the file header itself */
60 struct swp_header
*hdr
;
62 /* Swap implementation private fields */
66 #ifdef HED_CONFIG_SWAP_MMAP
71 struct list_head freeblocks
;
72 struct list_head usedblocks
;
77 struct swp_file
*swp_init_write(const char *name
);
78 struct swp_file
*swp_init_read(const char *name
);
79 int swp_done(struct swp_file
*swp
);
80 void *swp_malloc(struct swp_file
*swp
, size_t size
);
81 void *swp_zalloc(struct swp_file
*swp
, size_t size
);
82 void *swp_shrink(struct swp_file
*swp
, void *ptr
, size_t newsize
);
83 void swp_free(struct swp_file
*swp
, void *ptr
);
85 int swp_write(struct swp_file
*swp
);
86 size_t swp_cpin(struct swp_file
*swp
, void *buf
, void *ptr
, size_t len
);
89 swp_private(struct swp_file
*swp
)
94 #else /* HED_CONFIG_SWAP */
101 swp_malloc(struct swp_file
*swp
, size_t size
)
107 swp_zalloc(struct swp_file
*swp
, size_t size
)
109 return calloc(1, size
);
113 swp_shrink(struct swp_file
*swp
, void *ptr
, size_t newsize
)
115 return realloc(ptr
, newsize
);
119 swp_free(struct swp_file
*swp
, void *ptr
)
124 #endif /* HED_CONFIG_SWAP */
126 #endif /* LIBHED__SWAP_H */