/src/hdf5/src/H5VLnative_token.c
Line | Count | Source (jump to first uncovered line) |
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 COPYING 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 | | /* |
14 | | * Purpose: Object token callbacks for the native VOL connector |
15 | | */ |
16 | | |
17 | | /****************/ |
18 | | /* Module Setup */ |
19 | | /****************/ |
20 | | |
21 | | /***********/ |
22 | | /* Headers */ |
23 | | /***********/ |
24 | | #include "H5private.h" /* Generic Functions */ |
25 | | #include "H5Eprivate.h" /* Error handling */ |
26 | | #include "H5Iprivate.h" /* IDs */ |
27 | | #include "H5MMprivate.h" /* Memory handling */ |
28 | | #include "H5VLnative_private.h" /* Native VOL connector */ |
29 | | |
30 | | /****************/ |
31 | | /* Local Macros */ |
32 | | /****************/ |
33 | | |
34 | | /******************/ |
35 | | /* Local Typedefs */ |
36 | | /******************/ |
37 | | |
38 | | /********************/ |
39 | | /* Local Prototypes */ |
40 | | /********************/ |
41 | | |
42 | | /*********************/ |
43 | | /* Package Variables */ |
44 | | /*********************/ |
45 | | |
46 | | /*****************************/ |
47 | | /* Library Private Variables */ |
48 | | /*****************************/ |
49 | | |
50 | | /*******************/ |
51 | | /* Local Variables */ |
52 | | /*******************/ |
53 | | |
54 | | /*--------------------------------------------------------------------------- |
55 | | * Function: H5VL__native_token_cmp |
56 | | * |
57 | | * Purpose: Compare two of the connector's object tokens, setting |
58 | | * *cmp_value, following the same rules as strcmp(). |
59 | | * |
60 | | * Return: Success: 0 |
61 | | * Failure: (can't fail) |
62 | | * |
63 | | *--------------------------------------------------------------------------- |
64 | | */ |
65 | | herr_t |
66 | | H5VL__native_token_cmp(void H5_ATTR_UNUSED *obj, const H5O_token_t *token1, const H5O_token_t *token2, |
67 | | int *cmp_value) |
68 | 0 | { |
69 | 0 | herr_t ret_value = SUCCEED; |
70 | |
|
71 | 0 | FUNC_ENTER_PACKAGE_NOERR |
72 | | |
73 | | /* Check parameters */ |
74 | 0 | assert(token1); |
75 | 0 | assert(token2); |
76 | |
|
77 | 0 | *cmp_value = memcmp(token1, token2, sizeof(H5O_token_t)); |
78 | |
|
79 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
80 | 0 | } /* end H5VL__native_token_cmp() */ |
81 | | |
82 | | /*--------------------------------------------------------------------------- |
83 | | * Function: H5VL__native_token_to_str |
84 | | * |
85 | | * Purpose: Serialize an object token into a string |
86 | | * |
87 | | * Return: Success: 0 |
88 | | * Failure: -1 |
89 | | * |
90 | | *--------------------------------------------------------------------------- |
91 | | */ |
92 | | herr_t |
93 | | H5VL__native_token_to_str(void *obj, H5I_type_t obj_type, const H5O_token_t *token, char **token_str) |
94 | 0 | { |
95 | 0 | haddr_t addr; |
96 | 0 | size_t addr_ndigits; |
97 | 0 | herr_t ret_value = SUCCEED; |
98 | |
|
99 | 0 | FUNC_ENTER_PACKAGE |
100 | | |
101 | | /* Check parameters */ |
102 | 0 | assert(obj); |
103 | 0 | assert(token); |
104 | |
|
105 | 0 | if (H5VL_native_token_to_addr(obj, obj_type, *token, &addr) < 0) |
106 | 0 | HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, FAIL, "can't convert object token to address"); |
107 | | |
108 | 0 | if (addr == 0) |
109 | 0 | addr_ndigits = 1; |
110 | 0 | else |
111 | 0 | addr_ndigits = (size_t)(floor(log10((double)addr)) + 1); |
112 | |
|
113 | 0 | if (NULL == (*token_str = H5MM_malloc(addr_ndigits + 1))) |
114 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, FAIL, "can't allocate buffer for token string"); |
115 | | |
116 | 0 | snprintf(*token_str, addr_ndigits + 1, "%" PRIuHADDR, addr); |
117 | |
|
118 | 0 | done: |
119 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
120 | 0 | } /* end H5VL__native_token_to_str() */ |
121 | | |
122 | | /*--------------------------------------------------------------------------- |
123 | | * Function: H5VL__native_str_to_token |
124 | | * |
125 | | * Purpose: Deserialize a string into an object token |
126 | | * |
127 | | * Return: Success: 0 |
128 | | * Failure: -1 |
129 | | * |
130 | | *--------------------------------------------------------------------------- |
131 | | */ |
132 | | herr_t |
133 | | H5VL__native_str_to_token(void *obj, H5I_type_t obj_type, const char *token_str, H5O_token_t *token) |
134 | 0 | { |
135 | 0 | haddr_t addr; |
136 | 0 | herr_t ret_value = SUCCEED; |
137 | |
|
138 | 0 | FUNC_ENTER_PACKAGE |
139 | | |
140 | | /* Check parameters */ |
141 | 0 | assert(token_str); |
142 | |
|
143 | 0 | sscanf(token_str, "%" PRIuHADDR, &addr); |
144 | |
|
145 | 0 | if (H5VL_native_addr_to_token(obj, obj_type, addr, token) < 0) |
146 | 0 | HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, FAIL, "can't convert address to object token"); |
147 | | |
148 | 0 | done: |
149 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
150 | 0 | } /* end H5VL__native_str_to_token() */ |