PR c/79855: add full stop to store merging param descriptions
[official-gcc.git] / gcc / ada / cstreams.c
blobf0f826685b87b904df0b04cb982b9fa45c6e6e93
1 /****************************************************************************
2 * *
3 * GNAT RUN-TIME COMPONENTS *
4 * *
5 * C S T R E A M S *
6 * *
7 * Auxiliary C functions for Interfaces.C.Streams *
8 * *
9 * Copyright (C) 1992-2015, Free Software Foundation, Inc. *
10 * *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 3, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. *
17 * *
18 * As a special exception under Section 7 of GPL version 3, you are granted *
19 * additional permissions described in the GCC Runtime Library Exception, *
20 * version 3.1, as published by the Free Software Foundation. *
21 * *
22 * You should have received a copy of the GNU General Public License and *
23 * a copy of the GCC Runtime Library Exception along with this program; *
24 * see the files COPYING3 and COPYING.RUNTIME respectively. If not, see *
25 * <http://www.gnu.org/licenses/>. *
26 * *
27 * GNAT was originally developed by the GNAT team at New York University. *
28 * Extensive contributions were provided by Ada Core Technologies Inc. *
29 * *
30 ****************************************************************************/
32 /* Routines required for implementing routines in Interfaces.C.Streams. */
34 #ifndef _LARGEFILE_SOURCE
35 #define _LARGEFILE_SOURCE
36 #endif
37 #define _FILE_OFFSET_BITS 64
38 /* the define above will make off_t a 64bit type on GNU/Linux */
40 #include <stdio.h>
41 #include <sys/types.h>
42 #include <sys/stat.h>
43 #include <unistd.h>
45 #ifdef _AIX
46 /* needed to avoid conflicting declarations */
47 #include <unistd.h>
48 #include <sys/mman.h>
49 #endif
51 #ifdef __vxworks
52 #include "vxWorks.h"
53 #endif
55 #ifdef IN_RTS
56 #include "tconfig.h"
57 #include "tsystem.h"
58 #include <sys/stat.h>
59 #else
60 #include "config.h"
61 #include "system.h"
62 #endif
64 #include "adaint.h"
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
70 #ifdef VMS
71 #include <unixlib.h>
72 #endif
74 #ifdef __linux__
75 /* Don't use macros on GNU/Linux since they cause incompatible changes between
76 glibc 2.0 and 2.1 */
78 #ifdef stderr
79 # undef stderr
80 #endif
81 #ifdef stdin
82 # undef stdin
83 #endif
84 #ifdef stdout
85 # undef stdout
86 #endif
88 #endif
90 /* Don't use macros versions of this functions on VxWorks since they cause
91 imcompatible changes in some VxWorks versions */
92 #ifdef __vxworks
93 #undef getchar
94 #undef putchar
95 #undef feof
96 #undef ferror
97 #undef fileno
98 #endif
100 /* The _IONBF value in MINGW32 stdio.h is wrong. */
101 #if defined (WINNT) || defined (_WINNT)
102 #if OLD_MINGW
103 #undef _IONBF
104 #define _IONBF 0004
105 #endif
106 #endif
109 __gnat_feof (FILE *stream)
111 return (feof (stream));
115 __gnat_ferror (FILE *stream)
117 return (ferror (stream));
121 __gnat_fileno (FILE *stream)
123 return (fileno (stream));
126 /* on some systems, the constants for seek are not defined, if so, then
127 provide the conventional definitions */
129 #ifndef SEEK_SET
130 #define SEEK_SET 0 /* Set file pointer to offset */
131 #define SEEK_CUR 1 /* Set file pointer to its current value plus offset */
132 #define SEEK_END 2 /* Set file pointer to the size of the file plus offset */
133 #endif
135 /* if L_tmpnam is not set, use a large number that should be safe */
136 #ifndef L_tmpnam
137 #define L_tmpnam 256
138 #endif
140 int __gnat_constant_eof = EOF;
141 int __gnat_constant_iofbf = _IOFBF;
142 int __gnat_constant_iolbf = _IOLBF;
143 int __gnat_constant_ionbf = _IONBF;
144 int __gnat_constant_l_tmpnam = L_tmpnam;
145 int __gnat_constant_seek_cur = SEEK_CUR;
146 int __gnat_constant_seek_end = SEEK_END;
147 int __gnat_constant_seek_set = SEEK_SET;
149 FILE *
150 __gnat_constant_stderr (void)
152 return stderr;
155 FILE *
156 __gnat_constant_stdin (void)
158 return stdin;
161 FILE *
162 __gnat_constant_stdout (void)
164 return stdout;
167 char *
168 __gnat_full_name (char *nam, char *buffer)
170 #ifdef RTSS
171 /* RTSS applications have no current-directory notion, so RTSS file I/O
172 requests must use fully qualified path names, such as:
173 c:\temp\MyFile.txt (for a file system object)
174 \\.\MyDevice0 (for a device object)
176 if (nam[1] == ':' || nam[0] == '\\')
177 strcpy (buffer, nam);
178 else
179 buffer[0] = '\0';
181 #elif defined (__MINGW32__)
182 /* If this is a device file return it as is;
183 under Windows NT a device file ends with ":". */
184 if (nam[strlen (nam) - 1] == ':')
185 strcpy (buffer, nam);
186 else
188 char *p;
190 _fullpath (buffer, nam, __gnat_max_path_len);
192 for (p = buffer; *p; p++)
193 if (*p == '/')
194 *p = '\\';
197 #elif defined (__FreeBSD__) || defined (__DragonFly__) || defined (__OpenBSD__)
199 /* Use realpath function which resolves links and references to . and ..
200 on those Unix systems that support it. Note that GNU/Linux provides it but
201 cannot handle more than 5 symbolic links in a full name, so we use the
202 getcwd approach instead. */
203 realpath (nam, buffer);
205 #elif defined (VMS)
206 strncpy (buffer, __gnat_to_canonical_file_spec (nam), __gnat_max_path_len);
208 if (buffer[0] == '/' || strchr (buffer, '!')) /* '!' means decnet node */
209 strncpy (buffer, __gnat_to_host_file_spec (buffer), __gnat_max_path_len);
210 else
212 char *nambuffer = alloca (__gnat_max_path_len);
214 strncpy (nambuffer, buffer, __gnat_max_path_len);
215 strncpy
216 (buffer, getcwd (buffer, __gnat_max_path_len, 0), __gnat_max_path_len);
217 strncat (buffer, "/", __gnat_max_path_len);
218 strncat (buffer, nambuffer, __gnat_max_path_len);
219 strncpy (buffer, __gnat_to_host_file_spec (buffer), __gnat_max_path_len);
222 #elif defined (__vxworks)
224 /* On VxWorks systems, an absolute path can be represented (depending on
225 the host platform) as either /dir/file, or device:/dir/file, or
226 device:drive_letter:/dir/file. Use the __gnat_is_absolute_path
227 to verify it. */
229 int length;
231 if (__gnat_is_absolute_path (nam, strlen (nam)))
232 strcpy (buffer, nam);
234 else
236 length = __gnat_max_path_len;
237 __gnat_get_current_dir (buffer, &length);
238 strncat (buffer, nam, __gnat_max_path_len - length - 1);
241 #else
242 if (nam[0] != '/')
244 char *p = getcwd (buffer, __gnat_max_path_len);
246 if (p == 0)
248 buffer[0] = '\0';
249 return 0;
253 /* If the name returned is an absolute path, it is safe to append '/'
254 to the path and concatenate the name of the file. */
255 if (buffer[0] == '/')
256 strcat (buffer, "/");
258 strcat (buffer, nam);
260 else
261 strcpy (buffer, nam);
262 #endif
264 return buffer;
267 #ifdef _WIN32
268 /* On Windows we want to use the fseek/fteel supporting large files. This
269 issue is due to the fact that a long on Win64 is still a 32 bits value */
270 __int64
271 __gnat_ftell64 (FILE *stream)
273 return _ftelli64 (stream);
277 __gnat_fseek64 (FILE *stream, __int64 offset, int origin)
279 return _fseeki64 (stream, offset, origin);
282 #elif defined (__linux__) || defined (__sun__) || defined (__FreeBSD__) \
283 || defined (__APPLE__)
284 /* section for platforms having ftello/fseeko */
286 __int64
287 __gnat_ftell64 (FILE *stream)
289 return (__int64)ftello (stream);
293 __gnat_fseek64 (FILE *stream, __int64 offset, int origin)
295 /* make sure that the offset is not bigger than the OS off_t, if so return
296 with error as this mean that we are trying to handle files larger than
297 2Gb on a patform not supporting it. */
298 if ((off_t)offset == offset)
299 return fseeko (stream, (off_t) offset, origin);
300 else
301 return -1;
304 #else
306 __int64
307 __gnat_ftell64 (FILE *stream)
309 return (__int64)ftell (stream);
313 __gnat_fseek64 (FILE *stream, __int64 offset, int origin)
315 /* make sure that the offset is not bigger than the OS off_t, if so return
316 with error as this mean that we are trying to handle files larger than
317 2Gb on a patform not supporting it. */
318 if ((off_t)offset == offset)
319 return fseek (stream, (off_t) offset, origin);
320 else
321 return -1;
323 #endif
325 /* Returns true if the path names a fifo (i.e. a named pipe). */
327 __gnat_is_fifo (const char* path)
329 /* Posix defines S_ISFIFO as a macro. If the macro doesn't exist, we return
330 false. */
331 #ifdef S_ISFIFO
332 struct stat buf;
333 const int status = stat(path, &buf);
334 if (status == 0)
335 return S_ISFIFO(buf.st_mode);
336 #endif
338 /* S_ISFIFO is not available, or stat got an error (probably
339 file not found). */
340 return 0;
343 #ifdef __cplusplus
345 #endif