cio.c 3.69 KB
Newer Older
Richard Kenner committed
1 2 3 4 5 6 7 8
/****************************************************************************
 *                                                                          *
 *                         GNAT COMPILER COMPONENTS                         *
 *                                                                          *
 *                                  C I O                                   *
 *                                                                          *
 *                          C Implementation File                           *
 *                                                                          *
9
 *          Copyright (C) 1992-2011, Free Software Foundation, Inc.         *
Richard Kenner committed
10 11 12
 *                                                                          *
 * GNAT is free software;  you can  redistribute it  and/or modify it under *
 * 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- *
Richard Kenner committed
14 15
 * sion.  GNAT is distributed in the hope that it will be useful, but WITH- *
 * OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY *
16 17 18 19 20 21 22 23 24 25
 * or FITNESS FOR A PARTICULAR PURPOSE.                                     *
 *                                                                          *
 * As a special exception under Section 7 of GPL version 3, you are granted *
 * additional permissions described in the GCC Runtime Library Exception,   *
 * version 3.1, as published by the Free Software Foundation.               *
 *                                                                          *
 * You should have received a copy of the GNU General Public License and    *
 * a copy of the GCC Runtime Library Exception along with this program;     *
 * see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    *
 * <http://www.gnu.org/licenses/>.                                          *
Richard Kenner committed
26 27
 *                                                                          *
 * GNAT was originally developed  by the GNAT team at  New York University. *
28
 * Extensive contributions were provided by Ada Core Technologies Inc.      *
Richard Kenner committed
29 30 31
 *                                                                          *
 ****************************************************************************/

32 33 34 35
#ifdef __cplusplus
extern "C" {
#endif

Richard Kenner committed
36 37 38 39 40 41 42 43 44 45 46
#ifdef IN_RTS
#include "tconfig.h"
#include "tsystem.h"
#include <sys/stat.h>
#else
#include "config.h"
#include "system.h"
#endif

#include "adaint.h"

47
/* Don't use macros on GNU/Linux since they cause incompatible changes between
Richard Kenner committed
48 49 50 51 52 53
   glibc 2.0 and 2.1 */
#ifdef linux
#undef putchar
#undef getchar
#undef fputc
#undef stderr
54
#undef stdout
Richard Kenner committed
55 56
#endif

Arnaud Charlet committed
57 58 59
/* Don't use macros versions of this functions on VxWorks since they cause
   imcompatible changes in some VxWorks versions */
#ifdef __vxworks
60
#undef getchar
Arnaud Charlet committed
61 62 63 64
#undef putchar
#undef feof
#undef ferror
#undef fileno
65 66
#endif

67 68 69 70 71
#ifdef RTX
#include <windows.h>
#include <Rtapi.h>
#endif

Richard Kenner committed
72
int
R. Kelley Cook committed
73
get_char (void)
Richard Kenner committed
74 75 76 77 78 79 80 81 82
{
#ifdef VMS
  return decc$getchar();
#else
  return getchar ();
#endif
}

int
R. Kelley Cook committed
83
get_int (void)
Richard Kenner committed
84 85 86 87 88 89 90 91
{
  int x;

  scanf (" %d", &x);
  return x;
}

void
R. Kelley Cook committed
92
put_int (int x)
Richard Kenner committed
93
{
94 95 96
#ifdef RTX
   RtPrintf ("%d", x);
#else
97 98 99
   /* Use fprintf rather than printf, since the latter is unbuffered
      on vxworks */
   fprintf (stdout, "%d", x);
100
#endif
Richard Kenner committed
101 102 103
}

void
R. Kelley Cook committed
104
put_int_stderr (int x)
Richard Kenner committed
105
{
106 107 108
#ifdef RTX
  RtPrintf ("%d", x);
#else
Richard Kenner committed
109
  fprintf (stderr, "%d", x);
110
#endif
Richard Kenner committed
111 112 113
}

void
R. Kelley Cook committed
114
put_char (int c)
Richard Kenner committed
115
{
116 117 118
#ifdef RTX
  RtPrintf ("%c", c);
#else
Richard Kenner committed
119
  putchar (c);
120
#endif
Richard Kenner committed
121 122 123
}

void
R. Kelley Cook committed
124
put_char_stderr (int c)
Richard Kenner committed
125
{
126 127 128
#ifdef RTX
  RtPrintf ("%c", c);
#else
Richard Kenner committed
129
  fputc (c, stderr);
130
#endif
Richard Kenner committed
131 132 133 134 135
}

#ifdef __vxworks

char *
R. Kelley Cook committed
136
mktemp (char *template)
Richard Kenner committed
137 138 139 140
{
  return tmpnam (NULL);
}
#endif
141 142 143 144

#ifdef __cplusplus
}
#endif