OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [contrib/] [ptyfix2.txt] - Blame information for rev 673

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
 
2
--- demos/microwin/mterm.c.old Fri Dec  3 07:03:39 1999
3
+++ demos/microwin/mterm.c Fri Dec  3 07:16:23 1999
4
@@ -248,15 +248,16 @@
5
  char * argv[2];
6
 
7
 again:
8
- sprintf(pty_name, "/dev/ptyp%d", n);
9
- if ((tfd = open(pty_name, O_RDWR | O_NONBLOCK)) < 0) {
10
- if ((errno == EBUSY) && (n < 3)) {
11
- ++n;
12
- goto again;
13
- }
14
- fprintf(stderr, "Can't create pty %s\n", pty_name);
15
+        if ((tfd = getpt())<0) {
16
+ fprintf(stderr, "Can't create master pty\n");
17
  return -1;
18
  }
19
+
20
+        if (grantpt(tfd))
21
+                perror("failure");
22
+        if (unlockpt(tfd))
23
+                perror("failure");
24
+
25
  signal(SIGCHLD, ptysignaled);
26
  signal(SIGINT, ptysignaled);
27
  if ((pid = fork()) == -1) {
28
@@ -264,13 +265,13 @@
29
  return -1;
30
  }
31
  if (!pid) {
32
+                ptsname_r(tfd, pty_name, 12);
33
  close(STDIN_FILENO);
34
  close(STDOUT_FILENO);
35
  close(STDERR_FILENO);
36
  close(tfd);
37
 
38
  setsid();
39
- pty_name[5] = 't';
40
  if ((tfd = open(pty_name, O_RDWR)) < 0) {
41
  fprintf(stderr, "Child: Can't open pty %s\n", pty_name);
42
  exit(1);
43
--- demos/nanox/nterm.c.old Fri Dec  3 07:03:39 1999
44
+++ demos/nanox/nterm.c Fri Dec  3 07:16:20 1999
45
@@ -162,15 +162,16 @@
46
  pid_t pid;
47
 
48
 again:
49
- sprintf(pty_name, "/dev/ptyp%d", n);
50
- if ((tfd = open(pty_name, O_RDWR | O_NONBLOCK)) < 0) {
51
- if ((errno == EBUSY || errno == EIO) && n < 10) {
52
- n++;
53
- goto again;
54
- }
55
- fprintf(stderr, "Can't create pty %s\n", pty_name);
56
+        if ((tfd = getpt())<0) {
57
+ fprintf(stderr, "Can't create master pty\n");
58
  return -1;
59
  }
60
+
61
+        if (grantpt(tfd))
62
+                perror("failure");
63
+        if (unlockpt(tfd))
64
+                perror("failure");
65
+
66
  signal(SIGCHLD, sigchild);
67
  signal(SIGINT, sigchild);
68
  if ((pid = fork()) == -1) {
69
@@ -178,13 +179,13 @@
70
  return -1;
71
  }
72
  if (!pid) {
73
+                ptsname_r(tfd, pty_name, 12);
74
  close(STDIN_FILENO);
75
  close(STDOUT_FILENO);
76
  close(STDERR_FILENO);
77
  close(tfd);
78
 
79
  setsid();
80
- pty_name[5] = 't';
81
  if ((tfd = open(pty_name, O_RDWR)) < 0) {
82
  fprintf(stderr, "Child: Can't open pty %s\n", pty_name);
83
  exit(1);
84
 
85
 
86
--

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.