Hi,
I attach a piece of code making an ioctl call. It works when
compiled:
cc -ms ioctl_test.c
but not when compiled:
cc ioctl_test.c
giving the error message:
ioctl error 14,Bad address
A test file needed for the test was created:
echo “hi” > test.txt
Does anyone know why it doesn’t work when compiled with the
flat memory model?
— file: ioctl_test.c
#include <ioctl.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
int fd;
if((fd = open(“test.txt”,O_RDWR)) == -1)
{
printf(“open error\n”);
exit (-1);
}
if(ioctl(fd,FIONBIO,(char *)1) < 0)
{
printf(“ioctl error %d,%s\n”,errno,strerror(errno));
exit (-1);
}
printf(“finished successfully\n”);
return 0 ;
}
–
Regards,
Peter Engstrom
Replace engineering with eng to get the correct mail address.
“Peter Engstrom” <petere@prisma-engineering.it> wrote in message
news:6xy8i4mh17.fsf@lino.prisma…
Hi,
I attach a piece of code making an ioctl call. It works when
compiled:
cc -ms ioctl_test.c
but not when compiled:
cc ioctl_test.c
giving the error message:
ioctl error 14,Bad address
A test file needed for the test was created:
echo “hi” > test.txt
Does anyone know why it doesn’t work when compiled with the
flat memory model?
— file: ioctl_test.c
#include <ioctl.h
#include <stdio.h
#include <errno.h
#include <stdlib.h
#include <sys/types.h
#include <sys/stat.h
#include <fcntl.h
int main(int argc, char *argv[])
{
int fd;
if((fd = open(“test.txt”,O_RDWR)) == -1)
{
printf(“open error\n”);
exit (-1);
}
if(ioctl(fd,FIONBIO,(char *)1) < 0)
FIONBIO macro specifies that the argument should be a short ( 2 bytes) and
not a pointer (4 bytes) like you are specifying.
{
printf(“ioctl error %d,%s\n”,errno,strerror(errno));
exit (-1);
}
printf(“finished successfully\n”);
return 0 ;
}
–
Regards,
Peter Engstrom
Replace engineering with eng to get the correct mail address.