I don't know QNX, and I'm not sure what you mean by serial or // printer. Nor do I understand why you are taking such an odd approach to this.
I think it would make much more sense to be writing a journal_open() and maybe a journal_close(). A journal_write() might also make sense if you need to greatly assist with a device error such as out-of-paper. But there is a lot of one-time setup stuff for many printers.
Also a journal_open() would make the filename visable to you. With unix, you know that /dev/dsk/c0t6d0s4 is not a line printer. Unix has some naming conversions for devices. They vary from version to version...but each version has a well defined convention. I know that the whole
raison d'être of fstat() and fcntrl() was to enable programs to work with files already opened by the shell before the program even started to run. But a program like:
diagnose < /dev/any/device
is not a reasonable extention of this. A system can have many line printers. If your particular line printer has trouble, how would phrase the error message without a filename?
If you want to use your approach anyway, I can think of 2 approaches that might work. The first is to get the major number of the device. You do that looking at the st_dev field in the stat structure. You want to use a macro like this:
major(statbuf.st_dev)
where major is a macro in <sys/sysmacros.h>. You would have to know which major number refers to which driver and there is no portable way to do that...well maybe searching /dev. The second approach is to assume it is a serial device. Try a serial ioctl to it. If the ioctl works, it must be serial.
Quote:
how can I get the // printer status the way stty does?
On unix, stty would only work with a serial port. So at this point, I'm confused, however, to configure a serial port on unix using posix conventions, see "man termios".
Here is an example. To configure other devices under unix, you would typically use ioctl() with a request that is documented on the man page for the driver that controls the device.