Add read-file module.
[gnulib.git] / tests / test-read-file.c
1 /*
2  * Copyright (C) 2006 Free Software Foundation
3  * Written by Simon Josefsson
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.  */
19
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
23
24 #include "read-file.h"
25
26 #include <stdio.h>
27
28 #define FILE1 "/etc/resolv.conf"
29 #define FILE2 "/dev/null"
30
31 int
32 main (void)
33 {
34   {
35     size_t len;
36     char *out = read_file (FILE1, &len);
37
38     if (!out)
39       perror ("Could not read file");
40
41     if (out[len] != '\0')
42       perror ("BAD: out[len] not zero");
43
44     printf ("Read %d from %s...\n", len, FILE1);
45
46     free (out);
47   }
48
49   {
50     size_t len;
51     char *out = read_file (FILE2, &len);
52
53     if (!out)
54       perror ("Could not read file");
55
56     if (out[len] != '\0')
57       perror ("BAD: out[len] not zero");
58
59     printf ("Read %d from %s...\n", len, FILE2);
60
61     free (out);
62   }
63
64   return 0;
65 }