tags:

views:

156

answers:

3

I was reading through this Advanced Linux Programming tutorial when I encountered a problem. I was trying to eject the CD-ROM drive using this code:

int fd = open(path_to_cdrom, O_RDONLY);

// Eject the CD-ROM drive
ioctl(fd, CDROMEJECT);

close(fd);

Then I try to compile this code and get the following output:

In file included from /usr/include/linux/cdrom.h:14,
                 from new.c:2:
/usr/include/asm/byteorder.h: In function ‘___arch__swab32’:
/usr/include/asm/byteorder.h:19: error: expected ‘)’ before ‘:’ token
/usr/include/asm/byteorder.h: In function ‘___arch__swab64’:
/usr/include/asm/byteorder.h:43: error: expected ‘)’ before ‘:’ token

So what am I doing wrong?

+1  A: 

According to this, you need to specify O_NONBLOCK when opening the device, otherwise it won't work.

From that page:

cdrom = open(CDDEVICE,O_RDONLY | O_NONBLOCK)

mrduclaw
+5  A: 

The error message you're seeing looks like something is wrong in your #include lines, not with the code you posted. I tried compiling http://www.advancedlinuxprogramming.com/listings/chapter-6/cdrom-eject.c and it compiles just fine.

Laurence Gonsalves
I just did the same thing and got the same error.
Lucas McCoy
So how do I fix my include files?
Lucas McCoy
What compiler are you using? I took a look at /usr/include/asm/byteorder.h on my Linux box, and the line causing your error is inline assembly in a GCC specific syntax, so if you're using something other than GCC that might be the cause of your trouble.
Laurence Gonsalves
@Laurence: No I'm using GCC and I also looked at `byteorder.h` and seen the inline assembly.
Lucas McCoy
+1  A: 

You are missing a #include, I think. Do you have:

#include <fcntl.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

Those are the ones in the example...

DigitalRoss
No I have all of those
Lucas McCoy