home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / gnat-3.05- / gnat-3 / gnat-3.05-i486-linux-elf-bin / rts / a-cstrea.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-07  |  4.8 KB  |  136 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                          GNAT RUN-TIME COMPONENTS                        */
  4. /*                                                                          */
  5. /*              Auxiliary C functions for Interfaces.C.Streams              */
  6. /*                                                                          */
  7. /*                                   Body                                   */
  8. /*                                                                          */
  9. /*                              $Revision: 1.17 $                           */
  10. /*                                                                          */
  11. /*    Copyright (C) 1992, 1993, 1994, 1995 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. #include "config.h"
  38. #include <sys/types.h>
  39. #include <sys/stat.h>
  40. #include <stdio.h>
  41.  
  42. #if defined (__EMX__) || defined (WINNT)
  43. #include <stdlib.h>
  44. int max_path_len = _MAX_PATH;
  45. #else
  46. #include <sys/param.h>
  47.  
  48. /* If we can't find MAXPATHLEN there, try in unistd.h.  That file might
  49.    not exist, but we'll blow up anyway if we don't try something.  */
  50. #ifndef MAXPATHLEN
  51. #include <unistd.h>
  52. #endif
  53.  
  54. int max_path_len = MAXPATHLEN;
  55. #endif
  56.  
  57. int feof__ (FILE *stream)
  58. {
  59.    return (feof (stream));
  60. }
  61.  
  62. int ferror__ (FILE *stream)
  63. {
  64.    return (ferror (stream));
  65. }
  66.  
  67. int fileno__ (FILE *stream)
  68. {
  69.    return (fileno (stream));
  70. }
  71.  
  72. int
  73. is_regular_file_fd (fd)
  74.      int fd;
  75. {
  76.   int ret;
  77.   struct stat statbuf;
  78.  
  79.   ret = fstat (fd, &statbuf);
  80.   return (!ret && S_ISREG (statbuf.st_mode));
  81. }
  82.  
  83. /* on some systems, the constants for seek are not defined, if so, then
  84.    provide the conventional definitions */
  85. #ifndef SEEK_SET
  86. #define SEEK_SET 0  /* Set file pointer to offset                           */
  87. #define SEEK_CUR 1  /* Set file pointer to its current value plus offset    */
  88. #define SEEK_END 2  /* Set file pointer to the size of the file plus offset */
  89. #endif
  90.  
  91. int    c_constant_eof      = EOF;
  92. int    c_constant_iofbf    = _IOFBF;
  93. int    c_constant_iolbf    = _IOLBF;
  94. int    c_constant_ionbf    = _IONBF;
  95. int    c_constant_seek_cur = SEEK_CUR;
  96. int    c_constant_seek_end = SEEK_END;
  97. int    c_constant_seek_set = SEEK_SET;
  98.  
  99. FILE*  c_constant_stderr () {return stderr;}
  100. FILE*  c_constant_stdin  () {return stdin;}
  101. FILE*  c_constant_stdout () {return stdout;}
  102.  
  103.  
  104. char *
  105. full_name (char *nam, char *buffer)
  106. {
  107.    char *p;
  108. #if defined (__EMX__) || defined (WINNT)
  109.    _fullpath (buffer, nam, max_path_len);
  110.    for (p = buffer; *p; p++) if (*p == '/') *p = '\\';
  111.  
  112. #else
  113. #if defined (MSDOS)
  114.    _fixpath (nam, buffer);
  115.  
  116. #else
  117. #if defined (sgi) || defined (sun) || defined (linux)
  118.    /* Use realpath function which resolves links and references to .. and ..
  119.       on those Unix systems that support it. */
  120.    realpath (nam, buffer);
  121.  
  122. #else
  123.    extern char *getcwd();
  124.    if (nam[0] != '/') {
  125.       buffer = getcwd (buffer, max_path_len);
  126.       strcat (buffer, "/");
  127.       strcat (buffer, nam);
  128.    }
  129.    else {
  130.       strcpy (buffer, nam);
  131.    }
  132. #endif
  133. #endif
  134. #endif
  135. }
  136.