home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adav313.zip / gnat-3_13p-os2-bin-20010916.zip / emx / gnatlib / a-cstrea.c < prev    next >
C/C++ Source or Header  |  2000-07-19  |  7KB  |  274 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                          GNAT RUN-TIME COMPONENTS                        */
  4. /*                                                                          */
  5. /*              Auxiliary C functions for Interfaces.C.Streams              */
  6. /*                                                                          */
  7. /*                                   Body                                   */
  8. /*                                                                          */
  9. /*                              $Revision: 1.44 $
  10. /*                                                                          */
  11. /*          Copyright (C) 1992-2000 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. #include "config.h"
  42. #include <sys/types.h>
  43. #include <sys/stat.h>
  44. #include <stdio.h>
  45.  
  46. #ifdef __EMX__
  47. #include <stdlib.h>
  48. int max_path_len = _MAX_PATH;
  49.  
  50. #elif defined (VMS)
  51. #include "a-adaint.h"
  52. #include <unixlib.h>
  53. int max_path_len = 255; /* PATH_MAX */
  54.  
  55. #elif defined (__vxworks) || defined (__OPENNT)
  56. #include <limits.h>
  57. int max_path_len = PATH_MAX;
  58.  
  59. #elif defined (linux)
  60. #include <sys/param.h>
  61.  
  62. /* If we cannot find MAXPATHLEN there, try in unistd.h.  That file might
  63.    not exist, but we'll blow up anyway if we don't try something.  */
  64. #ifndef MAXPATHLEN
  65. #include <unistd.h>
  66. #endif
  67.  
  68. /* Don't use macros on linux since they cause incompatible changes between
  69.    glibc 2.0 and 2.1 */
  70.  
  71. #ifdef stderr
  72. #  undef stderr
  73. #endif
  74. #ifdef stdin
  75. #  undef stdin
  76. #endif
  77. #ifdef stdout
  78. #  undef stdout
  79. #endif
  80.  
  81. int max_path_len = MAXPATHLEN;
  82.  
  83. #else
  84. #include <sys/param.h>
  85.  
  86. /* If we can't find MAXPATHLEN there, try in unistd.h.  That file might
  87.    not exist, but we'll blow up anyway if we don't try something.  */
  88. #ifndef MAXPATHLEN
  89. #include <unistd.h>
  90. #endif
  91.  
  92. int max_path_len = MAXPATHLEN;
  93. #endif
  94.  
  95. /* the _IONBF value in CYGNUS or MINGW32 stdio.h is wrong */
  96. #if defined (WINNT) || defined (_WINNT)
  97. #undef _IONBF
  98. #define _IONBF 0004
  99. #endif
  100.  
  101. int
  102. feof__ (stream)
  103.      FILE *stream;
  104. {
  105.   return (feof (stream));
  106. }
  107.  
  108. int
  109. ferror__ (stream)
  110.      FILE *stream;
  111. {
  112.    return (ferror (stream));
  113. }
  114.  
  115. int
  116. fileno__ (stream)
  117.      FILE *stream;
  118. {
  119.    return (fileno (stream));
  120. }
  121.  
  122. int
  123. is_regular_file_fd (fd)
  124.      int fd;
  125. {
  126.   int ret;
  127.   struct stat statbuf;
  128.  
  129. #ifdef __EMX__
  130.   /* Programs using screen I/O may need to reset the FPU after
  131.      initialization of screen-handling related DLL's, so force
  132.      DLL initialization by doing a null-write and then reset the FPU */
  133.  
  134.   DosWrite (0, &ret, 0, &ret);
  135.   __gnat_init_float();
  136. #endif
  137.  
  138.   ret = fstat (fd, &statbuf);
  139.   return (!ret && S_ISREG (statbuf.st_mode));
  140. }
  141.  
  142. /* on some systems, the constants for seek are not defined, if so, then
  143.    provide the conventional definitions */
  144.  
  145. #ifndef SEEK_SET
  146. #define SEEK_SET 0  /* Set file pointer to offset                           */
  147. #define SEEK_CUR 1  /* Set file pointer to its current value plus offset    */
  148. #define SEEK_END 2  /* Set file pointer to the size of the file plus offset */
  149. #endif
  150.  
  151. /* if L_tmpnam is not set, use a large number that should be safe */
  152. #ifndef L_tmpnam
  153. #define L_tmpnam 256
  154. #endif
  155.  
  156. int    c_constant_eof      = EOF;
  157. int    c_constant_iofbf    = _IOFBF;
  158. int    c_constant_iolbf    = _IOLBF;
  159. int    c_constant_ionbf    = _IONBF;
  160. int    c_constant_l_tmpnam = L_tmpnam;
  161. int    c_constant_seek_cur = SEEK_CUR;
  162. int    c_constant_seek_end = SEEK_END;
  163. int    c_constant_seek_set = SEEK_SET;
  164.  
  165. FILE *
  166. c_constant_stderr ()
  167. {
  168.   return stderr;
  169. }
  170.  
  171. FILE *
  172. c_constant_stdin ()
  173. {
  174.   return stdin;
  175. }
  176.  
  177. FILE *
  178. c_constant_stdout ()
  179. {
  180.   return stdout;
  181. }
  182.  
  183. char *
  184. full_name (nam, buffer)
  185.      char *nam;
  186.      char *buffer;
  187. {
  188.    char *p;
  189.  
  190. #if defined(__EMX__) || defined (__MINGW32__)
  191.    /* if this is a device file return it as is */
  192.    /* under Windows NT and OS/2 a device file end with : */
  193.    if (nam [strlen (nam) - 1] == ':')
  194.      {
  195.        strcpy (buffer, nam);
  196.      }
  197.      else
  198.      {
  199.        _fullpath (buffer, nam, max_path_len);
  200.        for (p = buffer; *p; p++)
  201.      if (*p == '/')
  202.        *p = '\\';
  203.      }
  204.  
  205. #else
  206. #ifdef MSDOS
  207.    _fixpath (nam, buffer);
  208.  
  209. #else
  210. #if defined (sgi) || defined (sun) || defined (linux)
  211.  
  212.    /* Use realpath function which resolves links and references to .. and ..
  213.       on those Unix systems that support it. */
  214.    realpath (nam, buffer);
  215.  
  216. #else
  217. #ifdef _WINNT
  218.  
  219.    /* The Cygnus development environment supports Unix-like filenames
  220.       and provides a routine for converting paths to their full
  221.       specification.  If not using Cygwin32 (i.e. Mingw32), then use
  222.       the MS routine. */
  223. #ifdef __CYGWIN32__
  224.    cygwin32_conv_to_full_win32_path (nam, buffer, max_path_len);
  225. #else
  226.    _fullpath (nam, buffer);
  227. #endif
  228.  
  229. #else
  230. #ifdef VMS
  231.    strcpy (buffer, to_canonical_file_spec (nam));
  232.  
  233.    if (buffer[0] == '/')
  234.      {
  235.        strcpy (buffer, to_host_file_spec (buffer));
  236.      }
  237.    else
  238.      {
  239.        char nambuffer [max_path_len];
  240.  
  241.        strcpy (nambuffer, buffer);
  242.        strcpy (buffer, getcwd (buffer, max_path_len, 0));
  243.        strcat (buffer, "/");
  244.        strcat (buffer, nambuffer);
  245.        strcpy (buffer, to_host_file_spec (buffer));
  246.      }
  247.  
  248.    return buffer;
  249.  
  250. #else
  251.    extern char *getcwd();
  252.  
  253.    if (nam[0] != '/')
  254.      {
  255.        p = getcwd (buffer, max_path_len);
  256.        if (p == 0)
  257.      {
  258.        buffer[0] = '\0';
  259.        return NULL;
  260.      }
  261.  
  262.        strcat (buffer, "/");
  263.        strcat (buffer, nam);
  264.      }
  265.    else
  266.      strcpy (buffer, nam);
  267.  
  268. #endif
  269. #endif
  270. #endif
  271. #endif
  272. #endif
  273. }
  274.