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]> --- Makefile | 2 +- libc/unistd/ttyname.c | 16 ---------------- libc/unistd/ttyname_r.c | 3 +-- 3 files changed, 2 insertions(+), 19 deletions(-) delete mode 100644 libc/unistd/ttyname.c diff --git a/Makefile b/Makefile index 62e832c7..cd490a76 100644 --- 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 deleted file mode 100644 index 3fa71b29..00000000 --- a/libc/unistd/ttyname.c +++ /dev/null @@ -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 index 0bdba2b7..0ecf4f1d 100644 --- 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; } -- 2.26.2 -- 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/20200802224819.55935-1-jwkozaczuk%40gmail.com.
