#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include <syscalls.h>
int
isatty(int fd)
{
struct termios termios;
return _kern_ioctl(fd, TCGETA, &termios, sizeof(struct termios)) == B_OK;
}
char *
ctermid(char *s)
{
static char defaultBuffer[L_ctermid];
char *name = ttyname(STDOUT_FILENO);
if (s == NULL)
s = defaultBuffer;
return strcpy(s, name ? name : "");
}
int
tcsetpgrp(int fd, pid_t pgrpid)
{
return ioctl(fd, TIOCSPGRP, &pgrpid);
}
pid_t
tcgetpgrp(int fd)
{
pid_t foregroundProcess;
int status = ioctl(fd, TIOCGPGRP, &foregroundProcess);
if (status == 0)
return foregroundProcess;
return -1;
}