You can use
go tool cgo -godefs *file*.go
to generate the Go structs from C structs and either use them as-is or get
an idea how you should pad your hand-written Go structs.
file.go will have to do an import of the right .h file(s), something like:
/*
#include "file.h"
*/
import "C"
...
On Tuesday, December 6, 2016 at 4:47:39 PM UTC-8, Steven Logan wrote:
>
> I am trying to interact with devices using the V4L2 API. The API defines
> the following struct
>
> typedef __u64 v4l2_std_id
>
> struct v4l2_input {
> __u32 index;
> __u8 name[32];
> __u32 type;
> __u32 audioset;
> __u32 tuner;
> v4l2_std_id std;
> __u32 status;
> __u32 capabilities;
> __u32 reserved[3];
> };
>
> In Go I have replicated this struct with the following
>
> type StandardId uint64
>
> type Input struct {
> Index uint32
> Name [32]uint8
> Type uint32
> Audioset uint32
> Tuner uint32
> Standard StandardId
> Status uint32
> Capabilities uint32
> reserved [3]uint32
> }
>
> When I attempt to use the Go struct in an Ioctl call I get the following
> error
>
> EnumerateVideoInput: inappropriate ioctl for device
>>
>
> I have managed to track this down to what appears to be a slight
> difference in the size of the structs.
> The Go struct has sizeof 76 bytes and the C struct has sizeof 80 bytes.
> This means the creation of my ioctl request value is incorrect as I
> generate a value of 3,226,228,250 and the actual C #define from
> linux/videodev2.h has value 3,226,490,394.
>
> Up to this point I have not had a problem replicating the C structs in Go
> and using them to call Ioctl, with calls succeeding and all fields being
> populated with the expected values so far. It seems that the system calls
> in Go do not come with much documentation and I have seen a similar method
> to this used elsewhere online hence my adoption of this approach.
> My main goal was to avoid having to use CGO as this obviously comes with
> overhead on compilation time, etc.
>
> Assuming I haven't missed something glaringly obvious, is it possible to
> replicate the C structs in Go and use them in this way?
> What would be the recommended approach for using Ioctl?
> Does anyone know of some good resources for using the /x/sys/unix package
> (specifically Syscall related)?
>
> Thanks
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.