OSDN Git Service

* sem_ch3.adb (Find_Type_Of_Subtype_Indic): If subtype indication
[pf3gnuchains/gcc-fork.git] / gcc / ada / cstreams.c
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  *                              $Revision$
10  *                                                                          *
11  *          Copyright (C) 1992-2001 Free Software Foundation, Inc.          *
12  *                                                                          *
13  * GNAT is free software;  you can  redistribute it  and/or modify it under *
14  * terms of the  GNU General Public License as published  by the Free Soft- *
15  * ware  Foundation;  either version 2,  or (at your option) any later ver- *
16  * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
17  * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
18  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License *
19  * for  more details.  You should have  received  a copy of the GNU General *
20  * Public License  distributed with GNAT;  see file COPYING.  If not, write *
21  * to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, *
22  * MA 02111-1307, USA.                                                      *
23  *                                                                          *
24  * As a  special  exception,  if you  link  this file  with other  files to *
25  * produce an executable,  this file does not by itself cause the resulting *
26  * executable to be covered by the GNU General Public License. This except- *
27  * ion does not  however invalidate  any other reasons  why the  executable *
28  * file might be covered by the  GNU Public License.                        *
29  *                                                                          *
30  * GNAT was originally developed  by the GNAT team at  New York University. *
31  * It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). *
32  *                                                                          *
33  ****************************************************************************/
34
35 /* Routines required for implementing routines in Interfaces.C.Streams */
36
37 #ifdef __vxworks
38 #include "vxWorks.h"
39 #endif
40
41 #ifdef IN_RTS
42 #include "tconfig.h"
43 #include "tsystem.h"
44 #include <sys/stat.h>
45 #else
46 #include "config.h"
47 #include "system.h"
48 #endif
49
50 #include "adaint.h"
51
52 #ifdef __EMX__
53 int max_path_len = _MAX_PATH;
54 #elif defined (VMS)
55 #include <unixlib.h>
56 int max_path_len = 255; /* PATH_MAX */
57
58 #elif defined (__vxworks) || defined (__OPENNT)
59
60 int max_path_len = PATH_MAX;
61
62 #else
63
64 #ifdef linux
65
66 /* Don't use macros on GNU/Linux since they cause incompatible changes between
67    glibc 2.0 and 2.1 */
68
69 #ifdef stderr
70 #  undef stderr
71 #endif
72 #ifdef stdin
73 #  undef stdin
74 #endif
75 #ifdef stdout
76 #  undef stdout
77 #endif
78
79 #endif
80
81 #include <sys/param.h>
82
83 int max_path_len = MAXPATHLEN;
84 #endif
85
86 /* The _IONBF value in CYGNUS or MINGW32 stdio.h is wrong.  */
87 #if defined (WINNT) || defined (_WINNT)
88 #undef _IONBF
89 #define _IONBF 0004
90 #endif
91
92
93 int
94 __gnat_feof (stream)
95      FILE *stream;
96 {
97   return (feof (stream));
98 }
99
100 int
101 __gnat_ferror (stream)
102      FILE *stream;
103 {
104    return (ferror (stream));
105 }
106
107 int
108 __gnat_fileno (stream)
109      FILE *stream;
110 {
111    return (fileno (stream));
112 }
113
114 int
115 __gnat_is_regular_file_fd (fd)
116      int fd;
117 {
118   int ret;
119   struct stat statbuf;
120
121 #ifdef __EMX__
122   /* Programs using screen I/O may need to reset the FPU after
123      initialization of screen-handling related DLL's, so force
124      DLL initialization by doing a null-write and then reset the FPU */
125
126   DosWrite (0, &ret, 0, &ret);
127   __gnat_init_float();
128 #endif
129
130   ret = fstat (fd, &statbuf);
131   return (!ret && S_ISREG (statbuf.st_mode));
132 }
133
134 /* on some systems, the constants for seek are not defined, if so, then
135    provide the conventional definitions */
136
137 #ifndef SEEK_SET
138 #define SEEK_SET 0  /* Set file pointer to offset                           */
139 #define SEEK_CUR 1  /* Set file pointer to its current value plus offset    */
140 #define SEEK_END 2  /* Set file pointer to the size of the file plus offset */
141 #endif
142
143 /* if L_tmpnam is not set, use a large number that should be safe */
144 #ifndef L_tmpnam
145 #define L_tmpnam 256
146 #endif
147
148 int    __gnat_constant_eof      = EOF;
149 int    __gnat_constant_iofbf    = _IOFBF;
150 int    __gnat_constant_iolbf    = _IOLBF;
151 int    __gnat_constant_ionbf    = _IONBF;
152 int    __gnat_constant_l_tmpnam = L_tmpnam;
153 int    __gnat_constant_seek_cur = SEEK_CUR;
154 int    __gnat_constant_seek_end = SEEK_END;
155 int    __gnat_constant_seek_set = SEEK_SET;
156
157 FILE *
158 __gnat_constant_stderr ()
159 {
160   return stderr;
161 }
162
163 FILE *
164 __gnat_constant_stdin ()
165 {
166   return stdin;
167 }
168
169 FILE *
170 __gnat_constant_stdout ()
171 {
172   return stdout;
173 }
174
175 char *
176 __gnat_full_name (nam, buffer)
177      char *nam;
178      char *buffer;
179 {
180   char *p;
181
182 #if defined(__EMX__) || defined (__MINGW32__)
183   /* If this is a device file return it as is; under Windows NT and
184      OS/2 a device file end with ":".  */
185   if (nam [strlen (nam) - 1] == ':')
186     strcpy (buffer, nam);
187   else
188     {
189       _fullpath (buffer, nam, max_path_len);
190
191       for (p = buffer; *p; p++)
192         if (*p == '/')
193           *p = '\\';
194     }
195
196 #elif defined (MSDOS)
197   _fixpath (nam, buffer);
198
199 #elif defined (sgi)
200
201   /* Use realpath function which resolves links and references to .. and ..
202      on those Unix systems that support it. Note that GNU/Linux provides it but
203      cannot handle more than 5 symbolic links in a full name, so we use the
204      getcwd approach instead. */
205   realpath (nam, buffer);
206
207 #elif defined (VMS)
208   strcpy (buffer, __gnat_to_canonical_file_spec (nam));
209
210   if (buffer[0] == '/')
211     strcpy (buffer, __gnat_to_host_file_spec (buffer));
212   else
213     {
214       char nambuffer [MAXPATHLEN];
215
216       strcpy (nambuffer, buffer);
217       strcpy (buffer, getcwd (buffer, max_path_len, 0));
218       strcat (buffer, "/");
219       strcat (buffer, nambuffer);
220       strcpy (buffer, __gnat_to_host_file_spec (buffer));
221     }
222
223   return buffer;
224
225 #else
226   if (nam[0] != '/')
227     {
228       p = getcwd (buffer, max_path_len);
229       if (p == 0)
230         {
231           buffer[0] = '\0';
232           return 0;
233         }
234
235       /* If the name returned is an absolute path, it is safe to append '/'
236          to the path and concatenate the name of the file. */
237       if (buffer[0] == '/')
238         strcat (buffer, "/");
239
240       strcat (buffer, nam);
241     }
242   else
243     strcpy (buffer, nam);
244
245   return buffer;
246 #endif
247 }