Fix prototype (for GTK-DOC).
[libtasn1.git] / lib / gstr.c
blob7946b3ec5624466dd64dfaad5ec1c56b2d3ba2af
1 /*
2 * Copyright (C) 2006 Free Software Foundation
3 * Copyright (C) 2002 Nikos Mavroyanopoulos
5 * This file is part of LIBTASN1.
7 * The LIBTASN1 library is free software; you can redistribute it
8 * and/or modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA
23 #include <int.h>
25 /* These function are like strcat, strcpy. They only
26 * do bounds checking (they shouldn't cause buffer overruns),
27 * and they always produce null terminated strings.
29 * They should be used only with null terminated strings.
31 void _asn1_str_cat( char* dest, size_t dest_tot_size, const char* src) {
32 size_t str_size = strlen(src);
33 size_t dest_size = strlen(dest);
35 if ( dest_tot_size - dest_size > str_size) {
36 strcat( dest, src);
37 } else {
38 if ( dest_tot_size - dest_size > 0) {
39 strncat( dest, src, (dest_tot_size - dest_size) -1);
40 dest[dest_tot_size-1] = 0;
45 void _asn1_str_cpy( char* dest, size_t dest_tot_size, const char* src) {
46 size_t str_size = strlen(src);
48 if ( dest_tot_size > str_size) {
49 strcpy( dest, src);
50 } else {
51 if ( dest_tot_size > 0) {
52 strncpy( dest, src, (dest_tot_size) -1);
53 dest[dest_tot_size-1] = 0;