To make the example code work, you should do it this way:
#include <sys/ioctl.h>
#include <linux/cdrom.h>
int result=ioctl(fd, CDROM_DRIVE_STATUS, CDSL_NONE);
switch(result) {
case CDS_NO_INFO: ... break;
case CDS_NO_DISC: ... break;
case CDS_TRAY_OPEN: ... break;
case CDS_DRIVE_NOT_READY: ... break;
case CDS_DISC_OK: ... break;
default: /* error */
}
i.e. the result is returned as ioctl() function result, not into slot argument.