nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /* Copyright (C) 1998, 1999, 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
4  
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9  
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14  
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19  
20 #include <errno.h>
21 #include <fcntl.h>
22 #include <limits.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <termios.h>
26 #include <unistd.h>
27 #include <sys/types.h>
28 #include <sys/ioctl.h>
29  
30 #define _PATH_DEVPTMX "/dev/ptmx"
31  
32 int openpty (int *amaster, int *aslave, char *name, struct termios *termp,
33 struct winsize *winp)
34 {
35 char buf[PATH_MAX];
36 int master, slave;
37  
38 master = open(_PATH_DEVPTMX, O_RDWR);
39 if (master == -1)
40 return -1;
41  
42 if (grantpt(master))
43 goto fail;
44  
45 if (unlockpt(master))
46 goto fail;
47  
48 if (ptsname_r(master, buf, sizeof buf))
49 goto fail;
50  
51 slave = open(buf, O_RDWR | O_NOCTTY);
52 if (slave == -1)
53 goto fail;
54  
55 /* XXX Should we ignore errors here? */
56 if (termp)
57 tcsetattr(slave, TCSAFLUSH, termp);
58 if (winp)
59 ioctl(slave, TIOCSWINSZ, winp);
60  
61 *amaster = master;
62 *aslave = slave;
63 if (name != NULL)
64 strcpy(name, buf);
65  
66 return 0;
67  
68 fail:
69 close(master);
70 return -1;
71 }