From: Waldemar Kozaczuk <[email protected]>
Committer: Nadav Har'El <[email protected]>
Branch: master

libc: replace unistd/ttyname.c with the musl copy

This patch eliminates one more file - unistd/ttyname.c - that is
identical with the musl copy except for extra 'memset(buf, 0, sizeof(buf));' 
line
which does not seem necessary. There is already existing unit test that
verifies ttyname() and ttyname_r() behavior.

This patch also cleans up OSv specific implementation of
ttyname_r() - removes '\0' from a string and unnecessary return -
per original review of Rean's patch.

Finally, this patch effectively makes all files (*.c,*.cc) under libc/unistd/ 
"neutral"
to future musl upgrades.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
Message-Id: <[email protected]>

---
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1680,7 +1680,7 @@ libc += unistd/getppid.o
 libc += unistd/getsid.o
 libc += unistd/setsid.o
 libc += unistd/ttyname_r.o
-libc += unistd/ttyname.o
+musl += unistd/ttyname.o
 musl += unistd/tcgetpgrp.o
 musl += unistd/tcsetpgrp.o
 musl += unistd/setpgrp.o
diff --git a/libc/unistd/ttyname.c b/libc/unistd/ttyname.c
--- a/libc/unistd/ttyname.c
+++ b/libc/unistd/ttyname.c
@@ -1,16 +0,0 @@
-#include <unistd.h>
-#include <errno.h>
-#include <limits.h>
-#include <memory.h>
-
-char* ttyname(int fd)
-{
-   static char buf[TTY_NAME_MAX];
-   memset(buf, 0, sizeof(buf));
-   int result;
-   if ((result = ttyname_r(fd, buf, sizeof(buf)))) {
-      errno = result;
-      return NULL;
-   }
-   return buf;
-}
diff --git a/libc/unistd/ttyname_r.c b/libc/unistd/ttyname_r.c
--- a/libc/unistd/ttyname_r.c
+++ b/libc/unistd/ttyname_r.c
@@ -10,7 +10,7 @@ int ttyname_r(int fd, char *buf, size_t buflen)
    }
    // OSv doesn't support any virtual terminals or ptys so return
    // the fixed pathname of /dev/console
-   char* ttyname = "/dev/console\0";
+   char* ttyname = "/dev/console";
    size_t len = strlen(ttyname);
    if (!isatty(fd)) {
       return ENOTTY;
@@ -25,5 +25,4 @@ int ttyname_r(int fd, char *buf, size_t buflen)
          return 0;
       }
    }
-   return 0;
 }

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/0000000000002e44a505abf35617%40google.com.

Reply via email to