Skip to content

Commit

Permalink
LibC: Add ctermid
Browse files Browse the repository at this point in the history
We simply return "/dev/tty", since it always refers to the controlling
terminal of the calling process.
  • Loading branch information
en0mem authored and awesomekling committed Jun 18, 2022
1 parent 5b1e2cc commit f34e69a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Userland/Libraries/LibC/stdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,15 @@ FILE* tmpfile()
return fdopen(fd, "rw");
}

// https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctermid.html
char* ctermid(char* s)
{
static char tty_path[L_ctermid] = "/dev/tty";
if (s)
return strcpy(s, tty_path);
return tty_path;
}

size_t __fpending(FILE* stream)
{
ScopedFileLock lock(stream);
Expand Down
2 changes: 2 additions & 0 deletions Userland/Libraries/LibC/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ __BEGIN_DECLS
#define _IOLBF 1
#define _IONBF 2

#define L_ctermid 9
#define L_tmpnam 256
#define P_tmpdir "/tmp"

Expand Down Expand Up @@ -99,5 +100,6 @@ FILE* tmpfile(void);
char* tmpnam(char*);
FILE* popen(char const* command, char const* type);
int pclose(FILE*);
char* ctermid(char* s);

__END_DECLS

0 comments on commit f34e69a

Please sign in to comment.