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