1 /*
2 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
3 * University Research and Technology
4 * Corporation. All rights reserved.
5 * Copyright (c) 2004-2005 The University of Tennessee and The University
6 * of Tennessee Research Foundation. All rights
7 * reserved.
8 * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
9 * University of Stuttgart. All rights reserved.
10 * Copyright (c) 2004-2005 The Regents of the University of California.
11 * All rights reserved.
12 * Copyright (c) 2008-2018 Cisco Systems, Inc. All rights reserved
13 * Copyright (c) 2015 Research Organization for Information Science
14 * and Technology (RIST). All rights reserved.
15 * $COPYRIGHT$
16 *
17 * Additional copyrights may follow
18 *
19 * $HEADER$
20 */
21
22 #include "ompi_config.h"
23
24 #include <string.h>
25
26 #include "opal/util/string_copy.h"
27
28 #include "ompi/mpi/c/bindings.h"
29 #include "ompi/runtime/params.h"
30 #include "ompi/communicator/communicator.h"
31 #include "ompi/errhandler/errhandler.h"
32 #include "ompi/datatype/ompi_datatype.h"
33 #include "ompi/memchecker.h"
34
35 #if OMPI_BUILD_MPI_PROFILING
36 #if OPAL_HAVE_WEAK_SYMBOLS
37 #pragma weak MPI_Type_get_name = PMPI_Type_get_name
38 #endif
39 #define MPI_Type_get_name PMPI_Type_get_name
40 #endif
41
42 static const char FUNC_NAME[] = "MPI_Type_get_name";
43
44
45 int MPI_Type_get_name(MPI_Datatype type, char *type_name, int *resultlen)
46 {
47
48 MEMCHECKER(
49 memchecker_datatype(type);
50 );
51
52 OPAL_CR_NOOP_PROGRESS();
53
54 if ( MPI_PARAM_CHECK ) {
55 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
56 if (NULL == type || MPI_DATATYPE_NULL == type) {
57 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_TYPE,
58 FUNC_NAME );
59 } else if (NULL == type_name || NULL == resultlen) {
60 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG,
61 FUNC_NAME );
62 }
63 }
64
65 /* Note that MPI-2.1 requires:
66 - terminating the string with a \0
67 - name[*resultlen] == '\0'
68 - and therefore (*resultlen) cannot be > (MPI_MAX_OBJECT_NAME-1)
69
70 The Fortran API version will pad to the right if necessary.
71
72 Note that type->name is guaranteed to be \0-terminated and
73 able to completely fit into MPI_MAX_OBJECT_NAME bytes (i.e.,
74 name+\0). */
75 *resultlen = (int)strlen(type->name);
76 opal_string_copy(type_name, type->name, MPI_MAX_OBJECT_NAME);
77 return MPI_SUCCESS;
78 }