Ejemplo n.º 1
0
static struct serial *
serial_fdopen_ops (const int fd, const struct serial_ops *ops)
{
  struct serial *scb;

  if (!ops)
    {
      ops = serial_interface_lookup ("terminal");
      if (!ops)
 	ops = serial_interface_lookup ("hardwire");
    }

  if (!ops)
    return NULL;

  scb = new_serial (ops);

  scb->next = scb_base;
  scb_base = scb;

  if ((ops->fdopen) != NULL)
    (*ops->fdopen) (scb, fd);
  else
    scb->fd = fd;

  return scb;
}
Ejemplo n.º 2
0
static struct serial *
serial_fdopen_ops (const int fd, const struct serial_ops *ops)
{
  struct serial *scb;

  if (!ops)
    {
      ops = serial_interface_lookup ("terminal");
      if (!ops)
 	ops = serial_interface_lookup ("hardwire");
    }

  if (!ops)
    return NULL;

  scb = XCNEW (struct serial);

  scb->ops = ops;

  scb->bufcnt = 0;
  scb->bufp = scb->buf;
  scb->error_fd = -1;
  scb->refcnt = 1;

  scb->name = NULL;
  scb->next = scb_base;
  scb->debug_p = 0;
  scb->async_state = 0;
  scb->async_handler = NULL;
  scb->async_context = NULL;
  scb_base = scb;

  if ((ops->fdopen) != NULL)
    (*ops->fdopen) (scb, fd);
  else
    scb->fd = fd;

  return scb;
}
Ejemplo n.º 3
0
struct serial *
serial_open (const char *name)
{
  const struct serial_ops *ops;
  const char *open_name = name;

  if (startswith (name, "|"))
    {
      ops = serial_interface_lookup ("pipe");
      /* Discard ``|'' and any space before the command itself.  */
      ++open_name;
      open_name = skip_spaces (open_name);
    }
  /* Check for a colon, suggesting an IP address/port pair.
     Do this *after* checking for all the interesting prefixes.  We
     don't want to constrain the syntax of what can follow them.  */
  else if (strchr (name, ':'))
    ops = serial_interface_lookup ("tcp");
  else
    {
#ifndef USE_WIN32API
      /* Check to see if name is a socket.  If it is, then treat it
         as such.  Otherwise assume that it's a character device.  */
      struct stat sb;
      if (stat (name, &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFSOCK)
	ops = serial_interface_lookup ("local");
      else
#endif
	ops = serial_interface_lookup ("hardwire");
    }

  if (!ops)
    return NULL;

  return serial_open_ops_1 (ops, open_name);
}
Ejemplo n.º 4
0
int
serial_pipe (struct serial *scbs[2])
{
  const struct serial_ops *ops;
  int fildes[2];

  ops = serial_interface_lookup ("pipe");
  if (!ops)
    {
      errno = ENOSYS;
      return -1;
    }

  if (gdb_pipe (fildes) == -1)
    return -1;

  scbs[0] = serial_fdopen_ops (fildes[0], ops);
  scbs[1] = serial_fdopen_ops (fildes[1], ops);
  return 0;
}
Ejemplo n.º 5
0
Archivo: serial.c Proyecto: 0mp/freebsd
struct serial *
serial_fdopen (const int fd)
{
  struct serial *scb;
  struct serial_ops *ops;

  for (scb = scb_base; scb; scb = scb->next)
    if (scb->fd == fd)
      {
	scb->refcnt++;
	return scb;
      }

  ops = serial_interface_lookup ("hardwire");

  if (!ops)
    return NULL;

  scb = XMALLOC (struct serial);

  scb->ops = ops;

  scb->bufcnt = 0;
  scb->bufp = scb->buf;

  scb->fd = fd;

  scb->name = NULL;
  scb->next = scb_base;
  scb->refcnt = 1;
  scb->debug_p = 0;
  scb->async_state = 0;
  scb->async_handler = NULL;
  scb->async_context = NULL;
  scb_base = scb;

  last_serial_opened = scb;

  return scb;
}
Ejemplo n.º 6
0
struct serial *
serial_open (const char *name)
{
  struct serial *scb;
  const struct serial_ops *ops;
  const char *open_name = name;

  if (strcmp (name, "pc") == 0)
    ops = serial_interface_lookup ("pc");
  else if (startswith (name, "lpt"))
    ops = serial_interface_lookup ("parallel");
  else if (startswith (name, "|"))
    {
      ops = serial_interface_lookup ("pipe");
      /* Discard ``|'' and any space before the command itself.  */
      ++open_name;
      open_name = skip_spaces_const (open_name);
    }
  /* Check for a colon, suggesting an IP address/port pair.
     Do this *after* checking for all the interesting prefixes.  We
     don't want to constrain the syntax of what can follow them.  */
  else if (strchr (name, ':'))
    ops = serial_interface_lookup ("tcp");
  else
    ops = serial_interface_lookup ("hardwire");

  if (!ops)
    return NULL;

  scb = XNEW (struct serial);

  scb->ops = ops;

  scb->bufcnt = 0;
  scb->bufp = scb->buf;
  scb->error_fd = -1;
  scb->refcnt = 1;

  /* `...->open (...)' would get expanded by the open(2) syscall macro.  */
  if ((*scb->ops->open) (scb, open_name))
    {
      xfree (scb);
      return NULL;
    }

  scb->name = xstrdup (name);
  scb->next = scb_base;
  scb->debug_p = 0;
  scb->async_state = 0;
  scb->async_handler = NULL;
  scb->async_context = NULL;
  scb_base = scb;

  if (serial_logfile != NULL)
    {
      serial_logfp = gdb_fopen (serial_logfile, "w");
      if (serial_logfp == NULL)
	perror_with_name (serial_logfile);
    }

  return scb;
}
Ejemplo n.º 7
0
Archivo: serial.c Proyecto: 0mp/freebsd
struct serial *
serial_open (const char *name)
{
  struct serial *scb;
  struct serial_ops *ops;
  const char *open_name = name;

  for (scb = scb_base; scb; scb = scb->next)
    if (scb->name && strcmp (scb->name, name) == 0)
      {
	scb->refcnt++;
	return scb;
      }

  if (strcmp (name, "pc") == 0)
    ops = serial_interface_lookup ("pc");
  else if (strchr (name, ':'))
    ops = serial_interface_lookup ("tcp");
  else if (strncmp (name, "lpt", 3) == 0)
    ops = serial_interface_lookup ("parallel");
  else if (strncmp (name, "|", 1) == 0)
    {
      ops = serial_interface_lookup ("pipe");
      open_name = name + 1; /* discard ``|'' */
    }
  else
    ops = serial_interface_lookup ("hardwire");

  if (!ops)
    return NULL;

  scb = XMALLOC (struct serial);

  scb->ops = ops;

  scb->bufcnt = 0;
  scb->bufp = scb->buf;

  if (scb->ops->open (scb, open_name))
    {
      xfree (scb);
      return NULL;
    }

  scb->name = xstrdup (name);
  scb->next = scb_base;
  scb->refcnt = 1;
  scb->debug_p = 0;
  scb->async_state = 0;
  scb->async_handler = NULL;
  scb->async_context = NULL;
  scb_base = scb;

  last_serial_opened = scb;

  if (serial_logfile != NULL)
    {
      serial_logfp = gdb_fopen (serial_logfile, "w");
      if (serial_logfp == NULL)
	perror_with_name (serial_logfile);
    }

  return scb;
}