This commit is contained in:
parent
56eb0c8130
commit
15d5f00cd3
@ -23,10 +23,13 @@ void signal_handler(int signo)
|
|||||||
|
|
||||||
char* getpass()
|
char* getpass()
|
||||||
{
|
{
|
||||||
FILE* f = fopen("/dev/tty", "r");
|
char ctty[L_ctermid];
|
||||||
|
ctermid(ctty);
|
||||||
|
|
||||||
|
FILE* f = fopen(ctty, "r");
|
||||||
if (!f)
|
if (!f)
|
||||||
{
|
{
|
||||||
perror("Failed to open /dev/tty");
|
perror("Failed to open controlling terminal");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#define FOPEN_MAX 64 // Make sure this value matches FD_MAX in the kernel source.
|
#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
|
typedef struct
|
||||||
{
|
{
|
||||||
int _fd; // The underlying file descriptor.
|
int _fd; // The underlying file descriptor.
|
||||||
@ -206,6 +208,9 @@ extern "C"
|
|||||||
/* Pipe a stream to or from a process. */
|
/* Pipe a stream to or from a process. */
|
||||||
FILE* popen(const char* command, const char* type);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -851,4 +851,15 @@ extern "C"
|
|||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* ctermid(char* s)
|
||||||
|
{
|
||||||
|
static char path[] = "/dev/tty";
|
||||||
|
if (s)
|
||||||
|
{
|
||||||
|
strncpy(s, path, L_ctermid);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user