from scratch; add Berkeley specific header
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 1 Sep 1988 13:55:47 +0000 (05:55 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 1 Sep 1988 13:55:47 +0000 (05:55 -0800)
SCCS-vsn: lib/libc/gen/ttyslot.c 5.3
SCCS-vsn: lib/libc/gen/isatty.c 5.3

usr/src/lib/libc/gen/isatty.c
usr/src/lib/libc/gen/ttyslot.c

index fab1fd9..fc7c121 100644 (file)
@@ -1,18 +1,30 @@
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)isatty.c   5.2 (Berkeley) %G%";
-#endif LIBC_SCCS and not lint
-
 /*
 /*
- * Returns 1 iff file is a tty
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  */
 
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)isatty.c   5.3 (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
 #include <sgtty.h>
 
 #include <sgtty.h>
 
-isatty(f)
+isatty(fd)
+       int fd;
 {
        struct sgttyb ttyb;
 
 {
        struct sgttyb ttyb;
 
-       if (ioctl(f, TIOCGETP, &ttyb) < 0)
-               return(0);
-       return(1);
+       return(ioctl(fd, TIOCGETP, &ttyb) >= 0);
 }
 }
index 05d2ea3..de1081b 100644 (file)
@@ -1,48 +1,48 @@
 /*
 /*
- * Copyright (c) 1984 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)ttyslot.c  5.2 (Berkeley) %G%";
-#endif LIBC_SCCS and not lint
+static char sccsid[] = "@(#)ttyslot.c  5.3 (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
 
 
-/*
- * Return the number of the slot in the utmp file
- * corresponding to the current user: try for file 0, 1, 2.
- * Definition is the line number in the /etc/ttys file.
- */
 #include <ttyent.h>
 #include <ttyent.h>
-
-char   *ttyname();
-char   *rindex();
-
-#define        NULL    0
+#include <stdio.h>
 
 ttyslot()
 {
 
 ttyslot()
 {
-       register struct ttyent *ty;
-       register char *tp, *p;
-       register s;
+       register struct ttyent *ttyp;
+       register int slot;
+       register char *p;
+       int cnt;
+       char *name, *rindex(), *ttyname();
 
 
-       if ((tp = ttyname(0)) == NULL &&
-           (tp = ttyname(1)) == NULL &&
-           (tp = ttyname(2)) == NULL)
-               return(0);
-       if ((p = rindex(tp, '/')) == NULL)
-               p = tp;
-       else
-               p++;
-       setttyent();
-       s = 0;
-       while ((ty = getttyent()) != NULL) {
-               s++;
-               if (strcmp(ty->ty_name, p) == 0) {
-                       endttyent();
-                       return (s);
+       for (cnt = 0; cnt < 3; ++cnt) 
+               if (name = ttyname(cnt)) {
+                       if (p = rindex(name, '/')) 
+                               ++p;
+                       else
+                               p = name;
+                       for (slot = 1; ttyp = getttyent(); ++slot)
+                               if (!strcmp(ttyp->ty_name, p)) {
+                                       endttyent();
+                                       return(slot);
+                               }
+                       break;
                }
                }
-       }
        endttyent();
        endttyent();
-       return (0);
+       return(0);
 }
 }