Ioctl problem

I’m trying to use Ruby IO:ioctl on /dev/mixer. It work with c but not
with ruby. I sure it a dumb mistake, but I can see it. Below is a ruby
program that fails and the c program that work. Thanks ahead of time.
pc

···

#! /usr/bin/env ruby

SOUND_MIXER_READ_DEVMASK = 0x80044dfe

mixer = File.open("/dev/mixer", “w+”)
notused = 0
devmask = mixer.ioctl(SOUND_MIXER_READ_DEVMASK, notused)
printf “devmask[%08x]\n”, devmask

#~ Program results:
#~ test.rb:8:
#~ in `ioctl’: Bad address - /dev/mixer (Errno::EFAULT) from test.rb:8


#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>

#define SOUND_MIXER_READ_DEVMASK 0X80044dfe

int main(int argc, char *argv[])
{
int mixerfd, devmask;

char* name = "/dev/mixer";
if ((mixerfd = open(name, O_RDWR)) < 0) {
	perror(name);
	exit(1);
}
if (ioctl(mixerfd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) {
	perror("SOUND_MIXER_READ_DEVMASK");
	exit(-1);
}
printf("Mixer Device mask [%08x]\n", devmask);

return 0;

}
/*
Program results:
Mixer Device mask [005051d1]
*/

Hi,

I’m trying to use Ruby IO:ioctl on /dev/mixer. It work with c but not
with ruby. I sure it a dumb mistake, but I can see it. Below is a ruby
program that fails and the c program that work. Thanks ahead of time.
pc

You mean like this?

#! /usr/bin/env ruby

SOUND_MIXER_READ_DEVMASK = 0x80044dfe

mixer = File.open(“/dev/mixer”, “w+”)
devmask = [0].pack(“i”)
mixer.ioctl(SOUND_MIXER_READ_DEVMASK, devmask)
printf “devmask[%08x]\n”, *devmask.unpack(“i”)

···

In message “Ioctl problem” on 03/12/21, Phil Callihan pcallihan@columbus.rr.com writes: