1/////////////////////////////////////////////////////////////////////////// 2// 3// Copyright (c) 2000-2003 Intel Corporation 4// All rights reserved. 5// 6// Redistribution and use in source and binary forms, with or without 7// modification, are permitted provided that the following conditions are met: 8// 9// * Redistributions of source code must retain the above copyright notice, 10// this list of conditions and the following disclaimer. 11// * Redistributions in binary form must reproduce the above copyright notice, 12// this list of conditions and the following disclaimer in the documentation 13// and/or other materials provided with the distribution. 14// * Neither name of Intel Corporation nor the names of its contributors 15// may be used to endorse or promote products derived from this software 16// without specific prior written permission. 17// 18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 22// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 25// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 26// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 27// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29// 30/////////////////////////////////////////////////////////////////////////// 31 32/************************************************************************ 33* Purpose: This file contains functions for copying strings based on 34* different options. 35************************************************************************/ 36 37#include "upnp.h" 38#include "util.h" 39 40/************************************************************************ 41* Function : linecopy 42* 43* Parameters : 44* OUT char dest[LINE_SIZE] ; output buffer 45* IN const char* src ; input buffer 46* 47* Description : Copy no of bytes spcified by the LINE_SIZE constant, 48* from the source buffer. Null terminate the destination buffer 49* 50* Return : void ; 51* 52* Note : 53************************************************************************/ 54void 55linecopy( OUT char dest[LINE_SIZE], 56 IN const char *src ) 57{ 58 strncpy( dest, src, LINE_SIZE - 1 ); 59 dest[LINE_SIZE - 1] = '\0'; // null-terminate if len(src) >= LINE_SIZE 60} 61 62/************************************************************************ 63* Function : namecopy 64* 65* Parameters : 66* OUT char dest[NAME_SIZE] ; output buffer 67* IN const char* src ; input buffer 68* 69* Description : Copy no of bytes spcified by the NAME_SIZE constant, 70* from the source buffer. Null terminate the destination buffer 71* 72* Return : void ; 73* 74* Note : 75************************************************************************/ 76void 77namecopy( OUT char dest[NAME_SIZE], 78 IN const char *src ) 79{ 80 strncpy( dest, src, NAME_SIZE - 1 ); 81 dest[NAME_SIZE - 1] = '\0'; // null-terminate if len(src) >= NAME_SIZE 82} 83 84/************************************************************************ 85* Function : linecopylen 86* 87* Parameters : 88* OUT char dest[LINE_SIZE] ; output buffer 89* IN const char* src ; input buffer 90* IN size_t srclen ; bytes to be copied. 91* 92* Description : Determine if the srclen passed in paramter is less than 93* the permitted LINE_SIZE. If it is use the passed parameter, if not 94* use the permitted LINE_SIZE as the length parameter 95* Copy no of bytes spcified by the LINE_SIZE constant, 96* from the source buffer. Null terminate the destination buffer 97* 98* Return : void ; 99* 100* Note : 101************************************************************************/ 102void 103linecopylen( OUT char dest[LINE_SIZE], 104 IN const char *src, 105 IN size_t srclen ) 106{ 107 int len; 108 109 len = srclen < ( LINE_SIZE - 1 ) ? srclen : ( LINE_SIZE - 1 ); 110 strncpy( dest, src, len ); 111 dest[len] = '\0'; 112} 113