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