File: stdio_test.c

package info (click to toggle)
libsndfile0 0.0.28-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,336 kB
  • ctags: 1,743
  • sloc: ansic: 20,393; sh: 8,823; makefile: 210; cpp: 188; python: 47
file content (95 lines) | stat: -rw-r--r-- 2,658 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
** Copyright (C) 2001 Erik de Castro Lopo <erikd@zip.com.au>
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** 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, write to the Free Software 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

/*========================================================================== 
** This is a test program which tests reading from stdin and writing to 
** stdout. At the moment these features only work for file redirects at the
** shell. Pipes do not currently work but will be fixed In The Future (tm).
*/



#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<unistd.h>
#include	<sys/types.h>
#include	<sys/stat.h>

#define		SAMPLE_COUNT		12345

static size_t	file_length (char *filename) ;
static int		file_exists (char *filename) ;

static char *filetypes [] =
{	"wav", "aiff", "au", "paf", "svx", "nist", "ircam", NULL
} ; 

int
main (void)
{	static char buffer [256] ;
	int k, file_size, retval ;
	
	if (! file_exists ("libsndfile.spc.in"))
		chdir ("tests") ;
		
	for (k = 0 ; filetypes [k] ; k++)
	{	snprintf (buffer, sizeof (buffer), "./stdout_test %s %d > stdio.%s", filetypes [k], SAMPLE_COUNT, filetypes [k]) ;
		if ((retval = system (buffer)))
			exit (retval) ;
		
		snprintf (buffer, sizeof (buffer), "stdio.%s", filetypes [k]) ;
		if ((file_size = file_length (buffer)) < SAMPLE_COUNT)
		{	printf ("\n    Error : test file '%s' too small (%d).\n\n", buffer, file_size) ;
			exit (1) ;
			} ;
		
		snprintf (buffer, sizeof (buffer), "./stdin_test %s %d < stdio.%s", filetypes [k], SAMPLE_COUNT, filetypes [k]) ;
		if ((retval = system (buffer)))
			exit (retval) ;

		snprintf (buffer, sizeof (buffer), "rm stdio.%s", filetypes [k]) ;
		if ((retval = system (buffer)))
			exit (retval) ;

		} ;

	return 0;
} /* main */

static size_t	
file_length (char *filename)
{	struct stat buf ;

	if (stat (filename, &buf))
	{	perror (filename) ;
		exit (1) ;
		} ;

	return buf.st_size ;
} /* file_length */

static int
file_exists (char *filename)
{	struct stat buf ;

	if (stat (filename, &buf))
		return 0 ;
		
	return 1 ;
} /* file_exists */