Fix use of deprecated types, for now and the future.
[gnutls.git] / lib / minitasn1 / gstr.c
blob9c0835120bb44fc8f03619d004307298f077ce4e
1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009 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>
24 #include "gstr.h"
26 /* These function are like strcat, strcpy. They only
27 * do bounds checking (they shouldn't cause buffer overruns),
28 * and they always produce null terminated strings.
30 * They should be used only with null terminated strings.
32 void
33 _asn1_str_cat (char *dest, size_t dest_tot_size, const char *src)
35 size_t str_size = strlen (src);
36 size_t dest_size = strlen (dest);
38 if (dest_tot_size - dest_size > str_size)
40 strcat (dest, src);
42 else
44 if (dest_tot_size - dest_size > 0)
46 strncat (dest, src, (dest_tot_size - dest_size) - 1);
47 dest[dest_tot_size - 1] = 0;
52 void
53 _asn1_str_cpy (char *dest, size_t dest_tot_size, const char *src)
55 size_t str_size = strlen (src);
57 if (dest_tot_size > str_size)
59 strcpy (dest, src);
61 else
63 if (dest_tot_size > 0)
65 strncpy (dest, src, (dest_tot_size) - 1);
66 dest[dest_tot_size - 1] = 0;