Back to index

glibc  2.9
Functions
pty.h File Reference
#include <features.h>
#include <termios.h>
#include <sys/ioctl.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

__BEGIN_DECLS int openpty (int *__amaster, int *__aslave, char *__name, const struct termios *__termp, const struct winsize *__winp) __THROW
int forkpty (int *__amaster, char *__name, const struct termios *__termp, const struct winsize *__winp) __THROW

Function Documentation

int forkpty ( int __amaster,
char *  __name,
const struct termios __termp,
const struct winsize __winp 
)

Definition at line 27 of file forkpty.c.

{
  int master, slave, pid;

  if (openpty (&master, &slave, name, termp, winp) == -1)
    return -1;

  switch (pid = fork ())
    {
    case -1:
      close (master);
      close (slave);
      return -1;
    case 0:
      /* Child.  */
      close (master);
      if (login_tty (slave))
       _exit (1);

      return 0;
    default:
      /* Parent.  */
      *amaster = master;
      close (slave);

      return pid;
    }
}

Here is the call graph for this function:

__BEGIN_DECLS int openpty ( int __amaster,
int __aslave,
char *  __name,
const struct termios __termp,
const struct winsize __winp 
)

Definition at line 87 of file openpty.c.

{
#ifdef PATH_MAX
  char _buf[PATH_MAX];
#else
  char _buf[512];
#endif
  char *buf = _buf;
  int master, slave;

  master = getpt ();
  if (master == -1)
    return -1;

  if (grantpt (master))
    goto fail;

  if (unlockpt (master))
    goto fail;

  if (pts_name (master, &buf, sizeof (_buf)))
    goto fail;

  slave = open (buf, O_RDWR | O_NOCTTY);
  if (slave == -1)
    {
      if (buf != _buf)
       free (buf);

      goto fail;
    }

  /* XXX Should we ignore errors here?  */
  if(termp)
    tcsetattr (slave, TCSAFLUSH, termp);
  if (winp)
    ioctl (slave, TIOCSWINSZ, winp);

  *amaster = master;
  *aslave = slave;
  if (name != NULL)
    strcpy (name, buf);

  if (buf != _buf)
    free (buf);
  return 0;

 fail:
  close (master);
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function: