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,hid_t fapl_id)45 H5F_fake_alloc(uint8_t sizeof_size, hid_t fapl_id)
46 {
47 H5F_t *f = NULL; /* Pointer to fake file struct */
48 H5P_genplist_t *plist; /* Property list */
49 H5F_t *ret_value = NULL; /* Return value */
50
51 FUNC_ENTER_NOAPI(NULL)
52
53 /* Allocate faked file struct */
54 if(NULL == (f = H5FL_CALLOC(H5F_t)))
55 HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate top file structure")
56 if(NULL == (f->shared = H5FL_CALLOC(H5F_file_t)))
57 HGOTO_ERROR(H5E_FILE, H5E_NOSPACE, NULL, "can't allocate shared file structure")
58
59 /* Only set fields necessary for clients */
60 if(sizeof_size == 0)
61 f->shared->sizeof_size = H5F_OBJ_SIZE_SIZE;
62 else
63 f->shared->sizeof_size = sizeof_size;
64
65 /* Set low/high bounds according to the setting in fapl_id */
66 /* See H5F_new() in H5Fint.c */
67 if(NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
68 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not file access property list")
69
70 if(H5P_get(plist, H5F_ACS_LIBVER_LOW_BOUND_NAME, &(f->shared->low_bound)) < 0)
71 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get 'low' bound for library format versions")
72 if(H5P_get(plist, H5F_ACS_LIBVER_HIGH_BOUND_NAME, &(f->shared->high_bound)) < 0)
73 HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, NULL, "can't get 'high' bound for library format versions")
74
75 /* Set return value */
76 ret_value = f;
77
78 done:
79 if(!ret_value)
80 H5F_fake_free(f);
81
82 FUNC_LEAVE_NOAPI(ret_value)
83 } /* end H5F_fake_alloc() */
84
85
86 /*-------------------------------------------------------------------------
87 * Function: H5F_fake_free
88 *
89 * Purpose: Free a "fake" file structure.
90 *
91 * Return: Success: non-negative
92 * Failure: negative
93 *
94 * Programmer: Quincey Koziol
95 * koziol@hdfgroup.org
96 * Oct 2, 2006
97 *
98 *-------------------------------------------------------------------------
99 */
100 herr_t
H5F_fake_free(H5F_t * f)101 H5F_fake_free(H5F_t *f)
102 {
103 FUNC_ENTER_NOAPI_NOINIT_NOERR
104
105 /* Free faked file struct */
106 if(f) {
107 /* Destroy shared file struct */
108 if(f->shared)
109 f->shared = H5FL_FREE(H5F_file_t, f->shared);
110 f = H5FL_FREE(H5F_t, f);
111 } /* end if */
112
113 FUNC_LEAVE_NOAPI(SUCCEED)
114 } /* end H5F_fake_free() */
115
116