[comp.sys.hp] FIONREAD under HP/UX ioctl

garrett@udel.EDU (Joel Garrett) (12/17/87)

Trying to convert this code we have is really starting to look pretty dismal.
We seem to have fixed up the AF_UNIX problem with sockets, but are now stuck
on several ioctl calls.  We need to make a call similar to the BSD FIONREAD
which returns the number of characters in the input buffer of the given file
descriptor.  Unfortunately, according to the HP/UX docs (in parenthesized fine
print at the end of the termio section, I might add) this call is not available.
Would anyone know of a work-around for this or is it time to punt?

					Joel J. Garrett
					Research Associate
					Center for Composite Materials
					University of Delaware
					Newark, DE  19716

					arpa:  garrett@udel.edu
					or:    garrett@udel-ccm.arpa

decot@hpisod2.HP.COM (Dave Decot) (12/18/87)

> Trying to convert this code we have is really starting to look pretty
> dismal.  We seem to have fixed up the AF_UNIX problem with sockets, but
> are now stuck on several ioctl calls.  We need to make a call similar to
> the BSD FIONREAD which returns the number of characters in the input
> buffer of the given file descriptor.  Unfortunately, according to the
> HP/UX docs (in parenthesized fine print at the end of the termio
> section, I might add) this call is not available.  Would anyone know of
> a work-around for this or is it time to punt?
> 
> 					Joel J.  Garrett

FIONREAD is supported in HP-UX on the Series 800.

I assume from your comment that you are using a Series 300.

In this case, you may be able to accomplish your purpose using
the O_NDELAY flag, which is described on open(2) and read(2).

A read() call on a tty file descriptor with O_NDELAY set will
not block if no data is available; it will simply return 0 bytes.

If there is any data available, the read call will read and
return as many bytes as are present or were requested, whichever
is less.  Depending on what the purpose of the ioctl() call you
are porting was, this may be undesirable, tolerable, appropriate,
or even desirable.

See also select(2).

Dave Decot
Hewlett-Packard Company
hpda!decot

clark@killer.UUCP (Clark Brown) (12/19/87)

We have had the same problem trying to get Unisys EMACS to run on the
300.  Neither HP nor Unisys was helpful, so we finally gave up and used
read-and-hang on the keyboard.  Tricks useable on other systems did not
work.

wunder@hpcea.CE.HP.COM (Walter Underwood) (12/22/87)

> We have had the same problem trying to get Unisys EMACS to run on the
> 300.

Well, Unipress sells an Emacs for HP-UX and GNU Emacs works just fine
on HP-UX.  We use it all the time.

> Neither HP nor Unisys was helpful, so we finally gave up and used
> read-and-hang on the keyboard.  Tricks usable on other systems did not
> work.

What "tricks"?  The standard trick on System V is something like this:

      fake_fionread()
      static count
            if count > 0
                return count
            else
                set O_NDELAY
                if we got something on the read
		    count++
                clear O_NDELAY
                return count

Then replace getchar() with something that reads out of the buffer
where you stashed the characters from the read.

Microemacs does this, GNU probably does this, etc.

wunder