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) 2006-2018 Cisco Systems, Inc. All rights reserved
13 * Copyright (c) 2015-2017 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/threads/mutex.h"
27 #include "opal/util/string_copy.h"
28
29 #include "ompi/mpi/c/bindings.h"
30 #include "ompi/runtime/params.h"
31 #include "ompi/communicator/communicator.h"
32 #include "ompi/errhandler/errhandler.h"
33 #include "ompi/totalview.h"
34 #include "ompi/memchecker.h"
35
36 #if OMPI_BUILD_MPI_PROFILING
37 #if OPAL_HAVE_WEAK_SYMBOLS
38 #pragma weak MPI_Comm_get_name = PMPI_Comm_get_name
39 #endif
40 #define MPI_Comm_get_name PMPI_Comm_get_name
41 #endif
42
43 static const char FUNC_NAME[] = "MPI_Comm_get_name";
44
45
46 int MPI_Comm_get_name(MPI_Comm comm, char *name, int *length)
47 {
48 MEMCHECKER(
49 memchecker_comm(comm);
50 );
51
52 OPAL_CR_NOOP_PROGRESS();
53
54 if ( MPI_PARAM_CHECK ) {
55 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
56
57 if ( ompi_comm_invalid ( comm ) )
58 return OMPI_ERRHANDLER_INVOKE ( MPI_COMM_WORLD, MPI_ERR_COMM,
59 FUNC_NAME);
60
61 if ( NULL == name || NULL == length )
62 return OMPI_ERRHANDLER_INVOKE ( comm, MPI_ERR_ARG,
63 FUNC_NAME);
64 }
65 OPAL_THREAD_LOCK(&(comm->c_lock));
66 /* Note that MPI-2.1 requires:
67 - terminating the string with a \0
68 - name[*resultlen] == '\0'
69 - and therefore (*resultlen) cannot be > (MPI_MAX_OBJECT_NAME-1)
70
71 The Fortran API version will pad to the right if necessary.
72
73 Note that comm->c_name is guaranteed to be \0-terminated and
74 able to completely fit into MPI_MAX_OBJECT_NAME bytes (i.e.,
75 name+\0). */
76 if ( comm->c_flags & OMPI_COMM_NAMEISSET ) {
77 opal_string_copy(name, comm->c_name, MPI_MAX_OBJECT_NAME);
78 *length = (int) strlen(comm->c_name);
79 } else {
80 name[0] = '\0';
81 *length = 0;
82 }
83 OPAL_THREAD_UNLOCK(&(comm->c_lock));
84
85 return MPI_SUCCESS;
86 }