Sourcecode and documentation for libtasn1-2 version 0.2.10-3sarge1
show bar | Show file versions
Search packages:
| Sourcecode archive home

gstr.c

00001 /*
00002  *      Copyright (C) 2002 Nikos Mavroyanopoulos
00003  *
00004  * This file is part of LIBASN1.
00005  *
00006  * The LIBTASN1 library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public   
00008  * License as published by the Free Software Foundation; either 
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00019  */
00020 
00021 #include <int.h>
00022 
00023 /* These function are like strcat, strcpy. They only
00024  * do bound checking (they shouldn't cause buffer overruns),
00025  * and they always produce null terminated strings.
00026  *
00027  * They should be used only with null terminated strings.
00028  */
00029 void _asn1_str_cat( char* dest, size_t dest_tot_size, const char* src) {
00030 size_t str_size = strlen(src);
00031 size_t dest_size = strlen(dest);
00032 
00033       if ( dest_tot_size - dest_size > str_size) {
00034             strcat( dest, src);
00035       } else {
00036             if ( dest_tot_size - dest_size > 0) {
00037                   strncat( dest, src, (dest_tot_size - dest_size) -1);
00038                   dest[dest_tot_size-1] = 0;
00039             }
00040       }
00041 }
00042 
00043 void _asn1_str_cpy( char* dest, size_t dest_tot_size, const char* src) {
00044 size_t str_size = strlen(src);
00045 
00046       if ( dest_tot_size > str_size) {
00047             strcpy( dest, src);
00048       } else {
00049             if ( dest_tot_size > 0) {
00050                   strncpy( dest, src, (dest_tot_size) -1);
00051                   dest[dest_tot_size-1] = 0;
00052             }
00053       }
00054 }
00055 
00056 void _asn1_mem_cpy( char* dest, size_t dest_tot_size, const char* src, size_t src_size) 
00057 {
00058 
00059       if ( dest_tot_size >= src_size) {
00060             memcpy( dest, src, src_size);
00061       } else {
00062             if ( dest_tot_size > 0) {
00063                   memcpy( dest, src, dest_tot_size);
00064             }
00065       }
00066 }
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 

Generated by  Doxygen 1.5.1