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
|
/*
* 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.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
* This file is only here because some platforms have a broken strncpy
* (e.g., Itanium with RedHat Advanced Server glibc).
*/
#include "opal_config.h"
#include <string.h>
#include "opal/util/strncpy.h"
/**
* 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 *
opal_strncpy(char *dest, const char *src, size_t len)
{
size_t i;
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;
}
|