Mercurial > hg > octave-lojdl > gnulib-hg
annotate lib/forkpty.c @ 16229:daac1ca4c436
inttypes: Modernize.
* lib/inttypes.in.h (strtoimax, strtoumax): Use the C++ safe idioms.
* modules/inttypes-incomplete (Depends-on): Add snippet/c++defs.
(Makefile.am): Update inttypes.h rule.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 05 Jan 2012 18:42:08 +0100 |
parents | 8250f2777afc |
children | e542fd46ad6f |
rev | line source |
---|---|
13040
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
1 /* Fork a child process attached to the slave of a pseudo-terminal. |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
14079
diff
changeset
|
2 Copyright (C) 2010-2012 Free Software Foundation, Inc. |
13006
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
3 |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
5 it under the terms of the GNU General Public License as published by |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
7 (at your option) any later version. |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
8 |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
13 |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
16 |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
17 #include <config.h> |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
18 |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
19 /* Specification. */ |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
20 #include <pty.h> |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
21 |
13040
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
22 #if HAVE_FORKPTY |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
23 |
13042 | 24 /* Provide a wrapper with the prototype of glibc-2.8 and newer. */ |
13006
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
25 # undef forkpty |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
26 int |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
27 rpl_forkpty (int *amaster, char *name, struct termios const *termp, |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
28 struct winsize const *winp) |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
29 { |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
30 /* Cast away const, for implementations with weaker prototypes. */ |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
31 return forkpty (amaster, name, (struct termios *) termp, |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
32 (struct winsize *) winp); |
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
33 } |
13040
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
34 |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
35 #else /* AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw */ |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
36 |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
37 # include <pty.h> |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
38 # include <unistd.h> |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
39 |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
40 extern int login_tty (int slave_fd); |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
41 |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
42 int |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
43 forkpty (int *amaster, char *name, |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
44 const struct termios *termp, const struct winsize *winp) |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
45 { |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
46 int master, slave, pid; |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
47 |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
48 if (openpty (&master, &slave, name, termp, winp) == -1) |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
49 return -1; |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
50 |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
51 switch (pid = fork ()) |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
52 { |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
53 case -1: |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
54 close (master); |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
55 close (slave); |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
56 return -1; |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
57 |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
58 case 0: |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
59 /* Child. */ |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
60 close (master); |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
61 if (login_tty (slave)) |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
62 _exit (1); |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
63 return 0; |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
64 |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
65 default: |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
66 /* Parent. */ |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
67 *amaster = master; |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
68 close (slave); |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
69 return pid; |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
70 } |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
71 } |
320f40c27bf5
forkpty: Provide replacement on AIX, HP-UX, IRIX, Solaris.
Bruno Haible <bruno@clisp.org>
parents:
13006
diff
changeset
|
72 |
13006
b89998923de3
forkpty, openpty: prefer glibc's const-safe prototype
Eric Blake <eblake@redhat.com>
parents:
diff
changeset
|
73 #endif |