Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save parruda/16c43b918c7751c7cbd4134e8b5238cf to your computer and use it in GitHub Desktop.
Save parruda/16c43b918c7751c7cbd4134e8b5238cf to your computer and use it in GitHub Desktop.
Crystal Lang C Bindings for System V IPC on OSX 10.15 (Catalina)
lib LibC
IPC_CREAT = 0o1000
IPC_EXCL = 0o2000
IPC_NOWAIT = 0o4000
IPC_RMID = 0
IPC_SET = 1
IPC_STAT = 2
IPC_INFO = 3
SHM_LOCK = 3
SHM_UNLOCK = 4
SHM_RDONLY = 0o10000
SHM_RND = 0o20000
alias X__Int32T = LibC::Int
alias KeyT = X__Int32T
struct IpcPerm
uid : UidT
gid : GidT
cuid : UidT
cgid : GidT
mode : ModeT
_seq : LibC::UShort
_key : KeyT
end
alias X__Uint32T = LibC::UInt
alias X__Uint16T = LibC::UShort
alias MsglenT = LibC::ULong
alias MsgqnumT = LibC::ULong
alias X__DarwinSsizeT = LibC::Long
alias SsizeT = X__DarwinSsizeT
alias ShmattT = LibC::UShort
struct X__MsqidDsNew
msg_perm : IpcPerm
msg_first : X__Int32T
msg_last : X__Int32T
msg_cbytes : MsglenT
msg_qnum : MsgqnumT
msg_qbytes : MsglenT
msg_lspid : PidT
msg_lrpid : PidT
msg_stime : TimeT
msg_pad1 : X__Int32T
msg_rtime : TimeT
msg_pad2 : X__Int32T
msg_ctime : TimeT
msg_pad3 : X__Int32T
msg_pad4 : X__Int32T[4]
end
struct X__ShmidDsNew
shm_perm : IpcPerm
shm_segsz : LibC::SizeT
shm_lpid : PidT
shm_cpid : PidT
shm_nattch : ShmattT
shm_atime : TimeT
shm_dtime : TimeT
shm_ctime : TimeT
shm_internal : Void*
end
# Util
fun memcpy(dest : Void*, src : Void*, n : LibC::SizeT) : Void*
fun ftok(pathname : LibC::Char*, proj_id : LibC::Int) : KeyT
# Shared Memory
fun shmget(key : KeyT, size : LibC::SizeT, shmflg : LibC::Int) : LibC::Int
fun shmdt(shmaddr : Void*) : LibC::Int
fun shmat(shmid : LibC::Int, shmaddr : Void*, shmflg : LibC::Int) : Void*
fun shmctl(shmid : LibC::Int, cmd : LibC::Int, buf : X__ShmidDsNew*) : LibC::Int
# Message Queue
fun msgctl(msqid : LibC::Int, cmd : LibC::Int, buf : X__MsqidDsNew*) : LibC::Int
fun msgget(key : KeyT, flag : LibC::Int) : LibC::Int
fun msgsnd(msqid : LibC::Int, msgp : Void*, msgsz : LibC::SizeT, msgflg : LibC::Int) : LibC::Int
fun msgrcv(msqid : LibC::Int, msgp : Void*, msgsz : LibC::SizeT, mtype : LibC::Long, msgflg : LibC::Int) : SsizeT
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment