1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
10 * Copyright (C) 2001-2002 Ada Core Technologies, Inc. *
12 * GNAT is free software; you can redistribute it and/or modify it under *
13 * terms of the GNU General Public License as published by the Free Soft- *
14 * ware Foundation; either version 2, or (at your option) any later ver- *
15 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
16 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
18 * for more details. You should have received a copy of the GNU General *
19 * Public License distributed with GNAT; see file COPYING. If not, write *
20 * to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, *
21 * MA 02111-1307, USA. *
23 * As a special exception, if you link this file with other files to *
24 * produce an executable, this file does not by itself cause the resulting *
25 * executable to be covered by the GNU General Public License. This except- *
26 * ion does not however invalidate any other reasons why the executable *
27 * file might be covered by the GNU Public License. *
29 * GNAT was originally developed by the GNAT team at New York University. *
30 * It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). *
32 ****************************************************************************/
34 #ifdef __alpha_vxworks
47 /* This file provides the low level functionalities needed to implement Expect
48 capabilities in GNAT.Expect.
49 Implementations for unix and windows systems is provided.
50 Dummy stubs are also provided for other systems. */
53 /* Work around the fact that gcc/cpp does not define "unix" under AiX. */
62 /* ??? Provide a no-op for now */
76 __gnat_expect_portable_execvp (pid, cmd, argv)
81 *pid = (int) spawnve (_P_NOWAIT, cmd, argv, NULL);
90 CreatePipe (&read, &write, NULL, 0);
91 fd[0]=_open_osfhandle (read, 0);
92 fd[1]=_open_osfhandle (write, 0);
93 return 0; /* always success */
97 __gnat_expect_poll (fd, num_fd, timeout, is_set)
105 HANDLE handles[num_fd];
107 for (i = 0; i < num_fd; i++)
110 for (i = 0; i < num_fd; i++)
111 handles[i] = (HANDLE) _get_osfhandle (fd[i]);
117 for (i = 0; i < num_fd; i++)
119 if (!PeekNamedPipe (handles[i], NULL, 0, NULL, &avail, NULL))
129 if (timeout >= 0 && num == 0)
156 __gnat_expect_fork ()
162 __gnat_expect_portable_execvp (pid, cmd, argv)
167 *pid = (int) getpid();
168 /* Since cmd is fully qualified, it is incorrect to to call execvp */
173 __gnat_expect_poll (fd, num_fd, timeout, is_set)
179 int i, num, ready = 0;
181 int mbxchans [num_fd];
182 struct dsc$descriptor_s mbxname;
183 struct io_status_block {
190 for (i = 0; i < num_fd; i++)
193 for (i = 0; i < num_fd; i++)
196 /* Get name of the mailbox used in the pipe */
197 getname (fd [i], buf);
199 /* Assign a channel to the mailbox */
200 if (strlen (buf) > 0)
202 mbxname.dsc$w_length = strlen (buf);
203 mbxname.dsc$b_dtype = DSC$K_DTYPE_T;
204 mbxname.dsc$b_class = DSC$K_CLASS_S;
205 mbxname.dsc$a_pointer = buf;
207 status = SYS$ASSIGN (&mbxname, &mbxchans[i], 0, 0, 0);
215 for (i = 0; i < num_fd; i++)
220 /* Peek in the mailbox to see if there's data */
222 (0, mbxchans[i], IO$_SENSEMODE|IO$M_READERCHECK,
223 &iosb, 0, 0, 0, 0, 0, 0, 0, 0);
234 if (timeout >= 0 && num == 0)
246 /* Deassign channels assigned above */
247 for (i = 0; i < num_fd; i++)
250 status = SYS$DASSGN (mbxchans[i]);
258 #include <sys/time.h>
261 #define SELECT_MASK fd_set
262 #else /* !NO_FD_SET */
264 typedef long fd_mask;
267 #define SELECT_MASK void
269 #define SELECT_MASK int
271 #endif /* !NO_FD_SET */
281 __gnat_expect_fork ()
287 __gnat_expect_portable_execvp (pid, cmd, argv)
292 *pid = (int) getpid();
297 __gnat_expect_poll (fd, num_fd, timeout, is_set)
311 for (i = 0; i < num_fd; i++)
313 FD_SET (fd[i], &rset);
318 tv.tv_sec = timeout / 1000;
319 tv.tv_usec = (timeout % 1000) * 1000;
321 ready = select (max_fd + 1, &rset, NULL, NULL, timeout == -1 ? NULL : &tv);
324 for (i = 0; i < num_fd; i++)
325 is_set[i] = (FD_ISSET (fd[i], &rset) ? 1 : 0);
340 __gnat_expect_fork ()
346 __gnat_expect_portable_execvp (pid, cmd, argv)
355 __gnat_expect_poll (fd, num_fd, timeout, is_set)