1 /****************************************************************************
3 * GNAT RUN-TIME COMPONENTS *
7 * Auxiliary C functions for Interfaces.C.Streams *
9 * Copyright (C) 1992-2003 Free Software Foundation, Inc. *
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 2, 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. See the GNU General Public License *
17 * for more details. You should have received a copy of the GNU General *
18 * Public License distributed with GNAT; see file COPYING. If not, write *
19 * to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, *
20 * MA 02111-1307, USA. *
22 * As a special exception, if you link this file with other files to *
23 * produce an executable, this file does not by itself cause the resulting *
24 * executable to be covered by the GNU General Public License. This except- *
25 * ion does not however invalidate any other reasons why the executable *
26 * file might be covered by the GNU Public License. *
28 * GNAT was originally developed by the GNAT team at New York University. *
29 * Extensive contributions were provided by Ada Core Technologies Inc. *
31 ****************************************************************************/
33 /* Routines required for implementing routines in Interfaces.C.Streams */
55 /* Don't use macros on GNU/Linux since they cause incompatible changes between
70 /* The _IONBF value in MINGW32 stdio.h is wrong. */
71 #if defined (WINNT) || defined (_WINNT)
82 return (feof (stream));
86 __gnat_ferror (stream)
89 return (ferror (stream));
93 __gnat_fileno (stream)
96 return (fileno (stream));
100 __gnat_is_regular_file_fd (fd)
107 /* Programs using screen I/O may need to reset the FPU after
108 initialization of screen-handling related DLL's, so force
109 DLL initialization by doing a null-write and then reset the FPU */
111 DosWrite (0, &ret, 0, &ret);
115 ret = fstat (fd, &statbuf);
116 return (!ret && S_ISREG (statbuf.st_mode));
119 /* on some systems, the constants for seek are not defined, if so, then
120 provide the conventional definitions */
123 #define SEEK_SET 0 /* Set file pointer to offset */
124 #define SEEK_CUR 1 /* Set file pointer to its current value plus offset */
125 #define SEEK_END 2 /* Set file pointer to the size of the file plus offset */
128 /* if L_tmpnam is not set, use a large number that should be safe */
133 int __gnat_constant_eof = EOF;
134 int __gnat_constant_iofbf = _IOFBF;
135 int __gnat_constant_iolbf = _IOLBF;
136 int __gnat_constant_ionbf = _IONBF;
137 int __gnat_constant_l_tmpnam = L_tmpnam;
138 int __gnat_constant_seek_cur = SEEK_CUR;
139 int __gnat_constant_seek_end = SEEK_END;
140 int __gnat_constant_seek_set = SEEK_SET;
143 __gnat_constant_stderr ()
149 __gnat_constant_stdin ()
155 __gnat_constant_stdout ()
161 __gnat_full_name (nam, buffer)
165 #if defined(__EMX__) || defined (__MINGW32__)
168 /* If this is a device file return it as is; under Windows NT and
169 OS/2 a device file end with ":". */
170 if (nam[strlen (nam) - 1] == ':')
171 strcpy (buffer, nam);
174 _fullpath (buffer, nam, __gnat_max_path_len);
176 for (p = buffer; *p; p++)
181 #elif defined (MSDOS)
182 _fixpath (nam, buffer);
186 /* Use realpath function which resolves links and references to .. and ..
187 on those Unix systems that support it. Note that GNU/Linux provides it but
188 cannot handle more than 5 symbolic links in a full name, so we use the
189 getcwd approach instead. */
190 realpath (nam, buffer);
194 strncpy (buffer, __gnat_to_canonical_file_spec (nam), __gnat_max_path_len);
196 if (buffer[0] == '/' || strchr (buffer, '!')) /* '!' means decnet node */
197 strncpy (buffer, __gnat_to_host_file_spec (buffer), __gnat_max_path_len);
200 char *nambuffer = alloca (__gnat_max_path_len);
202 strncpy (nambuffer, buffer, __gnat_max_path_len);
204 (buffer, getcwd (buffer, __gnat_max_path_len, 0), __gnat_max_path_len);
205 strncat (buffer, "/", __gnat_max_path_len);
206 strncat (buffer, nambuffer, __gnat_max_path_len);
207 strncpy (buffer, __gnat_to_host_file_spec (buffer), __gnat_max_path_len);
217 p = getcwd (buffer, __gnat_max_path_len);
224 /* If the name returned is an absolute path, it is safe to append '/'
225 to the path and concatenate the name of the file. */
226 if (buffer[0] == '/')
227 strcat (buffer, "/");
229 strcat (buffer, nam);
232 strcpy (buffer, nam);