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 /****************/
15 /* Module Setup */
16 /****************/
17
18 #include "H5Amodule.h" /* This source code file is part of the H5A module */
19 #define H5O_FRIEND /*suppress error about including H5Opkg */
20
21
22 /***********/
23 /* Headers */
24 /***********/
25 #include "H5private.h" /* Generic Functions */
26 #include "H5Apkg.h" /* Attributes */
27 #include "H5CXprivate.h" /* API Contexts */
28 #include "H5Eprivate.h" /* Error handling */
29 #include "H5FLprivate.h" /* Free Lists */
30 #include "H5Iprivate.h" /* IDs */
31 #include "H5MMprivate.h" /* Memory management */
32 #include "H5Opkg.h" /* Object headers */
33 #include "H5Sprivate.h" /* Dataspace functions */
34 #include "H5SMprivate.h" /* Shared Object Header Messages */
35
36
37 /****************/
38 /* Local Macros */
39 /****************/
40
41
42 /******************/
43 /* Local Typedefs */
44 /******************/
45
46 /* Object header iterator callbacks */
47 /* Data structure for callback for locating the index by name */
48 typedef struct H5A_iter_cb1 {
49 const char *name;
50 int idx;
51 } H5A_iter_cb1;
52
53
54 /********************/
55 /* Package Typedefs */
56 /********************/
57
58
59 /********************/
60 /* Local Prototypes */
61 /********************/
62
63
64 /*********************/
65 /* Package Variables */
66 /*********************/
67
68 /* Package initialization variable */
69 hbool_t H5_PKG_INIT_VAR = FALSE;
70
71
72 /*****************************/
73 /* Library Private Variables */
74 /*****************************/
75
76
77 /*******************/
78 /* Local Variables */
79 /*******************/
80
81 /* Declare the free lists of H5A_t */
82 H5FL_DEFINE(H5A_t);
83
84 /* Declare the free lists for H5A_shared_t's */
85 H5FL_DEFINE(H5A_shared_t);
86
87 /* Declare a free list to manage blocks of type conversion data */
88 H5FL_BLK_DEFINE(attr_buf);
89
90 /* Attribute ID class */
91 static const H5I_class_t H5I_ATTR_CLS[1] = {{
92 H5I_ATTR, /* ID class value */
93 0, /* Class flags */
94 0, /* # of reserved IDs for class */
95 (H5I_free_t)H5A__close_cb /* Callback routine for closing objects of this class */
96 }};
97
98 /* Flag indicating "top" of interface has been initialized */
99 static hbool_t H5A_top_package_initialize_s = FALSE;
100
101
102
103 /*--------------------------------------------------------------------------
104 NAME
105 H5A__init_package -- Initialize interface-specific information
106 USAGE
107 herr_t H5A__init_package()
108
109 RETURNS
110 Non-negative on success/Negative on failure
111 DESCRIPTION
112 Initializes any interface-specific data or routines.
113
114 --------------------------------------------------------------------------*/
115 herr_t
H5A__init_package(void)116 H5A__init_package(void)
117 {
118 herr_t ret_value = SUCCEED; /* Return value */
119
120 FUNC_ENTER_PACKAGE
121
122 /*
123 * Create attribute ID type.
124 */
125 if(H5I_register_type(H5I_ATTR_CLS) < 0)
126 HGOTO_ERROR(H5E_INTERNAL, H5E_CANTINIT, FAIL, "unable to initialize interface")
127
128 /* Mark "top" of interface as initialized, too */
129 H5A_top_package_initialize_s = TRUE;
130
131 done:
132 FUNC_LEAVE_NOAPI(ret_value)
133 } /* end H5A__init_package() */
134
135
136 /*--------------------------------------------------------------------------
137 NAME
138 H5A_top_term_package
139 PURPOSE
140 Terminate various H5A objects
141 USAGE
142 void H5A_top_term_package()
143 RETURNS
144 DESCRIPTION
145 Release IDs for the atom group, deferring full interface shutdown
146 until later (in H5A_term_package).
147 GLOBAL VARIABLES
148 COMMENTS, BUGS, ASSUMPTIONS
149 Can't report errors...
150 EXAMPLES
151 REVISION LOG
152 --------------------------------------------------------------------------*/
153 int
H5A_top_term_package(void)154 H5A_top_term_package(void)
155 {
156 int n = 0;
157
158 FUNC_ENTER_NOAPI_NOINIT_NOERR
159
160 if(H5A_top_package_initialize_s) {
161 if(H5I_nmembers(H5I_ATTR) > 0) {
162 (void)H5I_clear_type(H5I_ATTR, FALSE, FALSE);
163 n++; /*H5I*/
164 } /* end if */
165
166 /* Mark closed */
167 if(0 == n)
168 H5A_top_package_initialize_s = FALSE;
169 } /* end if */
170
171 FUNC_LEAVE_NOAPI(n)
172 } /* H5A_top_term_package() */
173
174
175 /*--------------------------------------------------------------------------
176 NAME
177 H5A_term_package
178 PURPOSE
179 Terminate various H5A objects
180 USAGE
181 void H5A_term_package()
182 RETURNS
183 DESCRIPTION
184 Release any other resources allocated.
185 GLOBAL VARIABLES
186 COMMENTS, BUGS, ASSUMPTIONS
187 Can't report errors...
188
189 Finishes shutting down the interface, after H5A_top_term_package()
190 is called
191 EXAMPLES
192 REVISION LOG
193 --------------------------------------------------------------------------*/
194 int
H5A_term_package(void)195 H5A_term_package(void)
196 {
197 int n = 0;
198
199 FUNC_ENTER_NOAPI_NOINIT_NOERR
200
201 if(H5_PKG_INIT_VAR) {
202 /* Sanity checks */
203 HDassert(0 == H5I_nmembers(H5I_ATTR));
204 HDassert(FALSE == H5A_top_package_initialize_s);
205
206 /* Destroy the attribute object id group */
207 n += (H5I_dec_type_ref(H5I_ATTR) > 0);
208
209 /* Mark closed */
210 if(0 == n)
211 H5_PKG_INIT_VAR = FALSE;
212 } /* end if */
213
214 FUNC_LEAVE_NOAPI(n)
215 } /* H5A_term_package() */
216
217
218 /*--------------------------------------------------------------------------
219 NAME
220 H5Acreate2
221 PURPOSE
222 Creates an attribute on an object
223 USAGE
224 hid_t H5Acreate2(loc_id, attr_name, type_id, space_id, acpl_id,
225 aapl_id)
226 hid_t loc_id; IN: Object (dataset or group) to be attached to
227 const char *attr_name; IN: Name of attribute to locate and open
228 hid_t type_id; IN: ID of datatype for attribute
229 hid_t space_id; IN: ID of dataspace for attribute
230 hid_t acpl_id; IN: ID of creation property list (currently not used)
231 hid_t aapl_id; IN: Attribute access property list
232 RETURNS
233 Non-negative on success/Negative on failure
234
235 DESCRIPTION
236 This function creates an attribute which is attached to the object
237 specified with 'loc_id'. The name specified with 'attr_name' for
238 each attribute for an object must be unique for that object. The 'type_id'
239 and 'space_id' are created with the H5T and H5S interfaces respectively.
240 The 'aapl_id' property list is currently unused, but will be used in the
241 future for optional attribute access properties. The attribute ID returned
242 from this function must be released with H5Aclose or resource leaks will
243 develop.
244
245 --------------------------------------------------------------------------*/
246 hid_t
H5Acreate2(hid_t loc_id,const char * attr_name,hid_t type_id,hid_t space_id,hid_t acpl_id,hid_t aapl_id)247 H5Acreate2(hid_t loc_id, const char *attr_name, hid_t type_id, hid_t space_id,
248 hid_t acpl_id, hid_t aapl_id)
249 {
250 H5A_t *attr = NULL; /* Attribute created */
251 H5G_loc_t loc; /* Object location */
252 H5T_t *type; /* Datatype to use for attribute */
253 H5S_t *space; /* Dataspace to use for attribute */
254 hid_t ret_value; /* Return value */
255
256 FUNC_ENTER_API(FAIL)
257 H5TRACE6("i", "i*siiii", loc_id, attr_name, type_id, space_id, acpl_id, aapl_id);
258
259 /* check arguments */
260 if(H5I_ATTR == H5I_get_type(loc_id))
261 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
262 if(H5G_loc(loc_id, &loc) < 0)
263 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
264 if(0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR))
265 HGOTO_ERROR(H5E_ARGS, H5E_WRITEERROR, FAIL, "no write intent on file")
266 if(!attr_name || !*attr_name)
267 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
268 if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
269 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a type")
270 if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE)))
271 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
272
273 /* Verify access property list and set up collective metadata if appropriate */
274 if(H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, TRUE) < 0)
275 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info")
276
277 /* Go do the real work for attaching the attribute to the object */
278 if(NULL == (attr = H5A__create(&loc, attr_name, type, space, acpl_id)))
279 HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute")
280
281 /* Register the new attribute and get an ID for it */
282 if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0)
283 HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID")
284
285 done:
286 /* Cleanup on failure */
287 if(ret_value < 0 && attr && H5A__close(attr) < 0)
288 HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
289
290 FUNC_LEAVE_API(ret_value)
291 } /* H5Acreate2() */
292
293
294 /*--------------------------------------------------------------------------
295 NAME
296 H5Acreate_by_name
297 PURPOSE
298 Creates an attribute on an object
299 USAGE
300 hid_t H5Acreate_by_name(loc_id, obj_name, attr_name, type_id, space_id, acpl_id,
301 aapl_id, lapl_id)
302 hid_t loc_id; IN: Object (dataset or group) to be attached to
303 const char *obj_name; IN: Name of object relative to location
304 const char *attr_name; IN: Name of attribute to locate and open
305 hid_t type_id; IN: ID of datatype for attribute
306 hid_t space_id; IN: ID of dataspace for attribute
307 hid_t acpl_id; IN: ID of creation property list (currently not used)
308 hid_t aapl_id; IN: Attribute access property list
309 hid_t lapl_id; IN: Link access property list
310 RETURNS
311 Non-negative on success/Negative on failure
312
313 DESCRIPTION
314 This function creates an attribute which is attached to the object
315 specified with 'loc_id/obj_name'. The name specified with 'attr_name' for
316 each attribute for an object must be unique for that object. The 'type_id'
317 and 'space_id' are created with the H5T and H5S interfaces respectively.
318 The 'aapl_id' property list is currently unused, but will be used in the
319 future for optional attribute access properties. The attribute ID returned
320 from this function must be released with H5Aclose or resource leaks will
321 develop.
322
323 --------------------------------------------------------------------------*/
324 hid_t
H5Acreate_by_name(hid_t loc_id,const char * obj_name,const char * attr_name,hid_t type_id,hid_t space_id,hid_t acpl_id,hid_t aapl_id,hid_t lapl_id)325 H5Acreate_by_name(hid_t loc_id, const char *obj_name, const char *attr_name,
326 hid_t type_id, hid_t space_id, hid_t acpl_id, hid_t aapl_id,
327 hid_t lapl_id)
328 {
329 H5A_t *attr = NULL; /* Attribute created */
330 H5G_loc_t loc; /* Object location */
331 H5T_t *type; /* Datatype to use for attribute */
332 H5S_t *space; /* Dataspace to use for attribute */
333 hid_t ret_value; /* Return value */
334
335 FUNC_ENTER_API(FAIL)
336 H5TRACE8("i", "i*s*siiiii", loc_id, obj_name, attr_name, type_id, space_id,
337 acpl_id, aapl_id, lapl_id);
338
339 /* check arguments */
340 if(H5I_ATTR == H5I_get_type(loc_id))
341 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
342 if(H5G_loc(loc_id, &loc) < 0)
343 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
344 if(0 == (H5F_INTENT(loc.oloc->file) & H5F_ACC_RDWR))
345 HGOTO_ERROR(H5E_ARGS, H5E_WRITEERROR, FAIL, "no write intent on file")
346 if(!obj_name || !*obj_name)
347 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
348 if(!attr_name || !*attr_name)
349 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
350 if(NULL == (type = (H5T_t *)H5I_object_verify(type_id, H5I_DATATYPE)))
351 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a type")
352 if(NULL == (space = (H5S_t *)H5I_object_verify(space_id, H5I_DATASPACE)))
353 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a dataspace")
354
355 /* Verify access property list and set up collective metadata if appropriate */
356 if(H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, TRUE) < 0)
357 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, H5I_INVALID_HID, "can't set access property list info")
358
359 if(H5P_DEFAULT != lapl_id) {
360 if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS))
361 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID")
362 H5CX_set_lapl(lapl_id);
363 } /* end if */
364
365 /* Create the attribute on the object */
366 if(NULL == (attr = H5A__create_by_name(&loc, obj_name, attr_name, type, space, acpl_id)))
367 HGOTO_ERROR(H5E_ATTR, H5E_CANTINIT, FAIL, "unable to create attribute")
368
369 /* Register the new attribute and get an ID for it */
370 if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0)
371 HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID")
372
373 done:
374 /* Cleanup on failure */
375 if(ret_value < 0 && attr && H5A__close(attr) < 0)
376 HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
377
378 FUNC_LEAVE_API(ret_value)
379 } /* H5Acreate_by_name() */
380
381
382 /*--------------------------------------------------------------------------
383 NAME
384 H5Aopen
385 PURPOSE
386 Opens an attribute for an object by looking up the attribute name
387 USAGE
388 hid_t H5Aopen(loc_id, attr_name, aapl_id)
389 hid_t loc_id; IN: Object that attribute is attached to
390 const char *attr_name; IN: Name of attribute to locate and open
391 hid_t aapl_id; IN: Attribute access property list
392 RETURNS
393 ID of attribute on success, negative on failure
394
395 DESCRIPTION
396 This function opens an existing attribute for access. The attribute
397 name specified is used to look up the corresponding attribute for the
398 object. The attribute ID returned from this function must be released with
399 H5Aclose or resource leaks will develop.
400 --------------------------------------------------------------------------*/
401 hid_t
H5Aopen(hid_t loc_id,const char * attr_name,hid_t aapl_id)402 H5Aopen(hid_t loc_id, const char *attr_name, hid_t aapl_id)
403 {
404 H5G_loc_t loc; /* Object location */
405 H5A_t *attr = NULL; /* Attribute opened */
406 hid_t ret_value;
407
408 FUNC_ENTER_API(FAIL)
409 H5TRACE3("i", "i*si", loc_id, attr_name, aapl_id);
410
411 /* check arguments */
412 if(H5I_ATTR == H5I_get_type(loc_id))
413 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
414 if(H5G_loc(loc_id, &loc) < 0)
415 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
416 if(!attr_name || !*attr_name)
417 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
418
419 /* Verify access property list and set up collective metadata if appropriate */
420 if(H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, FALSE) < 0)
421 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
422
423 /* Read in attribute from object header */
424 if(NULL == (attr = H5A__open(&loc, attr_name)))
425 HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to load attribute info from object header for attribute: '%s'", attr_name)
426
427 /* Register the attribute and get an ID for it */
428 if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0)
429 HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID")
430
431 done:
432 /* Cleanup on failure */
433 if(ret_value < 0)
434 if(attr && H5A__close(attr) < 0)
435 HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
436
437 FUNC_LEAVE_API(ret_value)
438 } /* H5Aopen() */
439
440
441 /*--------------------------------------------------------------------------
442 NAME
443 H5Aopen_by_name
444 PURPOSE
445 Opens an attribute for an object by looking up the attribute name
446 USAGE
447 hid_t H5Aopen_by_name(loc_id, obj_name, attr_name, aapl_id, lapl_id)
448 hid_t loc_id; IN: Object that attribute is attached to
449 const char *obj_name; IN: Name of object relative to location
450 const char *attr_name; IN: Name of attribute to locate and open
451 hid_t aapl_id; IN: Attribute access property list
452 hid_t lapl_id; IN: Link access property list
453 RETURNS
454 ID of attribute on success, negative on failure
455
456 DESCRIPTION
457 This function opens an existing attribute for access. The attribute
458 name specified is used to look up the corresponding attribute for the
459 object. The attribute ID returned from this function must be released with
460 H5Aclose or resource leaks will develop.
461 --------------------------------------------------------------------------*/
462 hid_t
H5Aopen_by_name(hid_t loc_id,const char * obj_name,const char * attr_name,hid_t aapl_id,hid_t lapl_id)463 H5Aopen_by_name(hid_t loc_id, const char *obj_name, const char *attr_name,
464 hid_t aapl_id, hid_t lapl_id)
465 {
466 H5G_loc_t loc; /* Object location */
467 H5A_t *attr = NULL; /* Attribute opened */
468 hid_t ret_value;
469
470 FUNC_ENTER_API(FAIL)
471 H5TRACE5("i", "i*s*sii", loc_id, obj_name, attr_name, aapl_id, lapl_id);
472
473 /* check arguments */
474 if(H5I_ATTR == H5I_get_type(loc_id))
475 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
476 if(H5G_loc(loc_id, &loc) < 0)
477 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
478 if(!obj_name || !*obj_name)
479 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
480 if(!attr_name || !*attr_name)
481 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
482
483 /* Verify access property list and set up collective metadata if appropriate */
484 if(H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, FALSE) < 0)
485 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
486
487 if(H5P_DEFAULT != lapl_id) {
488 if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS))
489 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID")
490 H5CX_set_lapl(lapl_id);
491 } /* end if */
492
493 /* Open the attribute on the object header */
494 if(NULL == (attr = H5A__open_by_name(&loc, obj_name, attr_name)))
495 HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute")
496
497 /* Register the attribute and get an ID for it */
498 if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0)
499 HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID")
500
501 done:
502 /* Cleanup on failure */
503 if(ret_value < 0)
504 if(attr && H5A__close(attr) < 0)
505 HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
506
507 FUNC_LEAVE_API(ret_value)
508 } /* H5Aopen_by_name() */
509
510
511 /*--------------------------------------------------------------------------
512 NAME
513 H5Aopen_by_idx
514 PURPOSE
515 Opens the n'th attribute for an object, according to the order within
516 an index
517 USAGE
518 hid_t H5Aopen_by_idx(loc_id, obj_ame, idx_type, order, n, aapl_id, lapl_id)
519 hid_t loc_id; IN: Object that attribute is attached to
520 const char *obj_name; IN: Name of object relative to location
521 H5_index_t idx_type; IN: Type of index to use
522 H5_iter_order_t order; IN: Order to iterate over index
523 hsize_t n; IN: Index (0-based) attribute to open
524 hid_t aapl_id; IN: Attribute access property list
525 hid_t lapl_id; IN: Link access property list
526 RETURNS
527 ID of attribute on success, negative on failure
528
529 DESCRIPTION
530 This function opens an existing attribute for access. The attribute
531 index specified is used to look up the corresponding attribute for the
532 object. The attribute ID returned from this function must be released with
533 H5Aclose or resource leaks will develop.
534 --------------------------------------------------------------------------*/
535 hid_t
H5Aopen_by_idx(hid_t loc_id,const char * obj_name,H5_index_t idx_type,H5_iter_order_t order,hsize_t n,hid_t aapl_id,hid_t lapl_id)536 H5Aopen_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
537 H5_iter_order_t order, hsize_t n, hid_t aapl_id, hid_t lapl_id)
538 {
539 H5A_t *attr = NULL; /* Attribute opened */
540 H5G_loc_t loc; /* Object location */
541 hid_t ret_value; /* Return value */
542
543 FUNC_ENTER_API(FAIL)
544 H5TRACE7("i", "i*sIiIohii", loc_id, obj_name, idx_type, order, n, aapl_id,
545 lapl_id);
546
547 /* check arguments */
548 if(H5I_ATTR == H5I_get_type(loc_id))
549 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
550 if(H5G_loc(loc_id, &loc) < 0)
551 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
552 if(!obj_name || !*obj_name)
553 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
554 if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
555 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
556 if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
557 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified")
558
559 /* Verify access property list and set up collective metadata if appropriate */
560 if(H5CX_set_apl(&aapl_id, H5P_CLS_AACC, loc_id, FALSE) < 0)
561 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
562
563 if(H5P_DEFAULT != lapl_id) {
564 if(TRUE != H5P_isa_class(lapl_id, H5P_LINK_ACCESS))
565 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not link access property list ID")
566 H5CX_set_lapl(lapl_id);
567 } /* end if */
568
569 /* Open the attribute in the object header */
570 if(NULL == (attr = H5A__open_by_idx(&loc, obj_name, idx_type, order, n)))
571 HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "unable to open attribute")
572
573 /* Register the attribute and get an ID for it */
574 if((ret_value = H5I_register(H5I_ATTR, attr, TRUE)) < 0)
575 HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL, "unable to register attribute for ID")
576
577 done:
578 /* Cleanup on failure */
579 if(ret_value < 0)
580 if(attr && H5A__close(attr) < 0)
581 HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
582
583 FUNC_LEAVE_API(ret_value)
584 } /* H5Aopen_by_idx() */
585
586
587 /*--------------------------------------------------------------------------
588 NAME
589 H5Awrite
590 PURPOSE
591 Write out data to an attribute
592 USAGE
593 herr_t H5Awrite (attr_id, dtype_id, buf)
594 hid_t attr_id; IN: Attribute to write
595 hid_t dtype_id; IN: Memory datatype of buffer
596 const void *buf; IN: Buffer of data to write
597 RETURNS
598 Non-negative on success/Negative on failure
599
600 DESCRIPTION
601 This function writes a complete attribute to disk.
602 --------------------------------------------------------------------------*/
603 herr_t
H5Awrite(hid_t attr_id,hid_t dtype_id,const void * buf)604 H5Awrite(hid_t attr_id, hid_t dtype_id, const void *buf)
605 {
606 H5A_t *attr; /* Attribute object for ID */
607 H5T_t *mem_type; /* Memory datatype */
608 herr_t ret_value; /* Return value */
609
610 FUNC_ENTER_API(FAIL)
611 H5TRACE3("e", "ii*x", attr_id, dtype_id, buf);
612
613 /* check arguments */
614 if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR)))
615 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
616 if(NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE)))
617 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
618 if(NULL == buf)
619 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null attribute buffer")
620
621 /* Set up collective metadata if appropriate */
622 if(H5CX_set_loc(attr_id) < 0)
623 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set collective metadata read")
624
625 /* Go write the actual data to the attribute */
626 if((ret_value = H5A__write(attr, mem_type, buf)) < 0)
627 HGOTO_ERROR(H5E_ATTR, H5E_WRITEERROR, FAIL, "unable to write attribute")
628
629 done:
630 FUNC_LEAVE_API(ret_value)
631 } /* H5Awrite() */
632
633
634 /*--------------------------------------------------------------------------
635 NAME
636 H5Aread
637 PURPOSE
638 Read in data from an attribute
639 USAGE
640 herr_t H5Aread (attr_id, dtype_id, buf)
641 hid_t attr_id; IN: Attribute to read
642 hid_t dtype_id; IN: Memory datatype of buffer
643 void *buf; IN: Buffer for data to read
644 RETURNS
645 Non-negative on success/Negative on failure
646
647 DESCRIPTION
648 This function reads a complete attribute from disk.
649 --------------------------------------------------------------------------*/
650 herr_t
H5Aread(hid_t attr_id,hid_t dtype_id,void * buf)651 H5Aread(hid_t attr_id, hid_t dtype_id, void *buf)
652 {
653 H5A_t *attr; /* Attribute object for ID */
654 H5T_t *mem_type; /* Memory datatype */
655 herr_t ret_value; /* Return value */
656
657 FUNC_ENTER_API(FAIL)
658 H5TRACE3("e", "ii*x", attr_id, dtype_id, buf);
659
660 /* check arguments */
661 if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR)))
662 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
663 if(NULL == (mem_type = (H5T_t *)H5I_object_verify(dtype_id, H5I_DATATYPE)))
664 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a datatype")
665 if(NULL == buf)
666 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "null attribute buffer")
667
668 /* Go write the actual data to the attribute */
669 if((ret_value = H5A__read(attr, mem_type, buf)) < 0)
670 HGOTO_ERROR(H5E_ATTR, H5E_READERROR, FAIL, "unable to read attribute")
671
672 done:
673 FUNC_LEAVE_API(ret_value)
674 } /* H5Aread() */
675
676
677 /*--------------------------------------------------------------------------
678 NAME
679 H5Aget_space
680 PURPOSE
681 Gets a copy of the dataspace for an attribute
682 USAGE
683 hid_t H5Aget_space (attr_id)
684 hid_t attr_id; IN: Attribute to get dataspace of
685 RETURNS
686 A dataspace ID on success, negative on failure
687
688 DESCRIPTION
689 This function retrieves a copy of the dataspace for an attribute.
690 The dataspace ID returned from this function must be released with H5Sclose
691 or resource leaks will develop.
692 --------------------------------------------------------------------------*/
693 hid_t
H5Aget_space(hid_t attr_id)694 H5Aget_space(hid_t attr_id)
695 {
696 H5A_t *attr; /* Attribute object for ID */
697 hid_t ret_value; /* Return value */
698
699 FUNC_ENTER_API(FAIL)
700 H5TRACE1("i", "i", attr_id);
701
702 /* check arguments */
703 if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR)))
704 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
705
706 if((ret_value = H5A_get_space(attr)) < 0)
707 HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get space ID of attribute")
708 done:
709 FUNC_LEAVE_API(ret_value)
710 } /* H5Aget_space() */
711
712
713 /*--------------------------------------------------------------------------
714 NAME
715 H5Aget_type
716 PURPOSE
717 Gets a copy of the datatype for an attribute
718 USAGE
719 hid_t H5Aget_type (attr_id)
720 hid_t attr_id; IN: Attribute to get datatype of
721 RETURNS
722 A datatype ID on success, negative on failure
723
724 DESCRIPTION
725 This function retrieves a copy of the datatype for an attribute.
726 The datatype ID returned from this function must be released with H5Tclose
727 or resource leaks will develop.
728 --------------------------------------------------------------------------*/
729 hid_t
H5Aget_type(hid_t attr_id)730 H5Aget_type(hid_t attr_id)
731 {
732 H5A_t *attr; /* Attribute object for ID */
733 hid_t ret_value; /* Return value */
734
735 FUNC_ENTER_API(FAIL)
736 H5TRACE1("i", "i", attr_id);
737
738 /* check arguments */
739 if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR)))
740 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
741
742 if((ret_value = H5A__get_type(attr)) < 0)
743 HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get datatype ID of attribute")
744
745 done:
746 FUNC_LEAVE_API(ret_value)
747 } /* H5Aget_type() */
748
749
750 /*--------------------------------------------------------------------------
751 NAME
752 H5Aget_create_plist
753 PURPOSE
754 Gets a copy of the creation property list for an attribute
755 USAGE
756 hssize_t H5Aget_create_plist (attr_id, buf_size, buf)
757 hid_t attr_id; IN: Attribute to get name of
758 RETURNS
759 This function returns the ID of a copy of the attribute's creation
760 property list, or negative on failure.
761
762 ERRORS
763
764 DESCRIPTION
765 This function returns a copy of the creation property list for
766 an attribute. The resulting ID must be closed with H5Pclose() or
767 resource leaks will occur.
768 --------------------------------------------------------------------------*/
769 hid_t
H5Aget_create_plist(hid_t attr_id)770 H5Aget_create_plist(hid_t attr_id)
771 {
772 H5A_t *attr; /* Attribute object for ID */
773 hid_t ret_value;
774
775 FUNC_ENTER_API(FAIL)
776 H5TRACE1("i", "i", attr_id);
777
778 HDassert(H5P_LST_ATTRIBUTE_CREATE_ID_g != -1);
779
780 /* Get attribute and default attribute creation property list*/
781 if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR)))
782 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
783
784 if((ret_value = H5A__get_create_plist(attr)) < 0)
785 HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, FAIL, "can't get creation property list for attr")
786
787 done:
788 FUNC_LEAVE_API(ret_value)
789 } /* end H5Aget_create_plist() */
790
791
792 /*--------------------------------------------------------------------------
793 NAME
794 H5Aget_name
795 PURPOSE
796 Gets a copy of the name for an attribute
797 USAGE
798 hssize_t H5Aget_name (attr_id, buf_size, buf)
799 hid_t attr_id; IN: Attribute to get name of
800 size_t buf_size; IN: The size of the buffer to store the string in.
801 char *buf; IN: Buffer to store name in
802 RETURNS
803 This function returns the length of the attribute's name (which may be
804 longer than 'buf_size') on success or negative for failure.
805
806 DESCRIPTION
807 This function retrieves the name of an attribute for an attribute ID.
808 Up to 'buf_size' characters are stored in 'buf' followed by a '\0' string
809 terminator. If the name of the attribute is longer than 'buf_size'-1,
810 the string terminator is stored in the last position of the buffer to
811 properly terminate the string.
812 --------------------------------------------------------------------------*/
813 ssize_t
H5Aget_name(hid_t attr_id,size_t buf_size,char * buf)814 H5Aget_name(hid_t attr_id, size_t buf_size, char *buf)
815 {
816 H5A_t *my_attr; /* Attribute object for ID */
817 ssize_t ret_value;
818
819 FUNC_ENTER_API(FAIL)
820 H5TRACE3("Zs", "iz*s", attr_id, buf_size, buf);
821
822 /* check arguments */
823 if(NULL == (my_attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR)))
824 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
825 if(!buf && buf_size)
826 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid buffer")
827
828 /* Call private function in turn */
829 if(0 > (ret_value = H5A__get_name(my_attr, buf_size, buf)))
830 HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "can't get attribute name")
831
832 done:
833 FUNC_LEAVE_API(ret_value)
834 } /* H5Aget_name() */
835
836
837 /*-------------------------------------------------------------------------
838 * Function: H5Aget_name_by_idx
839 *
840 * Purpose: Retrieve name of an attribute, according to the
841 * order within an index.
842 *
843 * Same pattern of behavior as H5Iget_name.
844 *
845 * Return: Success: Non-negative length of name, with information
846 * in NAME buffer
847 * Failure: Negative
848 *
849 * Programmer: Quincey Koziol
850 * February 8, 2007
851 *
852 *-------------------------------------------------------------------------
853 */
854 ssize_t
H5Aget_name_by_idx(hid_t loc_id,const char * obj_name,H5_index_t idx_type,H5_iter_order_t order,hsize_t n,char * name,size_t size,hid_t lapl_id)855 H5Aget_name_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
856 H5_iter_order_t order, hsize_t n, char *name /*out*/, size_t size,
857 hid_t lapl_id)
858 {
859 H5G_loc_t loc; /* Object location */
860 H5A_t *attr = NULL; /* Attribute object for name */
861 ssize_t ret_value; /* Return value */
862
863 FUNC_ENTER_API(FAIL)
864 H5TRACE8("Zs", "i*sIiIohxzi", loc_id, obj_name, idx_type, order, n, name, size,
865 lapl_id);
866
867 /* Check args */
868 if(H5I_ATTR == H5I_get_type(loc_id))
869 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
870 if(H5G_loc(loc_id, &loc) < 0)
871 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
872 if(!obj_name || !*obj_name)
873 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
874 if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
875 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
876 if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
877 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified")
878
879 /* Verify access property list and set up collective metadata if appropriate */
880 if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, loc_id, FALSE) < 0)
881 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
882
883 /* Open the attribute on the object header */
884 if(NULL == (attr = H5A__open_by_idx(&loc, obj_name, idx_type, order, n)))
885 HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute")
886
887 /* Get the length of the name */
888 ret_value = (ssize_t)HDstrlen(attr->shared->name);
889
890 /* Copy the name into the user's buffer, if given */
891 if(name) {
892 HDstrncpy(name, attr->shared->name, MIN((size_t)(ret_value + 1), size));
893 if((size_t)ret_value >= size)
894 name[size - 1]='\0';
895 } /* end if */
896
897 done:
898 /* Release resources */
899 if(attr && H5A__close(attr) < 0)
900 HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
901
902 FUNC_LEAVE_API(ret_value)
903 } /* end H5Aget_name_by_idx() */
904
905
906 /*-------------------------------------------------------------------------
907 * Function: H5Aget_storage_size
908 *
909 * Purpose: Returns the amount of storage size that is required for this
910 * attribute.
911 *
912 * Return: Success: The amount of storage size allocated for the
913 * attribute. The return value may be zero
914 * if no data has been stored.
915 *
916 * Failure: Zero
917 *
918 * Programmer: Raymond Lu
919 * October 23, 2002
920 *
921 *-------------------------------------------------------------------------
922 */
923 hsize_t
H5Aget_storage_size(hid_t attr_id)924 H5Aget_storage_size(hid_t attr_id)
925 {
926 H5A_t *attr; /* Attribute object for ID */
927 hsize_t ret_value; /* Return value */
928
929 FUNC_ENTER_API(0)
930 H5TRACE1("h", "i", attr_id);
931
932 /* Check args */
933 if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR)))
934 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "not an attribute")
935
936 /* Set return value */
937 ret_value = attr->shared->data_size;
938
939 done:
940 FUNC_LEAVE_API(ret_value)
941 } /* end H5Aget_storage_size() */
942
943
944 /*-------------------------------------------------------------------------
945 * Function: H5Aget_info
946 *
947 * Purpose: Retrieve information about an attribute.
948 *
949 * Return: Success: Non-negative
950 * Failure: Negative
951 *
952 * Programmer: Quincey Koziol
953 * February 6, 2007
954 *
955 *-------------------------------------------------------------------------
956 */
957 herr_t
H5Aget_info(hid_t attr_id,H5A_info_t * ainfo)958 H5Aget_info(hid_t attr_id, H5A_info_t *ainfo)
959 {
960 H5A_t *attr; /* Attribute object for name */
961 herr_t ret_value = SUCCEED; /* Return value */
962
963 FUNC_ENTER_API(FAIL)
964 H5TRACE2("e", "i*x", attr_id, ainfo);
965
966 /* Check args */
967 if(NULL == (attr = (H5A_t *)H5I_object_verify(attr_id, H5I_ATTR)))
968 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
969
970 /* Get the attribute information */
971 if(H5A__get_info(attr, ainfo) < 0)
972 HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to get attribute info")
973
974 done:
975 FUNC_LEAVE_API(ret_value)
976 } /* end H5Aget_info() */
977
978
979 /*-------------------------------------------------------------------------
980 * Function: H5Aget_info_by_name
981 *
982 * Purpose: Retrieve information about an attribute by name.
983 *
984 * Return: Success: Non-negative
985 * Failure: Negative
986 *
987 * Programmer: Quincey Koziol
988 * February 6, 2007
989 *
990 *-------------------------------------------------------------------------
991 */
992 herr_t
H5Aget_info_by_name(hid_t loc_id,const char * obj_name,const char * attr_name,H5A_info_t * ainfo,hid_t lapl_id)993 H5Aget_info_by_name(hid_t loc_id, const char *obj_name, const char *attr_name,
994 H5A_info_t *ainfo, hid_t lapl_id)
995 {
996 H5G_loc_t loc; /* Object location */
997 H5A_t *attr = NULL; /* Attribute object for name */
998 herr_t ret_value = SUCCEED; /* Return value */
999
1000 FUNC_ENTER_API(FAIL)
1001 H5TRACE5("e", "i*s*s*xi", loc_id, obj_name, attr_name, ainfo, lapl_id);
1002
1003 /* Check args */
1004 if(H5I_ATTR == H5I_get_type(loc_id))
1005 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1006 if(H5G_loc(loc_id, &loc) < 0)
1007 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1008 if(!obj_name || !*obj_name)
1009 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
1010 if(!attr_name || !*attr_name)
1011 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
1012 if(NULL == ainfo)
1013 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid info pointer")
1014
1015 /* Verify access property list and set up collective metadata if appropriate */
1016 if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, loc_id, FALSE) < 0)
1017 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
1018
1019 /* Open the attribute on the object header */
1020 if(NULL == (attr = H5A__open_by_name(&loc, obj_name, attr_name)))
1021 HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute")
1022
1023 /* Get the attribute information */
1024 if(H5A__get_info(attr, ainfo) < 0)
1025 HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to get attribute info")
1026
1027 done:
1028 /* Release resources */
1029 if(attr && H5A__close(attr) < 0)
1030 HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
1031
1032 FUNC_LEAVE_API(ret_value)
1033 } /* end H5Aget_info_by_name() */
1034
1035
1036 /*-------------------------------------------------------------------------
1037 * Function: H5Aget_info_by_idx
1038 *
1039 * Purpose: Retrieve information about an attribute, according to the
1040 * order within an index.
1041 *
1042 * Return: Success: Non-negative with information in AINFO
1043 * Failure: Negative
1044 *
1045 * Programmer: Quincey Koziol
1046 * February 8, 2007
1047 *
1048 *-------------------------------------------------------------------------
1049 */
1050 herr_t
H5Aget_info_by_idx(hid_t loc_id,const char * obj_name,H5_index_t idx_type,H5_iter_order_t order,hsize_t n,H5A_info_t * ainfo,hid_t lapl_id)1051 H5Aget_info_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
1052 H5_iter_order_t order, hsize_t n, H5A_info_t *ainfo, hid_t lapl_id)
1053 {
1054 H5G_loc_t loc; /* Object location */
1055 H5A_t *attr = NULL; /* Attribute object for name */
1056 herr_t ret_value = SUCCEED; /* Return value */
1057
1058 FUNC_ENTER_API(FAIL)
1059 H5TRACE7("e", "i*sIiIoh*xi", loc_id, obj_name, idx_type, order, n, ainfo,
1060 lapl_id);
1061
1062 /* Check args */
1063 if(H5I_ATTR == H5I_get_type(loc_id))
1064 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1065 if(H5G_loc(loc_id, &loc) < 0)
1066 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1067 if(!obj_name || !*obj_name)
1068 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
1069 if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
1070 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
1071 if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
1072 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified")
1073 if(NULL == ainfo)
1074 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid info pointer")
1075
1076 /* Verify access property list and set up collective metadata if appropriate */
1077 if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, loc_id, FALSE) < 0)
1078 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
1079
1080 /* Open the attribute on the object header */
1081 if(NULL == (attr = H5A__open_by_idx(&loc, obj_name, idx_type, order, n)))
1082 HGOTO_ERROR(H5E_ATTR, H5E_CANTOPENOBJ, FAIL, "can't open attribute")
1083
1084 /* Get the attribute information */
1085 if(H5A__get_info(attr, ainfo) < 0)
1086 HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to get attribute info")
1087
1088 done:
1089 /* Release resources */
1090 if(attr && H5A__close(attr) < 0)
1091 HDONE_ERROR(H5E_ATTR, H5E_CANTFREE, FAIL, "can't close attribute")
1092
1093 FUNC_LEAVE_API(ret_value)
1094 } /* end H5Aget_info_by_idx() */
1095
1096
1097 /*-------------------------------------------------------------------------
1098 * Function: H5Arename
1099 *
1100 * Purpose: Rename an attribute
1101 *
1102 * Return: Success: Non-negative
1103 * Failure: Negative
1104 *
1105 * Programmer: Raymond Lu
1106 * October 23, 2002
1107 *
1108 *-------------------------------------------------------------------------
1109 */
1110 herr_t
H5Arename(hid_t loc_id,const char * old_name,const char * new_name)1111 H5Arename(hid_t loc_id, const char *old_name, const char *new_name)
1112 {
1113 herr_t ret_value = SUCCEED; /* Return value */
1114
1115 FUNC_ENTER_API(FAIL)
1116 H5TRACE3("e", "i*s*s", loc_id, old_name, new_name);
1117
1118 /* check arguments */
1119 if(!old_name || !new_name)
1120 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "name is nil")
1121 if(H5I_ATTR == H5I_get_type(loc_id))
1122 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1123
1124 /* Avoid thrashing things if the names are the same */
1125 if(HDstrcmp(old_name, new_name)) {
1126 H5G_loc_t loc; /* Object location */
1127
1128 if(H5G_loc(loc_id, &loc) < 0)
1129 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1130
1131 /* Set up collective metadata if appropriate */
1132 if(H5CX_set_loc(loc_id) < 0)
1133 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set collective metadata read")
1134
1135 /* Call private attribute rename routine */
1136 if(H5A__rename(&loc, old_name, new_name) < 0)
1137 HGOTO_ERROR(H5E_ATTR, H5E_CANTRENAME, FAIL, "can't rename attribute")
1138 } /* end if */
1139
1140 done:
1141 FUNC_LEAVE_API(ret_value)
1142 } /* H5Arename() */
1143
1144
1145 /*-------------------------------------------------------------------------
1146 * Function: H5Arename_by_name
1147 *
1148 * Purpose: Rename an attribute
1149 *
1150 * Return: Success: Non-negative
1151 * Failure: Negative
1152 *
1153 * Programmer: Quincey Koziol
1154 * February 20, 2007
1155 *
1156 *-------------------------------------------------------------------------
1157 */
1158 herr_t
H5Arename_by_name(hid_t loc_id,const char * obj_name,const char * old_attr_name,const char * new_attr_name,hid_t lapl_id)1159 H5Arename_by_name(hid_t loc_id, const char *obj_name, const char *old_attr_name,
1160 const char *new_attr_name, hid_t lapl_id)
1161 {
1162 herr_t ret_value = SUCCEED; /* Return value */
1163
1164 FUNC_ENTER_API(FAIL)
1165 H5TRACE5("e", "i*s*s*si", loc_id, obj_name, old_attr_name, new_attr_name,
1166 lapl_id);
1167
1168 /* check arguments */
1169 if(H5I_ATTR == H5I_get_type(loc_id))
1170 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1171 if(!obj_name || !*obj_name)
1172 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
1173 if(!old_attr_name || !*old_attr_name)
1174 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no old attribute name")
1175 if(!new_attr_name || !*new_attr_name)
1176 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no new attribute name")
1177
1178 /* Avoid thrashing things if the names are the same */
1179 if(HDstrcmp(old_attr_name, new_attr_name)) {
1180 H5G_loc_t loc; /* Object location */
1181
1182 /* Verify access property list and set up collective metadata if appropriate */
1183 if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, loc_id, TRUE) < 0)
1184 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
1185
1186 if(H5G_loc(loc_id, &loc) < 0)
1187 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1188
1189 /* Call private attribute rename routine */
1190 if(H5A__rename_by_name(loc, obj_name, old_attr_name, new_attr_name) < 0)
1191 HGOTO_ERROR(H5E_ATTR, H5E_CANTRENAME, FAIL, "can't rename attribute")
1192 } /* end if */
1193
1194 done:
1195 FUNC_LEAVE_API(ret_value)
1196 } /* H5Arename_by_name() */
1197
1198
1199 /*--------------------------------------------------------------------------
1200 NAME
1201 H5Aiterate2
1202 PURPOSE
1203 Calls a user's function for each attribute on an object
1204 USAGE
1205 herr_t H5Aiterate2(loc_id, idx_type, order, idx, op, op_data)
1206 hid_t loc_id; IN: Base location for object
1207 H5_index_t idx_type; IN: Type of index to use
1208 H5_iter_order_t order; IN: Order to iterate over index
1209 hsize_t *idx; IN/OUT: Starting (IN) & Ending (OUT) attribute
1210 in index & order
1211 H5A_operator2_t op; IN: User's function to pass each attribute to
1212 void *op_data; IN/OUT: User's data to pass through to iterator
1213 operator function
1214 RETURNS
1215 Returns a negative value if an error occurs, the return value of the
1216 last operator if it was non-zero (which can be a negative value), or zero
1217 if all attributes were processed.
1218
1219 DESCRIPTION
1220 This function interates over the attributes of dataset or group
1221 specified with 'loc_id' & 'obj_name'. For each attribute of the object,
1222 the 'op_data' and some additional information (specified below) are passed
1223 to the 'op' function. The iteration begins with the '*idx'
1224 object in the group and the next attribute to be processed by the operator
1225 is returned in '*idx'.
1226 The operation receives the ID for the group or dataset being iterated
1227 over ('loc_id'), the name of the current attribute about the object
1228 ('attr_name'), the attribute's "info" struct ('ainfo') and the pointer to
1229 the operator data passed in to H5Aiterate2 ('op_data'). The return values
1230 from an operator are:
1231 A. Zero causes the iterator to continue, returning zero when all
1232 attributes have been processed.
1233 B. Positive causes the iterator to immediately return that positive
1234 value, indicating short-circuit success. The iterator can be
1235 restarted at the next attribute.
1236 C. Negative causes the iterator to immediately return that value,
1237 indicating failure. The iterator can be restarted at the next
1238 attribute.
1239 --------------------------------------------------------------------------*/
1240 herr_t
H5Aiterate2(hid_t loc_id,H5_index_t idx_type,H5_iter_order_t order,hsize_t * idx,H5A_operator2_t op,void * op_data)1241 H5Aiterate2(hid_t loc_id, H5_index_t idx_type, H5_iter_order_t order,
1242 hsize_t *idx, H5A_operator2_t op, void *op_data)
1243 {
1244 herr_t ret_value; /* Return value */
1245
1246 FUNC_ENTER_API(FAIL)
1247 H5TRACE6("e", "iIiIo*hx*x", loc_id, idx_type, order, idx, op, op_data);
1248
1249 /* check arguments */
1250 if(H5I_ATTR == H5I_get_type(loc_id))
1251 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1252 if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
1253 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
1254 if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
1255 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified")
1256
1257 /* Call attribute iteration routine */
1258 if((ret_value = H5A__iterate(loc_id, idx_type, order, idx, op, op_data)) < 0)
1259 HERROR(H5E_ATTR, H5E_BADITER, "error iterating over attributes");
1260
1261 done:
1262 FUNC_LEAVE_API(ret_value)
1263 } /* H5Aiterate2() */
1264
1265
1266 /*--------------------------------------------------------------------------
1267 NAME
1268 H5Aiterate_by_name
1269 PURPOSE
1270 Calls a user's function for each attribute on an object
1271 USAGE
1272 herr_t H5Aiterate2(loc_id, obj_name, idx_type, order, idx, op, op_data, lapl_id)
1273 hid_t loc_id; IN: Base location for object
1274 const char *obj_name; IN: Name of object relative to location
1275 H5_index_t idx_type; IN: Type of index to use
1276 H5_iter_order_t order; IN: Order to iterate over index
1277 hsize_t *idx; IN/OUT: Starting (IN) & Ending (OUT) attribute
1278 in index & order
1279 H5A_operator2_t op; IN: User's function to pass each attribute to
1280 void *op_data; IN/OUT: User's data to pass through to iterator
1281 operator function
1282 hid_t lapl_id; IN: Link access property list
1283 RETURNS
1284 Returns a negative value if an error occurs, the return value of the
1285 last operator if it was non-zero (which can be a negative value), or zero
1286 if all attributes were processed.
1287
1288 DESCRIPTION
1289 This function interates over the attributes of dataset or group
1290 specified with 'loc_id' & 'obj_name'. For each attribute of the object,
1291 the 'op_data' and some additional information (specified below) are passed
1292 to the 'op' function. The iteration begins with the '*idx'
1293 object in the group and the next attribute to be processed by the operator
1294 is returned in '*idx'.
1295 The operation receives the ID for the group or dataset being iterated
1296 over ('loc_id'), the name of the current attribute about the object
1297 ('attr_name'), the attribute's "info" struct ('ainfo') and the pointer to
1298 the operator data passed in to H5Aiterate_by_name ('op_data'). The return values
1299 from an operator are:
1300 A. Zero causes the iterator to continue, returning zero when all
1301 attributes have been processed.
1302 B. Positive causes the iterator to immediately return that positive
1303 value, indicating short-circuit success. The iterator can be
1304 restarted at the next attribute.
1305 C. Negative causes the iterator to immediately return that value,
1306 indicating failure. The iterator can be restarted at the next
1307 attribute.
1308 --------------------------------------------------------------------------*/
1309 herr_t
H5Aiterate_by_name(hid_t loc_id,const char * obj_name,H5_index_t idx_type,H5_iter_order_t order,hsize_t * idx,H5A_operator2_t op,void * op_data,hid_t lapl_id)1310 H5Aiterate_by_name(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
1311 H5_iter_order_t order, hsize_t *idx, H5A_operator2_t op, void *op_data,
1312 hid_t lapl_id)
1313 {
1314 H5G_loc_t loc; /* Object location */
1315 herr_t ret_value; /* Return value */
1316
1317 FUNC_ENTER_API(FAIL)
1318 H5TRACE8("e", "i*sIiIo*hx*xi", loc_id, obj_name, idx_type, order, idx, op,
1319 op_data, lapl_id);
1320
1321 /* check arguments */
1322 if(H5I_ATTR == H5I_get_type(loc_id))
1323 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1324 if(H5G_loc(loc_id, &loc) < 0)
1325 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1326 if(!obj_name || !*obj_name)
1327 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
1328 if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
1329 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
1330 if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
1331 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified")
1332
1333 /* Verify access property list and set up collective metadata if appropriate */
1334 if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, loc_id, FALSE) < 0)
1335 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
1336
1337 /* Call attribute iteration by name routine */
1338 if((ret_value = H5A__iterate_by_name(&loc, obj_name, idx_type, order, idx, op, op_data)) < 0)
1339 HERROR(H5E_ATTR, H5E_BADITER, "error iterating over attributes");
1340
1341 done:
1342 FUNC_LEAVE_API(ret_value)
1343 } /* H5Aiterate_by_name() */
1344
1345
1346 /*--------------------------------------------------------------------------
1347 NAME
1348 H5Adelete
1349 PURPOSE
1350 Deletes an attribute from a location
1351 USAGE
1352 herr_t H5Adelete(loc_id, name)
1353 hid_t loc_id; IN: Object (dataset or group) to have attribute deleted from
1354 const char *name; IN: Name of attribute to delete
1355 RETURNS
1356 Non-negative on success/Negative on failure
1357 DESCRIPTION
1358 This function removes the named attribute from a dataset or group.
1359 --------------------------------------------------------------------------*/
1360 herr_t
H5Adelete(hid_t loc_id,const char * name)1361 H5Adelete(hid_t loc_id, const char *name)
1362 {
1363 H5G_loc_t loc; /* Object location */
1364 herr_t ret_value = SUCCEED; /* Return value */
1365
1366 FUNC_ENTER_API(FAIL)
1367 H5TRACE2("e", "i*s", loc_id, name);
1368
1369 /* check arguments */
1370 if(H5I_ATTR == H5I_get_type(loc_id))
1371 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1372 if(H5G_loc(loc_id, &loc) < 0)
1373 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1374 if(!name || !*name)
1375 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no name")
1376
1377 /* Set up collective metadata if appropriate */
1378 if(H5CX_set_loc(loc_id) < 0)
1379 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set collective metadata read")
1380
1381 /* Delete the attribute from the location */
1382 if(H5A__delete(&loc, name) < 0)
1383 HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute")
1384
1385 done:
1386 FUNC_LEAVE_API(ret_value)
1387 } /* H5Adelete() */
1388
1389
1390 /*--------------------------------------------------------------------------
1391 NAME
1392 H5Adelete_by_name
1393 PURPOSE
1394 Deletes an attribute from a location
1395 USAGE
1396 herr_t H5Adelete_by_name(loc_id, obj_name, attr_name, lapl_id)
1397 hid_t loc_id; IN: Base location for object
1398 const char *obj_name; IN: Name of object relative to location
1399 const char *attr_name; IN: Name of attribute to delete
1400 hid_t lapl_id; IN: Link access property list
1401 RETURNS
1402 Non-negative on success/Negative on failure
1403 DESCRIPTION
1404 This function removes the named attribute from an object.
1405 --------------------------------------------------------------------------*/
1406 herr_t
H5Adelete_by_name(hid_t loc_id,const char * obj_name,const char * attr_name,hid_t lapl_id)1407 H5Adelete_by_name(hid_t loc_id, const char *obj_name, const char *attr_name,
1408 hid_t lapl_id)
1409 {
1410 H5G_loc_t loc; /* Object location */
1411 herr_t ret_value = SUCCEED; /* Return value */
1412
1413 FUNC_ENTER_API(FAIL)
1414 H5TRACE4("e", "i*s*si", loc_id, obj_name, attr_name, lapl_id);
1415
1416 /* check arguments */
1417 if(H5I_ATTR == H5I_get_type(loc_id))
1418 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1419 if(H5G_loc(loc_id, &loc) < 0)
1420 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1421 if(!obj_name || !*obj_name)
1422 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
1423 if(!attr_name || !*attr_name)
1424 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
1425
1426 /* Verify access property list and set up collective metadata if appropriate */
1427 if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, loc_id, TRUE) < 0)
1428 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
1429
1430 /* Delete the attribute from the location */
1431 if(H5A__delete_by_name(&loc, obj_name, attr_name) < 0)
1432 HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute")
1433
1434 done:
1435 FUNC_LEAVE_API(ret_value)
1436 } /* H5Adelete_by_name() */
1437
1438
1439 /*--------------------------------------------------------------------------
1440 NAME
1441 H5Adelete_by_idx
1442 PURPOSE
1443 Deletes an attribute from a location, according to the order within an index
1444 USAGE
1445 herr_t H5Adelete_by_idx(loc_id, obj_name, idx_type, order, n, lapl_id)
1446 hid_t loc_id; IN: Base location for object
1447 const char *obj_name; IN: Name of object relative to location
1448 H5_index_t idx_type; IN: Type of index to use
1449 H5_iter_order_t order; IN: Order to iterate over index
1450 hsize_t n; IN: Offset within index
1451 hid_t lapl_id; IN: Link access property list
1452 RETURNS
1453 Non-negative on success/Negative on failure
1454 DESCRIPTION
1455 This function removes an attribute from an object, using the IDX_TYPE
1456 index to delete the N'th attribute in ORDER direction in the index. The
1457 object is specified relative to the LOC_ID with the OBJ_NAME path. To
1458 remove an attribute on the object specified by LOC_ID, pass in "." for
1459 OBJ_NAME. The link access property list, LAPL_ID, controls aspects of
1460 the group hierarchy traversal when using the OBJ_NAME to locate the final
1461 object to operate on.
1462 --------------------------------------------------------------------------*/
1463 herr_t
H5Adelete_by_idx(hid_t loc_id,const char * obj_name,H5_index_t idx_type,H5_iter_order_t order,hsize_t n,hid_t lapl_id)1464 H5Adelete_by_idx(hid_t loc_id, const char *obj_name, H5_index_t idx_type,
1465 H5_iter_order_t order, hsize_t n, hid_t lapl_id)
1466 {
1467 H5G_loc_t loc; /* Object location */
1468 herr_t ret_value = SUCCEED; /* Return value */
1469
1470 FUNC_ENTER_API(FAIL)
1471 H5TRACE6("e", "i*sIiIohi", loc_id, obj_name, idx_type, order, n, lapl_id);
1472
1473 /* check arguments */
1474 if(H5I_ATTR == H5I_get_type(loc_id))
1475 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1476 if(H5G_loc(loc_id, &loc) < 0)
1477 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1478 if(!obj_name || !*obj_name)
1479 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
1480 if(idx_type <= H5_INDEX_UNKNOWN || idx_type >= H5_INDEX_N)
1481 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid index type specified")
1482 if(order <= H5_ITER_UNKNOWN || order >= H5_ITER_N)
1483 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "invalid iteration order specified")
1484
1485 /* Verify access property list and set up collective metadata if appropriate */
1486 if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, loc_id, TRUE) < 0)
1487 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
1488
1489 /* Delete the attribute from the location */
1490 if(H5A__delete_by_idx(&loc, obj_name, idx_type, order, n) < 0)
1491 HGOTO_ERROR(H5E_ATTR, H5E_CANTDELETE, FAIL, "unable to delete attribute")
1492
1493 done:
1494 FUNC_LEAVE_API(ret_value)
1495 } /* H5Adelete_by_idx() */
1496
1497
1498 /*--------------------------------------------------------------------------
1499 NAME
1500 H5Aclose
1501 PURPOSE
1502 Close an attribute ID
1503 USAGE
1504 herr_t H5Aclose (attr_id)
1505 hid_t attr_id; IN: Attribute to release access to
1506 RETURNS
1507 Non-negative on success/Negative on failure
1508
1509 DESCRIPTION
1510 This function releases an attribute from use. Further use of the
1511 attribute ID will result in undefined behavior.
1512 --------------------------------------------------------------------------*/
1513 herr_t
H5Aclose(hid_t attr_id)1514 H5Aclose(hid_t attr_id)
1515 {
1516 herr_t ret_value = SUCCEED; /* Return value */
1517
1518 FUNC_ENTER_API(FAIL)
1519 H5TRACE1("e", "i", attr_id);
1520
1521 /* check arguments */
1522 if(NULL == H5I_object_verify(attr_id, H5I_ATTR))
1523 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not an attribute")
1524
1525 /* Decrement references to that atom (and close it) */
1526 if(H5I_dec_app_ref(attr_id) < 0)
1527 HGOTO_ERROR(H5E_ATTR, H5E_CANTDEC, FAIL, "can't close attribute")
1528
1529 done:
1530 FUNC_LEAVE_API(ret_value)
1531 } /* H5Aclose() */
1532
1533
1534 /*-------------------------------------------------------------------------
1535 * Function: H5Aexists
1536 *
1537 * Purpose: Checks if an attribute with a given name exists on an opened
1538 * object.
1539 *
1540 * Return: Success: TRUE/FALSE
1541 * Failure: Negative
1542 *
1543 * Programmer: Quincey Koziol
1544 * Thursday, November 1, 2007
1545 *
1546 *-------------------------------------------------------------------------
1547 */
1548 htri_t
H5Aexists(hid_t obj_id,const char * attr_name)1549 H5Aexists(hid_t obj_id, const char *attr_name)
1550 {
1551 H5G_loc_t loc; /* Object location */
1552 htri_t ret_value; /* Return value */
1553
1554 FUNC_ENTER_API(FAIL)
1555 H5TRACE2("t", "i*s", obj_id, attr_name);
1556
1557 /* check arguments */
1558 if (H5I_ATTR == H5I_get_type(obj_id))
1559 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1560 if (H5G_loc(obj_id, &loc) < 0)
1561 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1562 if (!attr_name || !*attr_name)
1563 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
1564
1565 /* Check if the attribute exists */
1566 if((ret_value = H5A__exists(&loc, attr_name)) < 0)
1567 HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to determine if attribute exists")
1568
1569 done:
1570 FUNC_LEAVE_API(ret_value)
1571 } /* H5Aexists() */
1572
1573
1574 /*-------------------------------------------------------------------------
1575 * Function: H5Aexists_by_name
1576 *
1577 * Purpose: Checks if an attribute with a given name exists on an object.
1578 *
1579 * Return: Success: TRUE/FALSE
1580 * Failure: Negative
1581 *
1582 * Programmer: Quincey Koziol
1583 * Thursday, November 1, 2007
1584 *
1585 *-------------------------------------------------------------------------
1586 */
1587 htri_t
H5Aexists_by_name(hid_t loc_id,const char * obj_name,const char * attr_name,hid_t lapl_id)1588 H5Aexists_by_name(hid_t loc_id, const char *obj_name, const char *attr_name,
1589 hid_t lapl_id)
1590 {
1591 H5G_loc_t loc; /* Object location */
1592 htri_t ret_value; /* Return value */
1593
1594 FUNC_ENTER_API(FAIL)
1595 H5TRACE4("t", "i*s*si", loc_id, obj_name, attr_name, lapl_id);
1596
1597 /* check arguments */
1598 if (H5I_ATTR == H5I_get_type(loc_id))
1599 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "location is not valid for an attribute")
1600 if (H5G_loc(loc_id, &loc) < 0)
1601 HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a location")
1602 if (!obj_name || !*obj_name)
1603 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no object name")
1604 if (!attr_name || !*attr_name)
1605 HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no attribute name")
1606
1607 /* Verify access property list and set up collective metadata if appropriate */
1608 if(H5CX_set_apl(&lapl_id, H5P_CLS_LACC, loc_id, FALSE) < 0)
1609 HGOTO_ERROR(H5E_ATTR, H5E_CANTSET, FAIL, "can't set access property list info")
1610
1611 if ((ret_value = H5A__exists_by_name(loc, obj_name, attr_name)) < 0)
1612 HGOTO_ERROR(H5E_ATTR, H5E_CANTGET, FAIL, "unable to determine if attribute exists")
1613
1614 done:
1615 FUNC_LEAVE_API(ret_value)
1616 } /* H5Aexists_by_name() */
1617
1618