File: secstr.c

package info (click to toggle)
tcpreen 1.4.4-2.1
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,316 kB
  • sloc: sh: 4,324; cpp: 2,142; ansic: 1,870; makefile: 34; sed: 16
file content (56 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * secstr.c - hopefully secure wrappper for string-related functions
 * $Id: secstr.c 151 2004-06-05 15:15:18Z rdenisc $
 */

/***********************************************************************
 *  Copyright (C) 2002-2004 Remi Denis-Courmont.                       *
 *  This program is free software; you can redistribute and/or modify  *
 *  it under the terms of the GNU General Public License as published  *
 *  by the Free Software Foundation; version 2 of the license.         *
 *                                                                     *
 *  This program is distributed in the hope that it will be useful,    *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of     *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               *
 *  See the GNU General Public License for more details.               *
 *                                                                     *
 *  You should have received a copy of the GNU General Public License  *
 *  along with this program; if not, you can get it from:              *
 *  http://www.gnu.org/copyleft/gpl.html                               *
 ***********************************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdarg.h>
#include <stdio.h>
#include <string.h>

#include "secstr.h"

/*
 * Secure wrapper for strncpy()
 */
char *secure_strncpy (char *dest, const char *src, size_t n)
{
	strncpy (dest, src, n);
	dest[n - 1] = 0;
	return dest;
}


/*
 * Secure wrapper for snprintf()
 */
int secure_snprintf (char *buf, size_t len, const char *fmt, ...)
{
	va_list ap;
	int res;

	va_start (ap, fmt);
	res = vsnprintf (buf, len, fmt, ap);
	va_end (ap);

	return res;
}