u8-istream: New library for reading a text file and recoding to UTF-8.
[pspp-builds.git] / src / libpspp / u8-istream.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2010, 2011 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef LIBPSPP_U8_ISTREAM_H
18 #define LIBPSPP_U8_ISTREAM_H 1
19
20 #include <sys/types.h>
21 #include <stdbool.h>
22
23 /* u8_istream.
24
25    Reads a text file and reencodes its contents into UTF-8, with optional
26    automatic encoding detection.
27 */
28
29 #define U8_ISTREAM_BUFFER_SIZE 4096
30
31 struct u8_istream *u8_istream_for_fd (const char *fromcode, int fd);
32 struct u8_istream *u8_istream_for_file (const char *fromcode,
33                                         const char *filename, int flags);
34
35 int u8_istream_close (struct u8_istream *);
36 void u8_istream_free (struct u8_istream *);
37
38 ssize_t u8_istream_read (struct u8_istream *, char *, size_t);
39
40 int u8_istream_fileno (const struct u8_istream *);
41
42 bool u8_istream_is_auto (const struct u8_istream *);
43 bool u8_istream_is_utf8 (const struct u8_istream *);
44
45 #endif /* libpspp/u8-istream.h */