2 * Copyright (C) 2002-2012 Free Software Foundation, Inc.
4 * This file is part of LIBTASN1.
6 * The LIBTASN1 library is free software; you can redistribute it
7 * and/or modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
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.
32 _asn1_str_cat (char *dest
, size_t dest_tot_size
, const char *src
)
34 size_t str_size
= strlen (src
);
35 size_t dest_size
= strlen (dest
);
37 if (dest_tot_size
- dest_size
> str_size
)
43 if (dest_tot_size
- dest_size
> 0)
45 strncat (dest
, src
, (dest_tot_size
- dest_size
) - 1);
46 dest
[dest_tot_size
- 1] = 0;
52 _asn1_str_cpy (char *dest
, size_t dest_tot_size
, const char *src
)
54 size_t str_size
= strlen (src
);
56 if (dest_tot_size
> str_size
)
62 if (dest_tot_size
> 0)
64 strncpy (dest
, src
, (dest_tot_size
) - 1);
65 dest
[dest_tot_size
- 1] = 0;