libc: Add ctermid
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-10-15 11:09:08 +02:00
parent 56eb0c8130
commit 15d5f00cd3
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 21 additions and 2 deletions

View File

@ -23,10 +23,13 @@ void signal_handler(int signo)
char* getpass()
{
FILE* f = fopen("/dev/tty", "r");
char ctty[L_ctermid];
ctermid(ctty);
FILE* f = fopen(ctty, "r");
if (!f)
{
perror("Failed to open /dev/tty");
perror("Failed to open controlling terminal");
return nullptr;
}

View File

@ -12,6 +12,8 @@
#define FOPEN_MAX 64 // Make sure this value matches FD_MAX in the kernel source.
#define L_ctermid 9 // /dev/tty + a NULL byte
typedef struct
{
int _fd; // The underlying file descriptor.
@ -206,6 +208,9 @@ extern "C"
/* Pipe a stream to or from a process. */
FILE* popen(const char* command, const char* type);
/* Return the path of the process's controlling terminal (always /dev/tty on Luna). */
char* ctermid(char* s);
#ifdef __cplusplus
}
#endif

View File

@ -851,4 +851,15 @@ extern "C"
return status;
}
char* ctermid(char* s)
{
static char path[] = "/dev/tty";
if (s)
{
strncpy(s, path, L_ctermid);
return s;
}
return path;
}
}