]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/intrinsics/fget.c
Remove DOS line endings.
[thirdparty/gcc.git] / libgfortran / intrinsics / fget.c
CommitLineData
5d723e54
FXC
1/* Implementation of the FGET, FGETC, FPUT and FPUTC intrinsics.
2 Copyright (C) 2005 Free Software Foundation, Inc.
3 Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
4
5This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7Libgfortran is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public
9License as published by the Free Software Foundation; either
10version 2 of the License, or (at your option) any later version.
11
12In addition to the permissions in the GNU General Public License, the
13Free Software Foundation gives you unlimited permission to link the
14compiled version of this file into combinations with other programs,
15and to distribute those combinations without any restriction coming
16from the use of this file. (The General Public License restrictions
17do apply in other respects; for example, they cover modification of
18the file, and distribution when not linked into a combine
19executable.)
20
21Libgfortran is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public
27License along with libgfortran; see the file COPYING. If not,
28write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29Boston, MA 02110-1301, USA. */
30
31#include "config.h"
32#include "libgfortran.h"
33
34#include <string.h>
35
36#include "../io/io.h"
37
38static const int five = 5;
39static const int six = 6;
40
41extern int PREFIX(fgetc) (const int *, char *, gfc_charlen_type);
42export_proto_np(PREFIX(fgetc));
43
44int
45PREFIX(fgetc) (const int * unit, char * c, gfc_charlen_type c_len)
46{
47 int ret;
48 size_t s;
49 gfc_unit * u = find_unit (*unit);
50
51 if (u == NULL)
52 return -1;
53
54 s = 1;
55 memset (c, ' ', c_len);
56 ret = sread (u->s, c, &s);
401cd90a 57 unlock_unit (u);
5d723e54
FXC
58
59 if (ret != 0)
60 return ret;
61
62 if (s != 1)
63 return -1;
64 else
65 return 0;
66}
67
68
69#define FGETC_SUB(kind) \
70 extern void fgetc_i ## kind ## _sub \
71 (const int *, char *, GFC_INTEGER_ ## kind *, gfc_charlen_type); \
72 export_proto(fgetc_i ## kind ## _sub); \
73 void fgetc_i ## kind ## _sub \
74 (const int * unit, char * c, GFC_INTEGER_ ## kind * st, gfc_charlen_type c_len) \
75 { if (st != NULL) \
76 *st = PREFIX(fgetc) (unit, c, c_len); \
77 else \
78 PREFIX(fgetc) (unit, c, c_len); }
79
80FGETC_SUB(1)
81FGETC_SUB(2)
82FGETC_SUB(4)
83FGETC_SUB(8)
84
85
86extern int PREFIX(fget) (char *, gfc_charlen_type);
87export_proto_np(PREFIX(fget));
88
89int
90PREFIX(fget) (char * c, gfc_charlen_type c_len)
91{
92 return PREFIX(fgetc) (&five, c, c_len);
93}
94
95
96#define FGET_SUB(kind) \
97 extern void fget_i ## kind ## _sub \
98 (char *, GFC_INTEGER_ ## kind *, gfc_charlen_type); \
99 export_proto(fget_i ## kind ## _sub); \
100 void fget_i ## kind ## _sub \
101 (char * c, GFC_INTEGER_ ## kind * st, gfc_charlen_type c_len) \
102 { if (st != NULL) \
103 *st = PREFIX(fgetc) (&five, c, c_len); \
104 else \
105 PREFIX(fgetc) (&five, c, c_len); }
106
107FGET_SUB(1)
108FGET_SUB(2)
109FGET_SUB(4)
110FGET_SUB(8)
111
112
113
114extern int PREFIX(fputc) (const int *, char *, gfc_charlen_type);
115export_proto_np(PREFIX(fputc));
116
117int
118PREFIX(fputc) (const int * unit, char * c,
119 gfc_charlen_type c_len __attribute__((unused)))
120{
121 size_t s;
401cd90a 122 int ret;
5d723e54
FXC
123 gfc_unit * u = find_unit (*unit);
124
125 if (u == NULL)
126 return -1;
127
128 s = 1;
401cd90a
JJ
129 ret = swrite (u->s, c, &s);
130 unlock_unit (u);
131 return ret;
5d723e54
FXC
132}
133
134
135#define FPUTC_SUB(kind) \
136 extern void fputc_i ## kind ## _sub \
137 (const int *, char *, GFC_INTEGER_ ## kind *, gfc_charlen_type); \
138 export_proto(fputc_i ## kind ## _sub); \
139 void fputc_i ## kind ## _sub \
140 (const int * unit, char * c, GFC_INTEGER_ ## kind * st, gfc_charlen_type c_len) \
141 { if (st != NULL) \
142 *st = PREFIX(fputc) (unit, c, c_len); \
143 else \
144 PREFIX(fputc) (unit, c, c_len); }
145
146FPUTC_SUB(1)
147FPUTC_SUB(2)
148FPUTC_SUB(4)
149FPUTC_SUB(8)
150
151
152extern int PREFIX(fput) (char *, gfc_charlen_type);
153export_proto_np(PREFIX(fput));
154
155int
156PREFIX(fput) (char * c, gfc_charlen_type c_len)
157{
158 return PREFIX(fputc) (&six, c, c_len);
159}
160
161
162#define FPUT_SUB(kind) \
163 extern void fput_i ## kind ## _sub \
164 (char *, GFC_INTEGER_ ## kind *, gfc_charlen_type); \
165 export_proto(fput_i ## kind ## _sub); \
166 void fput_i ## kind ## _sub \
167 (char * c, GFC_INTEGER_ ## kind * st, gfc_charlen_type c_len) \
168 { if (st != NULL) \
169 *st = PREFIX(fputc) (&six, c, c_len); \
170 else \
171 PREFIX(fputc) (&six, c, c_len); }
172
173FPUT_SUB(1)
174FPUT_SUB(2)
175FPUT_SUB(4)
176FPUT_SUB(8)
177