EPICS ARCHIVER V4
Main Page
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
trunk
ea4-cpp
include
common
tools
string2cp.h
1
#ifndef __STRING_TO_CP__
2
#define __STRING_TO_CP__
3
4
#include <cstring>
5
6
#include "tools/ToolsConfig.h"
7
#include "tools/MsgLogger.h"
8
9
// Safely (i.e. w/o overruns and '\0'-limited)
10
// copy a std-string into a char [].
11
//
12
// string::copy isn't available on all platforms, so strncpy is used.
13
inline
void
string2cp(
char
*dest,
const
stdString &src,
size_t
maxlen)
14
{
15
if
(src.length() >= maxlen)
16
{
17
LOG_MSG(
"string2cp: Truncating '%s' to %zu chars.\n"
,
18
src.c_str(), maxlen);
19
strncpy(dest, src.c_str(), maxlen);
20
dest[maxlen-1] =
'\0'
;
21
}
22
else
23
strncpy(dest, src.c_str(), maxlen);
24
}
25
26
#endif
Generated on Tue Dec 17 2013 11:07:27 for EPICS ARCHIVER V4 by
1.8.5