diff options
-rw-r--r-- | ChangeLog | 26 | ||||
-rw-r--r-- | iconvdata/TESTS | 10 | ||||
-rw-r--r-- | iconvdata/testdata/CP1250 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1250..UTF8 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1251 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1251..UTF8 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1252 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1252..UTF8 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1253 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1253..UTF8 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1254 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1254..UTF8 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1255 | 13 | ||||
-rw-r--r-- | iconvdata/testdata/CP1255..UTF8 | 13 | ||||
-rw-r--r-- | iconvdata/testdata/CP1256 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1256..UTF8 | 14 | ||||
-rw-r--r-- | iconvdata/testdata/CP1257 | 14 | ||||
-rw-r--r-- | streams/Makefile | 2 | ||||
-rw-r--r-- | streams/sys/stropts.h | 1 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/Makefile | 4 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/ptsname.c | 2 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/syscalls.list | 14 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/ttyname.c | 152 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/ttyname_r.c | 182 |
24 files changed, 588 insertions, 13 deletions
@@ -1,3 +1,29 @@ +1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> + + * streams/Makefile (headers): Add sys/stropts.h. + * streams/sys/stropts.h: New file. + +1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> + + * sysdeps/unix/sysv/linux/ttyname.c, + sysdeps/unix/sysv/linux/ttyname_r.c: New files, like + sysdeps/posix/ttyname*.c, but look in /dev/pts first. + +1998-04-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> + + * sysdeps/unix/sysv/linux/ptsname.c: Fix off-by-one bug in second + argument of _itoa_word. + +1998-04-24 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> + + * sysdeps/unix/sysv/linux/syscalls.list (s_getcwd, s_getdents, + s_pread64, s_pwrite64, s_reboot, s_sigpending, s_sigprocmask): Set + caller to getcwd, getdents, pread64, pwrite64, reboot, sigpending, + sigprocmask, resp., instead of EXTRA. + + * sysdeps/unix/sysv/linux/Makefile (sysdep_routines): Remove + s_pread64 and s_pwrite64. + 1998-04-26 18:44 Ulrich Drepper <drepper@cygnus.com> * iconvdata/Makefile: Correct rules to generate gap table. diff --git a/iconvdata/TESTS b/iconvdata/TESTS index d18a808290..fa4aea69b5 100644 --- a/iconvdata/TESTS +++ b/iconvdata/TESTS @@ -63,3 +63,13 @@ PT PT Y UTF8 PT2 PT2 Y UTF8 SEN_850200_B SEN_850200_B Y UTF8 SEN_850200_C SEN_850200_C Y UTF8 +KOI-8 KOI-8 Y UTF8 +KOI8-R KOI8-R Y UTF8 +CP1250 CP1250 Y UTF8 +CP1251 CP1251 Y UTF8 +CP1252 CP1252 Y UTF8 +CP1253 CP1253 Y UTF8 +CP1254 CP1254 Y UTF8 +CP1255 CP1255 Y UTF8 +CP1256 CP1256 Y UTF8 +CP1257 CP1257 Y UTF8 diff --git a/iconvdata/testdata/CP1250 b/iconvdata/testdata/CP1250 new file mode 100644 index 0000000000..0dc708da43 --- /dev/null +++ b/iconvdata/testdata/CP1250 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + + + + + + + + diff --git a/iconvdata/testdata/CP1250..UTF8 b/iconvdata/testdata/CP1250..UTF8 new file mode 100644 index 0000000000..0c80ff7dbf --- /dev/null +++ b/iconvdata/testdata/CP1250..UTF8 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + ‚ „ … † ‡ ‰ Š ‹ Ś Ť Ž Ź + ‘ ’ “ ” • – — ™ š › ś ť ž ź + ˇ ˘ Ł ¤ Ą ¦ § ¨ © Ş « ¬ ® Ż + ° ± ˛ ł ´ µ ¶ · ¸ ą ş » Ľ ˝ ľ ż + Ŕ Á Â Ă Ä Ĺ Ć Ç Č É Ę Ë Ě Í Î Ď + Đ Ń Ň Ó Ô Ő Ö × Ř Ů Ú Ű Ü Ý Ţ ß + ŕ á â ă ä ĺ ć ç č é ę ë ě í î ď + đ ń ň ó ô ő ö ÷ ř ů ú ű ü ý ţ ˙ diff --git a/iconvdata/testdata/CP1251 b/iconvdata/testdata/CP1251 new file mode 100644 index 0000000000..866d8f5a10 --- /dev/null +++ b/iconvdata/testdata/CP1251 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + + + + + + + + diff --git a/iconvdata/testdata/CP1251..UTF8 b/iconvdata/testdata/CP1251..UTF8 new file mode 100644 index 0000000000..ba62067bf9 --- /dev/null +++ b/iconvdata/testdata/CP1251..UTF8 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + Ђ Ѓ ‚ ѓ „ … † ‡ ‰ Љ ‹ Њ Ќ Ћ Џ + ђ ‘ ’ “ ” • – — ™ љ › њ ќ ћ џ + Ў ў Ј ¤ Ґ ¦ § Ё © Є « ¬ ® Ї + ° ± І і ґ µ ¶ · ё № є » ј Ѕ ѕ ї + А Б В Г Д Е Ж З И Й К Л М Н О П + Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я + а б в г д е ж з и й к л м н о п + р с т у ф х ц ч ш щ ъ ы ь э ю я diff --git a/iconvdata/testdata/CP1252 b/iconvdata/testdata/CP1252 new file mode 100644 index 0000000000..4720665a85 --- /dev/null +++ b/iconvdata/testdata/CP1252 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + + + + + + + + diff --git a/iconvdata/testdata/CP1252..UTF8 b/iconvdata/testdata/CP1252..UTF8 new file mode 100644 index 0000000000..420dd2391c --- /dev/null +++ b/iconvdata/testdata/CP1252..UTF8 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ + ‘ ’ “ ” • – — ˜ ™ š › œ Ÿ + ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ + ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ + À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï + Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß + à á â ã ä å æ ç è é ê ë ì í î ï + ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ diff --git a/iconvdata/testdata/CP1253 b/iconvdata/testdata/CP1253 new file mode 100644 index 0000000000..ede3a9a093 --- /dev/null +++ b/iconvdata/testdata/CP1253 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + + + + + + + + diff --git a/iconvdata/testdata/CP1253..UTF8 b/iconvdata/testdata/CP1253..UTF8 new file mode 100644 index 0000000000..36d9b2f561 --- /dev/null +++ b/iconvdata/testdata/CP1253..UTF8 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + ‚ ƒ „ … † ‡ ‰ ‹ + ‘ ’ “ ” • – — ™ › + ΅ Ά £ ¤ ¥ ¦ § ¨ © « ¬ ® ― + ° ± ² ³ ΄ µ ¶ · Έ Ή Ί » Ό ½ Ύ Ώ + ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο + Π Ρ Σ Τ Υ Φ Χ Ψ Ω Ϊ Ϋ ά έ ή ί + ΰ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο + π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ diff --git a/iconvdata/testdata/CP1254 b/iconvdata/testdata/CP1254 new file mode 100644 index 0000000000..4720665a85 --- /dev/null +++ b/iconvdata/testdata/CP1254 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + + + + + + + + diff --git a/iconvdata/testdata/CP1254..UTF8 b/iconvdata/testdata/CP1254..UTF8 new file mode 100644 index 0000000000..6733f178e3 --- /dev/null +++ b/iconvdata/testdata/CP1254..UTF8 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ + ‘ ’ “ ” • – — ˜ ™ š › œ Ÿ + ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ® ¯ + ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ + À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï + Ğ Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü İ Ş ß + à á â ã ä å æ ç è é ę ë ė í î ī + ğ ñ ò ó ô õ ö ÷ ø ù ú û ü ı ş ÿ diff --git a/iconvdata/testdata/CP1255 b/iconvdata/testdata/CP1255 new file mode 100644 index 0000000000..37af6ad3d1 --- /dev/null +++ b/iconvdata/testdata/CP1255 @@ -0,0 +1,13 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + + + + + + + diff --git a/iconvdata/testdata/CP1255..UTF8 b/iconvdata/testdata/CP1255..UTF8 new file mode 100644 index 0000000000..1ab9b027ae --- /dev/null +++ b/iconvdata/testdata/CP1255..UTF8 @@ -0,0 +1,13 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + ‚ ƒ „ … † ‡ ‰ ‹ + ‘ ’ “ ” • – — ™ › + ¢ £ ¤ ¥ ¦ § ¨ © × « ¬ ® ‾ + ° ± ² ³ ´ µ ¶ · ¸ ¹ ÷ » ¼ ½ ¾ + ‗ + א ב ג ד ה ו ז ח ט י ך כ ל ם מ ן + נ ס ע ף פ ץ צ ק ר ש ת diff --git a/iconvdata/testdata/CP1256 b/iconvdata/testdata/CP1256 new file mode 100644 index 0000000000..08d5d8e971 --- /dev/null +++ b/iconvdata/testdata/CP1256 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + + + + + + + + diff --git a/iconvdata/testdata/CP1256..UTF8 b/iconvdata/testdata/CP1256..UTF8 new file mode 100644 index 0000000000..2dbaf96e19 --- /dev/null +++ b/iconvdata/testdata/CP1256..UTF8 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + ، ٠ ‚ ١ „ … † ‡ ٢ ٣ ٤ ‹ ٥ ٦ ٧ ٨ + ٩ ‘ ’ “ ” • – — ؛ ™ ؟ › ء آ أ Ÿ + ؤ إ £ ¤ ئ ¦ § ا © ب « ¬ ® پ + ° ± ة ت ث µ ¶ · ج چ ح » خ د ذ ر + À ز  ژ س ش ص Ç È É Ê Ë ض ط Î Ï + ㄓ ع غ ـ Ô ف ق × ك Ù گ Û Ü ل م ن + à ه â ځ و ى ي ç è é ê ë ً ٌ î ï + ٍ َ ُ ِ ô ّ ْ ÷ ù û ü ÿ diff --git a/iconvdata/testdata/CP1257 b/iconvdata/testdata/CP1257 new file mode 100644 index 0000000000..e4a3e6b384 --- /dev/null +++ b/iconvdata/testdata/CP1257 @@ -0,0 +1,14 @@ + ! " # $ % & ' ( ) * + , - . / + 0 1 2 3 4 5 6 7 8 9 : ; < = > ? + @ A B C D E F G H I J K L M N O + P Q R S T U V W X Y Z [ \ ] ^ _ + ` a b c d e f g h i j k l m n o + p q r s t u v w x y z { | } ~ + + + + + + + + diff --git a/streams/Makefile b/streams/Makefile index c4c1190933..0b8143aaa1 100644 --- a/streams/Makefile +++ b/streams/Makefile @@ -21,7 +21,7 @@ # subdir := streams -headers = stropts.h bits/stropts.h +headers = stropts.h sys/stropts.h bits/stropts.h routines = isastream getmsg getpmsg putmsg putpmsg fattach fdetach include ../Rules diff --git a/streams/sys/stropts.h b/streams/sys/stropts.h new file mode 100644 index 0000000000..5b5bc02f40 --- /dev/null +++ b/streams/sys/stropts.h @@ -0,0 +1 @@ +#include <stropts.h> diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 9a509384d6..6f13dfe62b 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -82,10 +82,6 @@ sysdep_headers += netinet/in_systm.h netinet/udp.h \ netrom/netrom.h netpacket/packet.h netrose/rose.h endif -ifeq ($(subdir),posix) -sysdep_routines += s_pread64 s_pwrite64 -endif - # Don't compile the ctype glue code, since there is no old non-GNU C library. inhibit-glue = yes diff --git a/sysdeps/unix/sysv/linux/ptsname.c b/sysdeps/unix/sysv/linux/ptsname.c index c81f23504c..2db8f8d08a 100644 --- a/sysdeps/unix/sysv/linux/ptsname.c +++ b/sysdeps/unix/sysv/linux/ptsname.c @@ -101,7 +101,7 @@ __ptsname_r (fd, buf, buflen) idbuf[5] = '\0'; __stpcpy (__stpcpy (nbuf, "/dev/pts/"), - _itoa_word (ptyno, &idbuf[4], 10, 0)); + _itoa_word (ptyno, &idbuf[5], 10, 0)); if (__xstat (_STAT_VER, nbuf, &st) < 0) { if (errno != ENOENT) diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list index 3fcb9a6aef..507fbc35fc 100644 --- a/sysdeps/unix/sysv/linux/syscalls.list +++ b/sysdeps/unix/sysv/linux/syscalls.list @@ -40,19 +40,19 @@ rt_sigprocmask - rt_sigprocmask 4 __syscall_rt_sigprocmask rt_sigqueueinfo - rt_sigqueueinfo 3 __syscall_rt_sigqueueinfo rt_sigsuspend - rt_sigsuspend 2 __syscall_rt_sigsuspend rt_sigtimedwait - rt_sigtimedwait 4 __syscall_rt_sigtimedwait -s_getcwd EXTRA getcwd 2 __syscall_getcwd -s_getdents EXTRA getdents 3 __getdents +s_getcwd getcwd getcwd 2 __syscall_getcwd +s_getdents getdents getdents 3 __getdents s_getpriority getpriority getpriority 2 __syscall_getpriority s_getresgid getresgid getresgid 3 __syscall_getresgid s_getresuid getresuid getresuid 3 __syscall_getresuid s_poll poll poll 3 __syscall_poll -s_pread64 EXTRA pread 5 __syscall_pread64 +s_pread64 pread64 pread 5 __syscall_pread64 s_ptrace ptrace ptrace 4 __syscall_ptrace -s_pwrite64 EXTRA pwrite 5 __syscall_pwrite64 -s_reboot EXTRA reboot 3 __syscall_reboot +s_pwrite64 pwrite64 pwrite 5 __syscall_pwrite64 +s_reboot reboot reboot 3 __syscall_reboot s_sigaction sigaction sigaction 3 __syscall_sigaction -s_sigpending EXTRA sigpending 1 __syscall_sigpending -s_sigprocmask EXTRA sigprocmask 3 __syscall_sigprocmask +s_sigpending sigpending sigpending 1 __syscall_sigpending +s_sigprocmask sigprocmask sigprocmask 3 __syscall_sigprocmask s_sigsuspend sigsuspend sigsuspend 3 __syscall_sigsuspend s_sysctl sysctl _sysctl 1 __syscall__sysctl s_ustat ustat ustat 2 __syscall_ustat diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c new file mode 100644 index 0000000000..7f276b6130 --- /dev/null +++ b/sysdeps/unix/sysv/linux/ttyname.c @@ -0,0 +1,152 @@ +/* Copyright (C) 1991, 92, 93, 96, 97, 98 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <errno.h> +#include <limits.h> +#include <stddef.h> +#include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> + +char *__ttyname = NULL; + +static char * getttyname __P ((const char *dev, int fd, dev_t mydev, + ino_t myino, int save, int *dostat)) + internal_function; + +static char * +internal_function +getttyname (dev, fd, mydev, myino, save, dostat) + const char *dev; + int fd; + dev_t mydev; + ino_t myino; + int save; + int *dostat; +{ + static char *name; + static size_t namelen = 0; + struct stat st; + DIR *dirstream; + struct dirent *d; + size_t devlen = strlen (dev) + 1; + + dirstream = opendir (dev); + if (dirstream == NULL) + { + *dostat = -1; + return NULL; + } + + while ((d = readdir (dirstream)) != NULL) + if (((ino_t) d->d_fileno == myino || *dostat) + && strcmp (d->d_name, "stdin") + && strcmp (d->d_name, "stdout") + && strcmp (d->d_name, "stderr")) + { + size_t dlen = _D_ALLOC_NAMLEN (d); + if (devlen + dlen > namelen) + { + free (name); + namelen = 2 * (devlen + dlen); /* Big enough. */ + name = malloc (namelen); + if (! name) + { + *dostat = -1; + /* Perhaps it helps to free the directory stream buffer. */ + (void) closedir (dirstream); + return NULL; + } + *((char *) __mempcpy (name, dev, devlen - 1)) = '/'; + } + memcpy (&name[devlen], d->d_name, dlen); + if (stat (name, &st) == 0 +#ifdef _STATBUF_ST_RDEV + && S_ISCHR (st.st_mode) && st.st_rdev == mydev +#else + && (ino_t) d->d_fileno == myino && st.st_dev == mydev +#endif + ) + { + (void) closedir (dirstream); + __ttyname = name; + __set_errno (save); + return name; + } + } + + (void) closedir (dirstream); + __set_errno (save); + return NULL; +} + +/* Return the pathname of the terminal FD is open on, or NULL on errors. + The returned storage is good only until the next call to this function. */ +char * +ttyname (fd) + int fd; +{ + struct stat st, st1; + int dostat = 0; + char *name; + int save = errno; + + if (!__isatty (fd)) + return NULL; + + if (fstat (fd, &st) < 0) + return NULL; + + if (stat ("/dev/pts", &st1) == 0 && S_ISDIR (st1.st_mode)) + { +#ifdef _STATBUF_ST_RDEV + name = getttyname ("/dev/pts", fd, st.st_rdev, st.st_ino, save, &dostat); +#else + name = getttyname ("/dev/pts", fd, st.st_dev, st.st_ino, save, &dostat); +#endif + } + else + { + __set_errno (save); + name = NULL; + } + + if (!name && dostat != -1) + { +#ifdef _STATBUF_ST_RDEV + name = getttyname ("/dev", fd, st.st_rdev, st.st_ino, save, &dostat); +#else + name = getttyname ("/dev", fd, st.st_dev, st.st_ino, save, &dostat); +#endif + } + + if (!name && dostat != -1) + { + dostat = 1; +#ifdef _STATBUF_ST_RDEV + name = getttyname ("/dev", fd, st.st_rdev, st.st_ino, save, &dostat); +#else + name = getttyname ("/dev", fd, st.st_dev, st.st_ino, save, &dostat); +#endif + } + + return name; +} diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c new file mode 100644 index 0000000000..9f22f71f31 --- /dev/null +++ b/sysdeps/unix/sysv/linux/ttyname_r.c @@ -0,0 +1,182 @@ +/* Copyright (C) 1991, 92, 93, 95, 96, 97, 98 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include <errno.h> +#include <limits.h> +#include <stddef.h> +#include <dirent.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include <string.h> +#include <stdlib.h> + +static int getttyname_r __P ((int fd, char *buf, size_t buflen, + dev_t mydev, ino_t myino, int save, + int *dostat)) internal_function; + +static int +internal_function +getttyname_r (fd, buf, buflen, mydev, myino, save, dostat) + int fd; + char *buf; + size_t buflen; + dev_t mydev; + ino_t myino; + int save; + int *dostat; +{ + struct stat st; + DIR *dirstream; + struct dirent *d; + size_t devlen = strlen (buf); + + dirstream = opendir (buf); + if (dirstream == NULL) + { + *dostat = -1; + return errno; + } + + while ((d = readdir (dirstream)) != NULL) + if (((ino_t) d->d_fileno == myino || *dostat) + && strcmp (d->d_name, "stdin") + && strcmp (d->d_name, "stdout") + && strcmp (d->d_name, "stderr")) + { + char *cp; + size_t needed = _D_EXACT_NAMLEN (d) + 1; + + if (needed > buflen) + { + *dostat = -1; + (void) closedir (dirstream); + __set_errno (ERANGE); + return ERANGE; + } + + cp = __stpncpy (buf + devlen, d->d_name, needed); + cp[0] = '\0'; + + if (stat (buf, &st) == 0 +#ifdef _STATBUF_ST_RDEV + && S_ISCHR (st.st_mode) && st.st_rdev == mydev +#else + && (ino_t) d->d_fileno == myino && st.st_dev == mydev +#endif + ) + { + (void) closedir (dirstream); + __set_errno (save); + return 0; + } + } + + (void) closedir (dirstream); + __set_errno (save); + /* It is not clear what to return in this case. `isatty' says FD + refers to a TTY but no entry in /dev has this inode. */ + return ENOTTY; +} + +/* Store at most BUFLEN character of the pathname of the terminal FD is + open on in BUF. Return 0 on success, otherwise an error number. */ +int +__ttyname_r (fd, buf, buflen) + int fd; + char *buf; + size_t buflen; +{ + struct stat st, st1; + int dostat = 0; + int save = errno; + int ret; + + /* Test for the absolute minimal size. This makes life easier inside + the loop. */ + if (!buf) + { + __set_errno (EINVAL); + return EINVAL; + } + + if (buflen < sizeof ("/dev/pts/")) + { + __set_errno (ERANGE); + return ERANGE; + } + + if (!__isatty (fd)) + { + __set_errno (ENOTTY); + return ENOTTY; + } + + if (fstat (fd, &st) < 0) + return errno; + + /* Prepare the result buffer. */ + memcpy (buf, "/dev/pts/", sizeof ("/dev/pts/")); + buflen -= sizeof ("/dev/pts/") - 1; + + if (stat (buf, &st1) == 0 && S_ISDIR (st1.st_mode)) + { +#ifdef _STATBUF_ST_RDEV + ret = getttyname_r (fd, buf, buflen, st.st_rdev, st.st_ino, save, + &dostat); +#else + ret = getttyname_r (fd, buf, buflen, st.st_dev, st.st_ino, save, + &dostat); +#endif + } + else + { + __set_errno (save); + ret = ENOENT; + } + + if (ret && dostat != -1) + { + buf[sizeof ("/dev/") - 1] = '\0'; + buflen += sizeof ("pts/") - 1; +#ifdef _STATBUF_ST_RDEV + ret = getttyname_r (fd, buf, buflen, st.st_rdev, st.st_ino, save, + &dostat); +#else + ret = getttyname_r (fd, buf, buflen, st.st_dev, st.st_ino, save, + &dostat); +#endif + } + + if (ret && dostat != -1) + { + buf[sizeof ("/dev/") - 1] = '\0'; + dostat = 1; +#ifdef _STATBUF_ST_RDEV + ret = getttyname_r (fd, buf, buflen, st.st_rdev, st.st_ino, + save, &dostat); +#else + ret = getttyname_r (fd, buf, buflen, st.st_dev, st.st_ino, + save, &dostat); +#endif + } + + return ret; +} + +weak_alias (__ttyname_r, ttyname_r) |