1b815c7f3Sopenharmony_ci/*
2b815c7f3Sopenharmony_ci** Copyright (C) 2010-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
3b815c7f3Sopenharmony_ci**
4b815c7f3Sopenharmony_ci** This program is free software; you can redistribute it and/or modify
5b815c7f3Sopenharmony_ci** it under the terms of the GNU Lesser General Public License as published by
6b815c7f3Sopenharmony_ci** the Free Software Foundation; either version 2.1 of the License, or
7b815c7f3Sopenharmony_ci** (at your option) any later version.
8b815c7f3Sopenharmony_ci**
9b815c7f3Sopenharmony_ci** This program is distributed in the hope that it will be useful,
10b815c7f3Sopenharmony_ci** but WITHOUT ANY WARRANTY; without even the implied warranty of
11b815c7f3Sopenharmony_ci** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12b815c7f3Sopenharmony_ci** GNU Lesser General Public License for more details.
13b815c7f3Sopenharmony_ci**
14b815c7f3Sopenharmony_ci** You should have received a copy of the GNU Lesser General Public License
15b815c7f3Sopenharmony_ci** along with this program; if not, write to the Free Software
16b815c7f3Sopenharmony_ci** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17b815c7f3Sopenharmony_ci*/
18b815c7f3Sopenharmony_ci
19b815c7f3Sopenharmony_ci#include "sfconfig.h"
20b815c7f3Sopenharmony_ci
21b815c7f3Sopenharmony_ci#include <stdio.h>
22b815c7f3Sopenharmony_ci#include <stdlib.h>
23b815c7f3Sopenharmony_ci
24b815c7f3Sopenharmony_ci#include "common.h"
25b815c7f3Sopenharmony_ci
26b815c7f3Sopenharmony_ci#include "test_main.h"
27b815c7f3Sopenharmony_ci
28b815c7f3Sopenharmony_civoid
29b815c7f3Sopenharmony_citest_psf_strlcpy_crlf (void)
30b815c7f3Sopenharmony_ci{	const char *src = "a\nb\nc\n" ;
31b815c7f3Sopenharmony_ci	char *dest ;
32b815c7f3Sopenharmony_ci	int dest_len ;
33b815c7f3Sopenharmony_ci
34b815c7f3Sopenharmony_ci	print_test_name ("Testing psf_strlcpy_crlf") ;
35b815c7f3Sopenharmony_ci
36b815c7f3Sopenharmony_ci	for (dest_len = 3 ; dest_len < 30 ; dest_len++)
37b815c7f3Sopenharmony_ci	{	dest = calloc (1, dest_len + 1) ;
38b815c7f3Sopenharmony_ci		if (dest == NULL)
39b815c7f3Sopenharmony_ci		{	printf ("\n\nLine %d: calloc failed!\n\n", __LINE__) ;
40b815c7f3Sopenharmony_ci			exit (1) ;
41b815c7f3Sopenharmony_ci			} ;
42b815c7f3Sopenharmony_ci
43b815c7f3Sopenharmony_ci		/* This value needs to be a in the [0, 127] range to avoid tripping up
44b815c7f3Sopenharmony_ci		** compiles like Sun Studio 12.*
45b815c7f3Sopenharmony_ci		*/
46b815c7f3Sopenharmony_ci		dest [dest_len] = '\x5a' ;
47b815c7f3Sopenharmony_ci
48b815c7f3Sopenharmony_ci		psf_strlcpy_crlf (dest, src, dest_len, sizeof (*src)) ;
49b815c7f3Sopenharmony_ci
50b815c7f3Sopenharmony_ci		if (dest [dest_len] != '\x5a')
51b815c7f3Sopenharmony_ci		{	printf ("\n\nLine %d: buffer overrun for dest_len == %d\n\n", __LINE__, dest_len) ;
52b815c7f3Sopenharmony_ci			exit (1) ;
53b815c7f3Sopenharmony_ci			} ;
54b815c7f3Sopenharmony_ci
55b815c7f3Sopenharmony_ci		free (dest) ;
56b815c7f3Sopenharmony_ci		} ;
57b815c7f3Sopenharmony_ci
58b815c7f3Sopenharmony_ci	puts ("ok") ;
59b815c7f3Sopenharmony_ci} /* test_psf_strlcpy_crlf */
60