public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* sys/stropts.h
@ 2020-03-04 14:26 stratus
  2020-03-04 17:24 ` sys/stropts.h Adhemerval Zanella
  0 siblings, 1 reply; 4+ messages in thread
From: stratus @ 2020-03-04 14:26 UTC (permalink / raw)
  To: libc-help

Dear GLIBC,
I just noticed sys/stropts.h has been removed. I was using a function closely derived from the GLIBC manual example, line 640 here which will need updating:
https://github.com/zqqw/consolelogga/blob/master/src/consolelogga.c

The new manual example seems to indicate the affected part can be deleted, and it seems to be only an error check that is probably not essential.
Is that correct, can I safely delete this part? I think it should be fine I guess.
  if (isastream (slave))
    {
      if (ioctl (slave, I_PUSH, "ptem") < 0
          || ioctl (slave, I_PUSH, "ldterm") < 0)
        goto close_slave;
    }

But also, when I was looking at the new example in the manual, I noticed there was a small oversight - the close_slave: goto tag is now unused.

https://www.gnu.org/software/libc/manual/html_node/Allocation.html#index-getpt
int
open_pty_pair (int *amaster, int *aslave)
{
  int master, slave;
  char *name;

  master = getpt ();
  if (master < 0)
    return 0;

  if (grantpt (master) < 0 || unlockpt (master) < 0)
    goto close_master;
  name = ptsname (master);
  if (name == NULL)
    goto close_master;

  slave = open (name, O_RDWR);
  if (slave == -1)
    goto close_master;

  *amaster = master;
  *aslave = slave;
  return 1;

close_slave:
  close (slave);

close_master:
  close (master);
  return 0;
}


Old version:
int
open_pty_pair (int *amaster, int *aslave)
{
  int master, slave;
  char *name;

  master = getpt ();
  if (master < 0)
    return 0;

  if (grantpt (master) < 0 || unlockpt (master) < 0)
    goto close_master;
  name = ptsname (master);
  if (name == NULL)
    goto close_master;

  slave = open (name, O_RDWR);
  if (slave == -1)
    goto close_master;

  if (isastream (slave))
    {
      if (ioctl (slave, I_PUSH, "ptem") < 0
          || ioctl (slave, I_PUSH, "ldterm") < 0)
        goto close_slave;
    }

  *amaster = master;
  *aslave = slave;
  return 1;

close_slave:
  close (slave);

close_master:
  close (master);
  return 0;
}

Yours sincerely,
zqqw.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-04 18:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-04 14:26 sys/stropts.h stratus
2020-03-04 17:24 ` sys/stropts.h Adhemerval Zanella
2020-03-04 17:55   ` sys/stropts.h Florian Weimer
2020-03-04 18:09     ` sys/stropts.h Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).