Reading binary data

Thomas Heller theller at python.net
Wed Nov 23 15:14:16 EST 2005


"David M" <Neruocomp at yahoo.com> writes:

> Thanks but the C Struct describing the data doesn't match up with the
> list on the module-struct page.
>
> this is the acct.h file
[...]

Tooting my ctypes horn (sorry for that):

thomas at linux:~/ctypes> locate acct.h
/usr/include/linux/acct.h
/usr/include/sys/acct.h
thomas at linux:~/ctypes> python ctypes/wrap/h2xml.py sys/acct.h -o acct.xml
creating xml output file ...
running: gccxml /tmp/tmpSWogJs.cpp -fxml=acct.xml
thomas at linux:~/ctypes> python ctypes/wrap/xml2py.py acct.xml -o acct.py  
thomas at linux:~/ctypes> python
Python 2.4.1a0 (#1, Oct 23 2004, 15:48:15) 
[GCC 3.3.1 (SuSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import acct
>>> acct.acct
<class 'acct.acct'>
>>> acct.AFORK
1
>>> acct.ASU
2
>>> acct.acct.ac_comm
<Field type=c_char_Array_17, ofs=36, size=17>
>>> acct.acct.ac_utime
<Field type=c_ushort, ofs=12, size=2>
>>> from ctypes import sizeof
>>> sizeof(acct.acct) 
64
>>> acct.acct.ac_flag
<Field type=c_char, ofs=0, size=1>
>>> 
thomas at linux:~/ctypes> 

But it won't help you to decode/encode the comp_t fields into floats.
Note that the h2xml.py script requires gccxml.

Thomas



More information about the Python-list mailing list