rename IPC_CREATE to IPC_CREAT

This commit is contained in:
hslam 2020-11-27 13:11:57 +08:00
parent 9a1543c240
commit 9d0f21e8bd
3 changed files with 7 additions and 6 deletions

View File

@ -40,7 +40,7 @@ func main() {
}
func writer() {
shmid, data, err := shm.GetAt(2, 128, shm.IPC_CREATE|0600)
shmid, data, err := shm.GetAt(2, 128, shm.IPC_CREAT|0600)
if err != nil {
log.Fatal(err)
}
@ -92,9 +92,9 @@ func writer() {
if err != nil {
panic(err)
}
defer shm.Close(fd)
length := 128
shm.Ftruncate(fd, int64(length))
defer shm.Close(fd)
defer shm.Unlink(name)
data, err := mmap.Open(fd, 0, length, mmap.READ|mmap.WRITE)
if err != nil {
@ -110,6 +110,7 @@ func reader() {
if err != nil {
panic(err)
}
defer shm.Close(fd)
data, err := mmap.Open(fd, 0, 128, mmap.READ)
if err != nil {
panic(err)

View File

@ -11,8 +11,8 @@ import (
)
const (
// IPC_CREATE creates if key is nonexistent
IPC_CREATE = 00001000
// IPC_CREAT creates if key is nonexistent
IPC_CREAT = 00001000
//IPC_RMID removes identifier
IPC_RMID = 0
@ -21,7 +21,7 @@ const (
// GetAt calls the shmget and shmat system call.
func GetAt(key int, size int, shmFlg int) (uintptr, []byte, error) {
if shmFlg == 0 {
shmFlg = IPC_CREATE | 0600
shmFlg = IPC_CREAT | 0600
}
shmid, _, errno := syscall.Syscall(SYS_SHMGET, uintptr(key), uintptr(validSize(int64(size))), uintptr(shmFlg))
if int(shmid) < 0 {

View File

@ -16,7 +16,7 @@ func TestGetAt(t *testing.T) {
context := "Hello World"
done := make(chan struct{})
go func() {
shmid, data, err := GetAt(2, 128, IPC_CREATE|0600)
shmid, data, err := GetAt(2, 128, IPC_CREAT|0600)
if err != nil {
t.Error(err)
}