Use C function variables in Go

I use shm_openwith cgo. shm_opendefined by three arguments in Linux

int shm_open(const char *name, int oflag, mode_t mode);

whereas on OSX (Darwin) the 3rd mode flag is optional.

int shm_open(const char *name, int oflag, ...);

This creates a problem with CGO when trying to transfer OSX mode. He complains that I pass 3 arguments when only 2 are expected.

How can I get around this?

+4
source share
1 answer

As usual, revelation comes 1 second after being published in SO. In fact, you can declare functions in the CGO comment section, so all you have to do is use that kind of shell.

/*
#include <stdio.h>

int shm_open2(const char *name, int oflag, mode_t mode) {
  return shm_open(name, oflag, mode);
}
*/
import "C"
+5
source

All Articles