2004-01-07 18:21:25 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2015-06-24 06:59:57 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
2004-11-28 23:09:25 +03:00
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
2004-11-22 04:38:40 +03:00
|
|
|
* Additional copyrights may follow
|
2015-06-24 06:59:57 +03:00
|
|
|
*
|
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).
|
|
|
|
*/
|
|
|
|
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal_config.h"
|
2004-01-07 18:21:25 +03:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-07-04 06:38:44 +04:00
|
|
|
#include "opal/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 *
|
2005-07-04 06:38:44 +04:00
|
|
|
opal_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;
|
|
|
|
}
|