• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*! \file exif-mem.h
2  *  \brief Define the ExifMem data type and the associated functions.
3  *  ExifMem defines the memory management functions used within libexif.
4  */
5 /* exif-mem.h
6  *
7  * Copyright (c) 2003 Lutz Mueller <lutz@users.sourceforge.net>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA  02110-1301  USA.
23  *
24  * SPDX-License-Identifier: LGPL-2.0-or-later
25  */
26 
27 #ifndef LIBEXIF_EXIF_MEM_H
28 #define LIBEXIF_EXIF_MEM_H
29 
30 #include <libexif/exif-utils.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif /* __cplusplus */
35 
36 /*! Should work like calloc()
37  *
38  *  \param[in] s the size of the block to allocate.
39  *  \return the allocated memory and initialized.
40  */
41 typedef void * (* ExifMemAllocFunc)   (ExifLong s);
42 
43 /*! Should work like realloc()
44  *
45  * \param[in] p the pointer to reallocate
46  * \param[in] s the size of the reallocated block
47  * \return allocated memory
48  */
49 typedef void * (* ExifMemReallocFunc) (void *p, ExifLong s);
50 
51 /*! Free method for ExifMem
52  *
53  * \param[in] p the pointer to free
54  * \return the freed pointer
55  */
56 typedef void   (* ExifMemFreeFunc)    (void *p);
57 
58 /*! ExifMem define a memory allocator */
59 typedef struct _ExifMem ExifMem;
60 
61 /*! Create a new ExifMem
62  *
63  * \param[in] a the allocator function
64  * \param[in] r the reallocator function
65  * \param[in] f the free function
66  * \return allocated #ExifMem, or NULL on error
67  */
68 ExifMem *exif_mem_new   (ExifMemAllocFunc a, ExifMemReallocFunc r,
69 			 ExifMemFreeFunc f);
70 /*! Refcount an ExifMem
71  */
72 void     exif_mem_ref   (ExifMem *);
73 
74 /*! Unrefcount an ExifMem.
75  * If the refcount reaches 0, the ExifMem is freed
76  */
77 void     exif_mem_unref (ExifMem *);
78 
79 void *exif_mem_alloc   (ExifMem *m, ExifLong s);
80 void *exif_mem_realloc (ExifMem *m, void *p, ExifLong s);
81 void  exif_mem_free    (ExifMem *m, void *p);
82 
83 /*! Create a new ExifMem with default values for your convenience
84  *
85  * \return return a new default ExifMem
86  */
87 ExifMem *exif_mem_new_default (void);
88 
89 #ifdef __cplusplus
90 }
91 #endif /* __cplusplus */
92 
93 #endif /* !defined(LIBEXIF_EXIF_MEM_H) */
94