2004-01-07 18:21:25 +03:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*
|
|
|
|
* This file is only here because some platforms have a broken strncpy
|
|
|
|
* (e.g., Itanium with RedHat Advanced Server glibc).
|
|
|
|
*/
|
|
|
|
|
2004-10-06 19:24:48 +04:00
|
|
|
#include "ompi_config.h"
|
2004-01-07 18:21:25 +03:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "util/strncpy.h"
|
2004-01-07 18:21:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide a portable, working strncpy() for platforms that have
|
|
|
|
* broken implementations.
|
|
|
|
*
|
|
|
|
* @param dest Destination string.
|
|
|
|
* @param src Source string.
|
|
|
|
* @param len Length of the string to copy.
|
|
|
|
*
|
|
|
|
* @return The value dest.
|
|
|
|
*
|
|
|
|
* This function is identical in behavior to strncpy(), but is not
|
|
|
|
* optimized at all (we're not concerned with high-performance
|
|
|
|
* strncpy!). It is only here because some platforms have broken
|
|
|
|
* implementations of strncpy() that cause segfaults (cough cough Red
|
|
|
|
* Hat Advanced Server glibc cough cough).
|
|
|
|
*/
|
|
|
|
char *
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_strncpy(char *dest, const char *src, size_t len)
|
2004-01-07 18:21:25 +03:00
|
|
|
{
|
2004-10-18 19:38:19 +04:00
|
|
|
size_t i;
|
2004-01-07 18:21:25 +03:00
|
|
|
int pad = 0;
|
|
|
|
char *new_dest = dest;
|
|
|
|
|
|
|
|
for (i = 0; i < len; ++i, ++src, ++new_dest) {
|
|
|
|
if (pad != 0)
|
|
|
|
*new_dest = '\0';
|
|
|
|
else {
|
|
|
|
*new_dest = *src;
|
|
|
|
if ('\0' == *src)
|
|
|
|
pad = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|