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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/* -*- C -*-
*
* This code is derived from MPICH, which is copyright
* (C) 2001 by Argonne National Laboratory.
*
* Copyright 2016 Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
* retains certain rights in this software.
*
* Copyright (c) 2016 Intel Corporation. All rights reserved.
* This software is available to you under the BSD license.
*
* This file is part of the Sandia OpenSHMEM software package. For license
* information, see the LICENSE file in the top level directory of the
* distribution.
*
*/
/*
* MPL_strncpy - Copy at most n characters. Stop once a null is reached.
*
* This is different from strncpy, which null pads so that exactly
* n characters are copied. The strncpy behavior is correct for many
* applications because it guarantees that the string has no uninitialized
* data.
*
* If n characters are copied without reaching a null, return an error.
* Otherwise, return 0.
*
* Question: should we provide a way to request the length of the string,
* since we know it?
*/
/*@ MPL_strncpy - Copy a string with a maximum length
Input Parameters:
+ instr - String to copy
- maxlen - Maximum total length of 'outstr'
Output Parameters:
. outstr - String to copy into
Notes:
This routine is the routine that you wish 'strncpy' was. In copying
'instr' to 'outstr', it stops when either the end of 'outstr' (the
null character) is seen or the maximum length 'maxlen' is reached.
Unlike 'strncpy', it does not add enough nulls to 'outstr' after
copying 'instr' in order to move precisely 'maxlen' characters.
Thus, this routine may be used anywhere 'strcpy' is used, without any
performance cost related to large values of 'maxlen'.
If there is insufficient space in the destination, the destination is
still null-terminated, to avoid potential failures in routines that neglect
to check the error code return from this routine.
Module:
Utility
@*/
static inline int
static inline void
/*@ MPL_strnapp - Append to a string with a maximum length
Input Parameters:
+ instr - String to copy
- maxlen - Maximum total length of 'outstr'
Output Parameters:
. outstr - String to copy into
Notes:
This routine is similar to 'strncat' except that the 'maxlen' argument
is the maximum total length of 'outstr', rather than the maximum
number of characters to move from 'instr'. Thus, this routine is
easier to use when the declared size of 'instr' is known.
Module:
Utility
@*/
static inline int
static inline int
/* MPL_H */