Port-sparc64 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: ioctl question



On Monday 09 June 2008 13:37:32 raymond.meyer%rambler.ru@localhost wrote:
> Does anyone know why on 64-bit NetBSD sparc64 the following code works:
>
> ioctl(fd, SNDCTL_DSP_CHANNELS, &channels);
>
> but the following code returns -1 from ioctl
>
> unsigned long dsp_ch = SNDCTL_DSP_CHANNELS;
> ioctl(fd, dsp_ch, &channels)
>
> /usr/include/soundcard.h has:
>
> #define SNDCTL_DSP_CHANNELS             _IOWR('P', 6, int)

OK, a few corrections, I think both of the above work.
The following code does not work

int call_ioctl(int fd, int request, void *argp)
{
        int val = *argp;

        if (ioctl(fd, request, &val) != 0)
                return -1;
}

call_ioctl(some_fd, SNDCTL_DSP_CHANNELS, &some_arg);

Well I think the reason why this fails is because 2nd arg to ioctl() is of 
type 'int', and not 'unsigned log'. 

If I put

printf("request=%ul, SNDCTL_DSP_CHANNELS=%ul\n", request, 
SNDCTL_DSP_CHANNELS);

inside call_ioctl() function they both print the same value. I don't 
understand why casting 'int' to 'unsigned long' in a call to ioctl does not 
work??

i.e. if (ioctl(fd, (unsigned long)request, &val) != 0)


Home | Main Index | Thread Index | Old Index