1 /* classes: h_files */
2 
3 #ifndef SCM_FPORTS_H
4 #define SCM_FPORTS_H
5 
6 /* Copyright (C) 1995-2001, 2006, 2008, 2009, 2011, 2012,
7  *   2017 Free Software Foundation, Inc.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 3 of
12  * the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  */
24 
25 
26 
27 #include "libguile/__scm.h"
28 
29 #include "libguile/ports.h"
30 
31 
32 
33 /* struct allocated for each buffered FPORT.  */
34 typedef struct scm_t_fport {
35   /* The file descriptor.  */
36   int fdes;
37   /* Revealed count; 0 indicates not revealed, > 1 revealed.  */
38   unsigned int revealed;
39   /* Set of scm_fport_option flags.  */
40   unsigned options;
41 } scm_t_fport;
42 
43 SCM_API scm_t_port_type *scm_file_port_type;
44 
45 #define SCM_FSTREAM(x) ((scm_t_fport *) SCM_STREAM (x))
46 #define SCM_FPORT_FDES(x) (SCM_FSTREAM (x)->fdes)
47 
48 #define SCM_FPORTP(x) \
49   (SCM_PORTP (x) && SCM_PORT_TYPE (x) == scm_file_port_type)
50 #define SCM_OPFPORTP(x) (SCM_FPORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_OPN))
51 #define SCM_OPINFPORTP(x) (SCM_OPFPORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_RDNG))
52 #define SCM_OPOUTFPORTP(x) (SCM_OPFPORTP (x) && (SCM_CELL_WORD_0 (x) & SCM_WRTNG))
53 
54 
55 SCM_API void scm_evict_ports (int fd);
56 SCM_INTERNAL int scm_i_mode_to_open_flags (SCM mode, int *is_binary,
57                                            const char *FUNC_NAME);
58 SCM_API SCM scm_open_file_with_encoding (SCM filename, SCM modes,
59                                          SCM guess_encoding, SCM encoding);
60 SCM_API SCM scm_open_file (SCM filename, SCM modes);
61 SCM_API SCM scm_fdes_to_port (int fdes, char *mode, SCM name);
62 SCM_API SCM scm_file_port_p (SCM obj);
63 
64 
65 /* Revealed counts.  */
66 SCM_API int scm_revealed_count (SCM port);
67 SCM_API SCM scm_port_revealed (SCM port);
68 SCM_API SCM scm_set_port_revealed_x (SCM port, SCM rcount);
69 SCM_API SCM scm_adjust_port_revealed_x (SCM port, SCM addend);
70 
71 
72 SCM_INTERNAL void scm_init_fports_keywords (void);
73 SCM_INTERNAL void scm_init_fports (void);
74 
75 /* internal functions */
76 
77 #ifdef BUILDING_LIBGUILE
78 enum scm_fport_option
79   {
80     /* FD's that aren't created by Guile probably need to be checked for
81        validity.  We also check that the open mode is valid.  */
82     SCM_FPORT_OPTION_VERIFY = 1U<<0,
83     /* We know some ports aren't seekable and can elide a syscall in
84        that case.  */
85     SCM_FPORT_OPTION_NOT_SEEKABLE = 1U<<1
86   };
87 SCM_INTERNAL SCM scm_i_fdes_to_port (int fdes, long mode_bits, SCM name,
88                                      unsigned options);
89 #endif /* BUILDING_LIBGUILE */
90 
91 #endif  /* SCM_FPORTS_H */
92 
93 /*
94   Local Variables:
95   c-file-style: "gnu"
96   End:
97 */
98