This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

isastream


Hi,

Right now, we only provide a stub implementation of the `isastream'
function, since all supported systems do not have STREAMS.
However, since these systems do not have STREAMS, we could alse
implement isastream to always return 0 (indicating that the
file is not STREAMS based).  This would be convenient in writing
portable programs that want to open pseudo terminals, because it would
enable programmers to write something like:

  int master, slave;
  char *pts;

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

  if (grantpt (master) < 0)
    return -1;

  if (unlockpt (master) < 0)
    return -1;

  pts = ptsname (master)
  if (pts == NULL)
    return -1;

  slave = open (pts, O_RDWR);
  if (slave < 0)
    return -1;

#if HAVE_STROPTS_H
# if HAVE_ISASTREAM
  if (isastream (slave) == 1)
# endif
  {
    if (ioctl (slave, I_PUSH, "ldterm") < 0)
      return -1;

    /* Do more STREAMS magic if necessary.  */
  }
#endif

Right now this does not work because we provide <stropts.h>, so
HAVE_STROPTS_H would be defined to 1, but we have a stub isastream, so
HAVE_ISASTREAM would not be defined.

The only problem is that according to Unix98, isastream will with
EBADF if an invalid file descriptor is passed.  On POSIX systems this
could be arranged for example by having isastream call

  fcntl (fd, F_GETFD, &flags);

but maybe there is a better way.

Anyway, if nobody has any objections, I will write such an isastream
implementation and post it to the list in a few days.

Mark


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]