File: string_copy.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (39 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (5)
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
/*
 * Copyright (c) 2018 Cisco Systems, Inc.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "opal_config.h"

#include <assert.h>

#include "opal/util/string_copy.h"

void opal_string_copy(char *dest, const char *src, size_t dest_len)
{
    size_t i;
    char *new_dest = dest;

    // Open MPI 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
    // opal_string_copy() more than 128K), the core dumps that are
    // generated by the assert() failure should make this fairly
    // obvious.
    assert(dest_len <= OPAL_MAX_SIZE_ALLOWED_BY_OPAL_STRING_COPY);

    for (i = 0; i < dest_len; ++i, ++src, ++new_dest) {
        *new_dest = *src;
        if ('\0' == *src) {
            return;
        }
    }

    dest[i - 1] = '\0';
}