ioctl

Charles G Waldman cgw at alum.mit.edu
Tue Feb 1 15:22:31 EST 2000


In article <8771k4$2o1c$1 at noao.edu>, cheselka at tucana.noao.edu (Matt Cheselka) wrote:
> I'm talking to a device driver that wants the address of a pointer to an array
> as it's input.  In C, it looks like this:
> 
> 
> 	char	linearray[NUM], *subarr;
> 
> 	<do something with linearray[]>
> 
> 	subarr = linearry
> 
> 	ioctl (fd, DO_SOMETHING, &subarr);
> 

I would use SWIG to make a little extension module.

Create the file "my_ioctl.i" with the following contents:

%module my_ioctl

%{
#include <whatever.h>

int
do_something(int fd, char *string){
	return ioctl(fd, DO_SOMETHING, &string);
}
%}
int do_something(int fd, char *string);

Then do "swig -python my_ioctl.i"
Compile the resulting my_ioctl_wrap.c as a dynamic Python extension module
and load it with "import my_ioctl"

You should then be able to, in Python code, do

my_ioctl.do_something(file_object.fileno(), "Some string");





More information about the Python-list mailing list