1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 #include "H5Fmodule.h" /* This source code file is part of the H5F module */
15
16
17 /* Packages needed by this file... */
18 #include "H5private.h" /* Generic Functions */
19 #include "H5Eprivate.h" /* Error handling */
20 #include "H5Fpkg.h" /* File access */
21 #include "H5Iprivate.h" /* IDs */
22 #include "H5Pprivate.h" /* Property lists */
23
24 /* PRIVATE PROTOTYPES */
25
26
27 /*-------------------------------------------------------------------------
28 * Function: H5F_fake_alloc
29 *
30 * Purpose: Allocate a "fake" file structure, for various routines to
31 * use for encoding/decoding data structures using internal API
32 * routines that need a file structure, but don't ultimately
33 * depend on having a "real" file.
34 *
35 * Return: Success: Pointer to 'faked up' file structure
36 * Failure: NULL
37 *
38 * Programmer: Quincey Koziol
39 * koziol@hdfgroup.org
40 * Oct 2, 2006
41 *
42 *-------------------------------------------------------------------------
43 */
44 H5F_t *
H5F_fake_alloc(uint8_t sizeof_size)45 H5F_fake_alloc(uint8_t sizeof_size)
46 {
47 H5F_t *f = NULL; /* Pointer to fake file struct */
48 H5F_t *ret_value = NULL; /* Return value */
49
50 FUNC_ENTER_NOAPI(NULL)
51
52 /* Allocate faked file struct */
53 if(NULL == (f = H5FL_CALLOC(H5F_t)))
54 HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate top file structure")
55 if(NULL == (f->shared = H5FL_CALLOC(H5F_file_t)))
56 HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate shared file structure")
57
58 /* Only set fields necessary for clients */
59 if(sizeof_size == 0)
60 f->shared->sizeof_size = H5F_OBJ_SIZE_SIZE;
61 else
62 f->shared->sizeof_size = sizeof_size;
63
64 ret_value = f;
65
66 done:
67 if(!ret_value)
68 H5F_fake_free(f);
69
70 FUNC_LEAVE_NOAPI(ret_value)
71 } /* end H5F_fake_alloc() */
72
73
74 /*-------------------------------------------------------------------------
75 * Function: H5F_fake_free
76 *
77 * Purpose: Free a "fake" file structure.
78 *
79 * Return: Success: non-negative
80 * Failure: negative
81 *
82 * Programmer: Quincey Koziol
83 * koziol@hdfgroup.org
84 * Oct 2, 2006
85 *
86 *-------------------------------------------------------------------------
87 */
88 herr_t
H5F_fake_free(H5F_t * f)89 H5F_fake_free(H5F_t *f)
90 {
91 FUNC_ENTER_NOAPI_NOINIT_NOERR
92
93 /* Free faked file struct */
94 if(f) {
95 /* Destroy shared file struct */
96 if(f->shared)
97 f->shared = H5FL_FREE(H5F_file_t, f->shared);
98 f = H5FL_FREE(H5F_t, f);
99 } /* end if */
100
101 FUNC_LEAVE_NOAPI(SUCCEED)
102 } /* end H5F_fake_free() */
103
104