The API you have when you don't have an API in the Unix world. This is because of the way Unix was designed -- it was designed to be platform-independent. However, this leaves you with a problem: How do you handle low-level devices like serial ports and parallel ports? What sort of programming interface do you provide?

The Unix answer: you don't! You create a catch-all function called ioctl that takes a device, a request and a variable number of other parameters. The devices, requests and other parameters are then defined in header files. These devices and requests are platform-specific, poorly documented and very messy.

This gives programmers access to the hardware but it's a complete non-solution in every other way. It's platform-specific, which is the very problem you were trying to solve in the first place. It's very difficult to program with and it can be complicated and tedious to read up on.

For example, say you want to open a serial port, set the baud rate to 38400, and disable hardware flow control. The code for that might be something like 30 icky lines of setting up structs, calling open, passing data structures and the like. It is seriously messy. For example, here's typical code to open a serial port under Linux:

#define FOB_SP "/dev/ttyS0"
  struct termios fobtio;
  int iorv;
  dprintf(stderr, "init_FOB called\n");
  fobtio.c_iflag = IGNBRK; /* iflag */
  fobtio.c_oflag = 0;   /* oflag */
  fobtio.c_cflag = B38400 | CS8 | CLOCAL | CREAD; /* cflag */
  fobtio.c_lflag = 0; /* lflag */
  fobtio.c_ccVMIN = 0;
  fobtio.c_ccVTIME = 0;
  fobfd = open(FOB_SP, O_RDWR);

  if(fobfd == -1){

  iorv = tcsetattr(fobfd, TCSAFLUSH, &fobtio);
  if(iorv == -1){

Whereas something like BeOS, it looks like:

BSerial b = new BSerial("serial1"); // open first serial port

I'm not against Unix in general, but this is the cruddiest thing in it.

Log in or register to write something here or to contact authors.