summaryrefslogtreecommitdiff
path: root/recipes/glibc/glibc-2.3.2/glibc22-ttyname-devfs.patch
blob: 902a1b7351fbb3773f8a1e0f43b4fad102aa88a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
--- sysdeps/unix/sysv/linux/ttyname_r.c~	2001/07/06 04:56:13	1.14
+++ sysdeps/unix/sysv/linux/ttyname_r.c	2002/01/06 02:27:48
@@ -28,21 +28,24 @@
 
 #include <stdio-common/_itoa.h>
 
-static int getttyname_r (char *buf, size_t buflen,
-			 dev_t mydev, ino64_t myino, int save,
+static int getttyname_r (const char *prefix, char *buf, size_t buflen,
+			 struct stat64 *mystat, int save,
 			 int *dostat) internal_function;
 
 static int
 internal_function
-getttyname_r (char *buf, size_t buflen, dev_t mydev, ino64_t myino,
+getttyname_r (const char *prefix, char *buf, size_t buflen, struct stat64 *mystat,
 	      int save, int *dostat)
 {
   struct stat64 st;
   DIR *dirstream;
   struct dirent64 *d;
-  size_t devlen = strlen (buf);
+  size_t devlen = strlen (prefix);
 
-  dirstream = __opendir (buf);
+  memcpy (buf, prefix, devlen);
+  buflen -= devlen;
+
+  dirstream = __opendir (prefix);
   if (dirstream == NULL)
     {
       *dostat = -1;
@@ -50,7 +53,7 @@
     }
 
   while ((d = __readdir64 (dirstream)) != NULL)
-    if ((d->d_fileno == myino || *dostat)
+    if ((d->d_fileno == mystat->st_ino || *dostat)
 	&& strcmp (d->d_name, "stdin")
 	&& strcmp (d->d_name, "stdout")
 	&& strcmp (d->d_name, "stderr"))
@@ -71,9 +74,9 @@
 
 	if (__xstat64 (_STAT_VER, buf, &st) == 0
 #ifdef _STATBUF_ST_RDEV
-	    && S_ISCHR (st.st_mode) && st.st_rdev == mydev
+	    && S_ISCHR (st.st_mode) && st.st_rdev == mystat->st_rdev
 #else
-	    && d->d_fileno == myino && st.st_dev == mydev
+	    && d->d_fileno == mystat->st_ino && st.st_dev == mystat->st_dev
 #endif
 	   )
 	  {
@@ -99,7 +102,8 @@
   struct stat64 st, st1;
   int dostat = 0;
   int save = errno;
-  int ret;
+  int ret, i;
+  const char *dirs[] = { "/dev/pts/", "/dev/vc/", "/dev/tts/", 0 };
 
   /* Test for the absolute minimal size.  This makes life easier inside
      the loop.  */
@@ -139,50 +143,24 @@
   if (__fxstat64 (_STAT_VER, fd, &st) < 0)
     return errno;
 
-  /* Prepare the result buffer.  */
-  memcpy (buf, "/dev/pts/", sizeof ("/dev/pts/"));
-  buflen -= sizeof ("/dev/pts/") - 1;
+  ret = ENOTTY;
 
-  if (__xstat64 (_STAT_VER, buf, &st1) == 0 && S_ISDIR (st1.st_mode))
-    {
-#ifdef _STATBUF_ST_RDEV
-      ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino, save,
-			  &dostat);
-#else
-      ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino, save,
-			  &dostat);
-#endif
-    }
-  else
+  for (i = 0; ret && dirs[i]; i++)
     {
-      __set_errno (save);
-      ret = ENOENT;
+      if (__xstat64 (_STAT_VER, dirs[i], &st1) == 0 && S_ISDIR (st1.st_mode))
+	ret = getttyname_r (dirs[i], buf, buflen, &st, save, &dostat);
+      else
+	__set_errno (save);
     }
 
+
   if (ret && dostat != -1)
-    {
-      buf[sizeof ("/dev/") - 1] = '\0';
-      buflen += sizeof ("pts/") - 1;
-#ifdef _STATBUF_ST_RDEV
-      ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino, save,
-			  &dostat);
-#else
-      ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino, save,
-			  &dostat);
-#endif
-    }
+    ret = getttyname_r ("/dev/", buf, buflen, &st, save, &dostat);
 
   if (ret && dostat != -1)
     {
-      buf[sizeof ("/dev/") - 1] = '\0';
       dostat = 1;
-#ifdef _STATBUF_ST_RDEV
-      ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino,
-			  save, &dostat);
-#else
-      ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino,
-			  save, &dostat);
-#endif
+      ret = getttyname_r ("/dev/", buf, buflen, &st, save, &dostat);
     }
 
   return ret;
--- sysdeps/unix/sysv/linux/ttyname.c~	2001/07/06 04:56:13	1.16
+++ sysdeps/unix/sysv/linux/ttyname.c	2002/01/06 02:27:48
@@ -30,8 +30,8 @@
 
 char *__ttyname;
 
-static char *getttyname (const char *dev, dev_t mydev,
-			 ino64_t myino, int save, int *dostat)
+static char *getttyname (const char *dev, struct stat64 *mystat,
+			 int save, int *dostat)
      internal_function;
 
 
@@ -39,7 +39,7 @@
 
 static char *
 internal_function
-getttyname (const char *dev, dev_t mydev, ino64_t myino, int save, int *dostat)
+getttyname (const char *dev, struct stat64 *mystat, int save, int *dostat)
 {
   static size_t namelen;
   struct stat64 st;
@@ -55,7 +55,7 @@
     }
 
   while ((d = __readdir64 (dirstream)) != NULL)
-    if ((d->d_fileno == myino || *dostat)
+    if ((d->d_fileno == mystat->st_ino || *dostat)
 	&& strcmp (d->d_name, "stdin")
 	&& strcmp (d->d_name, "stdout")
 	&& strcmp (d->d_name, "stderr"))
@@ -78,9 +78,9 @@
 	memcpy (&getttyname_name[devlen], d->d_name, dlen);
 	if (__xstat64 (_STAT_VER, getttyname_name, &st) == 0
 #ifdef _STATBUF_ST_RDEV
-	    && S_ISCHR (st.st_mode) && st.st_rdev == mydev
+	    && S_ISCHR (st.st_mode) && st.st_rdev == mystat->st_rdev
 #else
-	    && d->d_fileno == myino && st.st_dev == mydev
+	    && d->d_fileno == mystat->st_ino && st.st_dev == mystat->st_dev
 #endif
 	   )
 	  {
@@ -110,9 +110,10 @@
   char procname[30];
   struct stat64 st, st1;
   int dostat = 0;
-  char *name;
+  char *name = NULL;
   int save = errno;
-  int len;
+  int len, i;
+  const char *dirs[] = { "/dev/pts", "/dev/vc", "/dev/tts", 0 };
 
   if (!__isatty (fd))
     return NULL;
@@ -146,37 +147,21 @@
   if (__fxstat64 (_STAT_VER, fd, &st) < 0)
     return NULL;
 
-  if (__xstat64 (_STAT_VER, "/dev/pts", &st1) == 0 && S_ISDIR (st1.st_mode))
+  for (i = 0; !name && dirs[i]; i++)
     {
-#ifdef _STATBUF_ST_RDEV
-      name = getttyname ("/dev/pts", st.st_rdev, st.st_ino, save, &dostat);
-#else
-      name = getttyname ("/dev/pts", st.st_dev, st.st_ino, save, &dostat);
-#endif
+      if (__xstat64 (_STAT_VER, dirs[i], &st1) == 0 && S_ISDIR (st1.st_mode))
+	name = getttyname (dirs[i], &st, save, &dostat);
+      else
+	__set_errno (save);
     }
-  else
-    {
-      __set_errno (save);
-      name = NULL;
-    }
-
+  
   if (!name && dostat != -1)
-    {
-#ifdef _STATBUF_ST_RDEV
-      name = getttyname ("/dev", st.st_rdev, st.st_ino, save, &dostat);
-#else
-      name = getttyname ("/dev", st.st_dev, st.st_ino, save, &dostat);
-#endif
-    }
+    name = getttyname ("/dev", &st, save, &dostat);
 
   if (!name && dostat != -1)
     {
       dostat = 1;
-#ifdef _STATBUF_ST_RDEV
-      name = getttyname ("/dev", st.st_rdev, st.st_ino, save, &dostat);
-#else
-      name = getttyname ("/dev", st.st_dev, st.st_ino, save, &dostat);
-#endif
+      name = getttyname ("/dev", &st, save, &dostat);
     }
 
   return name;