stevens@hsi.UUCP (Richard Stevens) (02/05/89)
Is there a "best" way to tell if a given descriptor refers to a streams device ?? I've found that none of the simple ioctl's listed in streamio(7) return the "Not a streams device" (errno=60) error, which is the error message I'd like to get. The poll(2) system call appears to return POLLHUP (hang up) if the descriptor isn't a streams device. The getmsg(2) system call does give you the right error, but you may not want to get a message. I didn't see anything on the stat(2) man page that would give you a clue. Richard Stevens Health Systems International, New Haven, CT stevens@hsi.com ... { uunet | yale } ! hsi ! stevens
guy@auspex.UUCP (Guy Harris) (02/06/89)
>Is there a "best" way to tell if a given descriptor refers to >a streams device ?? I've found that none of the simple ioctl's >listed in streamio(7) return the "Not a streams device" (errno=60) >error, which is the error message I'd like to get. Well, you'll just have to get use to not getting it, because, in general, UNIX systems tend to return ENOTTY or EINVAL if you do an "ioctl" on a file descriptor that refers to an object that doesn't recognize the "ioctl" in question. Modifying *every* driver on the system to return ENOSTR for all streams "ioctl"s (which is what would have to have been done in order to get the result you want) would have been time-consuming; furthermore, there's no guarantee that *every* driver would have been caught. I'd suggest using I_LOOK or I_FIND, since they don't modify the stream, just look at it; if it returns an error, it's not a stream, otherwise, it is.
dougm@ico.ISC.COM (Doug McCallum) (02/06/89)
In article <290@hsi86.hsi.UUCP> stevens@hsi.UUCP (Richard Stevens) writes: >Is there a "best" way to tell if a given descriptor refers to >a streams device ?? ... >streams device. The getmsg(2) system call does give you the right >error, but you may not want to get a message. ... getmsg/putmsg appear to be the only way to get that particular error message (ENOSR). You could always ask to "get" zero bytes of data but this may not give predictable results in some modes. It is probably safest to do an ioctl such as I_NREAD or I_PEEK and assume it is not a STREAMS device if the EINVAL error is returned. If it had been a STREAMS device it would have been valid. The only place I found the ENOSTR in the kernel was in a check for valid send or receive on a STREAM. As far as a "stat" is concerned, a STREAM is just a character device. The stat structure would have no indication of it. The difference is detected on an open in that the cdevsw structure has a streams information structure pointer and no open, close, etc. in the entry. Sorry to not be of much help, but if I were to need to detect whether it was a STREAM descriptor I would probably just assume it was if one of the safe ioctl's failed. Doug McCallum Interactive Systems Corp. dougm@ico.isc.com