1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2005 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2013 Los Alamos National Security, LLC. All rights
14 * reserved.
15 * Copyright (c) 2015 Research Organization for Information Science
16 * and Technology (RIST). All rights reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 */
23
24 #include "ompi_config.h"
25
26 #include "ompi/mpi/c/bindings.h"
27 #include "ompi/runtime/params.h"
28 #include "ompi/communicator/communicator.h"
29 #include "ompi/errhandler/errhandler.h"
30 #include "ompi/info/info.h"
31 #include <stdlib.h>
32 #include <string.h>
33
34 #if OMPI_BUILD_MPI_PROFILING
35 #if OPAL_HAVE_WEAK_SYMBOLS
36 #pragma weak MPI_Info_get_valuelen = PMPI_Info_get_valuelen
37 #endif
38 #define MPI_Info_get_valuelen PMPI_Info_get_valuelen
39 #endif
40
41 static const char FUNC_NAME[] = "MPI_Info_get_valuelen";
42
43
44 /**
45 * MPI_Info_get_valuelen - Get the length of a value for a given key in an 'M
46 *
47 * @param info - info object (handle)
48 * @param key - null-terminated character string of the index key
49 * @param valuelen - length of the value associated with 'key' (integer)
50 * @param flag - true (1) if 'key' defined on 'info', false (0) if not
51 * (logical)
52 *
53 * @retval MPI_SUCCESS
54 * @retval MPI_ERR_ARG
55 * @retval MPI_ERR_INFO
56 * @retval MPI_ERR_INFO_KEY
57 *
58 * The length returned in C and C++ does not include the end-of-string
59 * character. If the 'key' is not found on 'info', 'valuelen' is left
60 * alone.
61 */
62 int MPI_Info_get_valuelen(MPI_Info info, const char *key, int *valuelen,
63 int *flag)
64 {
65 int key_length;
66 int err;
67
68 /*
69 * Simple function. All we need to do is search for the value
70 * having the "key" associated with it and return the length
71 */
72 if (MPI_PARAM_CHECK) {
73 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
74 if (NULL == info || MPI_INFO_NULL == info ||
75 ompi_info_is_freed(info)) {
76 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_INFO,
77 FUNC_NAME);
78 }
79 key_length = (key) ? (int)strlen (key) : 0;
80 if ((NULL == key) || (0 == key_length) ||
81 (MPI_MAX_INFO_KEY <= key_length)) {
82 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_INFO_KEY,
83 FUNC_NAME);
84 }
85 if (NULL == flag || NULL == valuelen) {
86 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
87 FUNC_NAME);
88 }
89 }
90
91 OPAL_CR_ENTER_LIBRARY();
92
93 err = ompi_info_get_valuelen (info, key, valuelen, flag);
94 OMPI_ERRHANDLER_RETURN(err, MPI_COMM_WORLD, err, FUNC_NAME);
95 }