summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/lib/ttyname.c
diff options
context:
space:
mode:
authorGwenolé Beauchesne <gbeauchesne@mandriva.org>2003-06-04 18:31:57 +0000
committerGwenolé Beauchesne <gbeauchesne@mandriva.org>2003-06-04 18:31:57 +0000
commit09e967c2d732783b2579e4e120cd9b608404cb00 (patch)
tree8d2783a6a7e33608c6012efd6a88b8f5694df81d /mdk-stage1/dietlibc/lib/ttyname.c
parent18fcff49d3c836697d3b75a3d01d31c700e69974 (diff)
downloaddrakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar
drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.gz
drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.bz2
drakx-09e967c2d732783b2579e4e120cd9b608404cb00.tar.xz
drakx-09e967c2d732783b2579e4e120cd9b608404cb00.zip
Merge from R9_0-AMD64, most notably:
- AMD64 support to insmod-busybox, minilibc, et al. - Sync with insmod-modutils 2.4.19 something but everyone should use dietlibc nowadays - Factor out compilation and prefix with $(DIET) for dietlibc builds - 64-bit & varargs fixes
Diffstat (limited to 'mdk-stage1/dietlibc/lib/ttyname.c')
-rw-r--r--mdk-stage1/dietlibc/lib/ttyname.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/mdk-stage1/dietlibc/lib/ttyname.c b/mdk-stage1/dietlibc/lib/ttyname.c
index a6b479088..2bbc7f2a9 100644
--- a/mdk-stage1/dietlibc/lib/ttyname.c
+++ b/mdk-stage1/dietlibc/lib/ttyname.c
@@ -1,30 +1,35 @@
#include "dietfeatures.h"
#include <unistd.h>
#include <sys/stat.h>
+#include <string.h>
#ifdef __linux__
-extern int __ltostr(char *s, int size, unsigned long i, int base, char UpCase);
+#include <stdlib.h>
char *ttyname(int fd) {
#ifdef SLASH_PROC_OK
char ibuf[20];
static char obuf[20];
+ int len;
+ if (!isatty(fd)) return 0;
strcpy(ibuf,"/proc/self/fd/");
- ibuf[__ltostr(ibuf+14,6,fd,10,0)+14]=0;
- if (readlink(ibuf,obuf,sizeof(obuf)-1)<0) return 0;
+ ibuf[__ltostr(ibuf+14,6,(unsigned long)fd,10,0)+14]=0;
+ if ((len=readlink(ibuf,obuf,sizeof(obuf)-1))<0) return 0;
+ obuf[len]=0;
return obuf;
#else
- static char buf[20]="/dev/tty";
+ static char buf[20];
struct stat s;
char *c=buf+8;
int n;
+ if (!isatty(fd)) return 0;
if (fstat(fd,&s)) return 0;
+ strcpy(buf,"/dev/tty");
if (S_ISCHR(s.st_mode)) {
n=minor(s.st_rdev);
switch (major(s.st_rdev)) {
case 4:
- buf[5]='t'; buf[7]='y';
if (n>63) {
n-=64;
*c='S';
@@ -34,16 +39,18 @@ num:
c[__ltostr(c,6,n,10,0)]=0;
break;
case 2:
- buf[5]='p'; buf[7]='y';
buf[8]='p'-(n>>4);
buf[9]=n%4+'0';
if (buf[9]>'9') *c+='a'-'0';
buf[10]=0;
+ goto duh;
case 136:
case 137:
case 138:
case 139:
- buf[5]='p'; buf[7]='s';
+ buf[7]='s';
+duh:
+ buf[5]='p';
n+=(major(s.st_rdev)-136)<<8;
*c='/'; ++c;
goto num;