1 /*
2 * Copyright (c) 2018 Cisco Systems, Inc. All rights reserved.
3 * $COPYRIGHT$
4 *
5 * Additional copyrights may follow
6 *
7 * $HEADER$
8 */
9
10 #include "opal_config.h"
11
12 #include <assert.h>
13
14 #include "opal/util/string_copy.h"
15
16
17 void opal_string_copy(char *dest, const char *src, size_t dest_len)
18 {
19 size_t i;
20 char *new_dest = dest;
21
22 // Open MPI does not do *giant* string copies. Hence, we use the
23 // hueristic: if "dest_len" is too large, this is a programmer
24 // error. We pseudo-arbitrarily pick a large value to be the max
25 // allowable dest_len: 128K. If we ever need to increase this
26 // value someday (because something has a legit reason to
27 // opal_string_copy() more than 128K), the core dumps that are
28 // generated by the assert() failure should make this fairly
29 // obvious.
30 assert(dest_len <= OPAL_MAX_SIZE_ALLOWED_BY_OPAL_STRING_COPY);
31
32 for (i = 0; i < dest_len; ++i, ++src, ++new_dest) {
33 *new_dest = *src;
34 if ('\0' == *src) {
35 return;
36 }
37 }
38
39 dest[i - 1] = '\0';
40 }