1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (c) 2018-2020 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2019-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2021-2023 Nanook Consulting. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "pmix_config.h"
#include <assert.h>
#include "src/util/pmix_string_copy.h"
void pmix_string_copy(char *dest, const char *src, size_t dest_len)
{
size_t i;
char *new_dest = dest;
// PMIx does not do *giant* string copies. Hence, we use the
// heuristic: if "dest_len" is too large, this is a programmer
// error. We pseudo-arbitrarily pick a large value to be the max
// allowable dest_len: 128K. If we ever need to increase this
// value someday (because something has a legit reason to
// pmix_string_copy() more than 128K), the core dumps that are
// generated by the assert() failure should make this fairly
// obvious.
assert(dest_len <= PMIX_MAX_SIZE_ALLOWED_BY_PMIX_STRING_COPY);
for (i = 0; i < dest_len; ++i, ++src, ++new_dest) {
*new_dest = *src;
if ('\0' == *src) {
return;
}
}
dest[i - 1] = '\0';
}
char *pmix_getline(FILE *fp)
{
char *ret, *buff;
char input[1024];
ret = fgets(input, 1024, fp);
if (NULL != ret) {
input[strlen(input) - 1] = '\0'; /* remove newline */
buff = strdup(input);
return buff;
}
return NULL;
}