OSDN Git Service

2006-03-01 Andrew Pinski <pinskia@physics.uc.edu>
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / vms-psxcrt0-64.c
1 /* VMS 64bit crt0 returning Unix style condition codes .
2    Copyright (C) 2001 Free Software Foundation, Inc.
3    Contributed by Douglas B. Rupp (rupp@gnat.com).
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file.  (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
20
21 GCC is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with GCC; see the file COPYING.  If not, write to
28 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA.  */
30
31 #if !defined(__DECC)
32 You Lose! This file can only be compiled with DEC C.
33 #else
34
35 /* This file can only be compiled with DEC C, due to the call to
36    lib$establish and the pragmas pointer_size.  */
37
38 #pragma __pointer_size short
39
40 #include <stdlib.h>
41 #include <string.h>
42 #include <ssdef.h>
43 #include <stsdef.h>
44 #include <errnodef.h>
45
46 extern void decc$main ();
47 extern int main ();
48
49 static int
50 handler (sigargs, mechargs)
51      void *sigargs;
52      void *mechargs;
53 {
54   return SS$_RESIGNAL;
55 }
56
57 int
58 __main (arg1, arg2, arg3, image_file_desc, arg5, arg6)
59      void *arg1, *arg2, *arg3;
60      void *image_file_desc;
61      void *arg5, *arg6)
62 {
63   int argc;
64   char **argv;
65   char **envp;
66
67 #pragma __pointer_size long
68
69   int i;
70   char **long_argv;
71   char **long_envp;
72   int status;
73
74 #pragma __pointer_size short
75
76   lib$establish (handler);
77   decc$main (arg1, arg2, arg3, image_file_desc,
78              arg5, arg6, &argc, &argv, &envp);
79
80 #pragma __pointer_size long
81
82   /* Reallocate argv with 64 bit pointers.  */
83   long_argv = (char **) malloc (sizeof (char *) * (argc + 1));
84
85   for (i = 0; i < argc; i++)
86     long_argv[i] = strdup (argv[i]);
87
88   long_argv[argc] = (char *) 0;
89
90   long_envp = (char **) malloc (sizeof (char *) * 5);
91
92   for (i = 0; envp[i]; i++)
93     long_envp[i] = strdup (envp[i]);
94
95   long_envp[i] = (char *) 0;
96
97 #pragma __pointer_size short
98
99   status = main (argc, long_argv, long_envp);
100
101   /* Map into a range of 0 - 255.  */
102   status = status & 255;
103
104   if (status > 0)
105     {
106       int save_status = status;
107
108       status = C$_EXIT1 + ((status - 1) << STS$V_MSG_NO);
109
110       /* An exit failure status requires a "severe" error.  All status values
111          are defined in errno with a successful (1) severity but can be
112          changed to an error (2) severity by adding 1.  In addition for
113          compatibility with UNIX exit() routines we inhibit a run-time error
114          message from being generated on exit(1).  */
115
116       if (save_status == 1)
117         {
118           status++;
119           status |= STS$M_INHIB_MSG;
120         }
121     }
122
123   if (status == 0)
124     status = SS$_NORMAL;
125
126   return status;
127 }
128 #endif