Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/gen/sem_new.c
Show First 20 Lines • Show All 208 Lines • ▼ Show 20 Lines | _sem_open(const char *name, int flags, ...) | ||||
ni->name = (char *)(ni+1); | ni->name = (char *)(ni+1); | ||||
strcpy(ni->name, name); | strcpy(ni->name, name); | ||||
if (fd == -1) { | if (fd == -1) { | ||||
fd = _open(path, flags | O_RDWR | O_CLOEXEC | O_EXLOCK, mode); | fd = _open(path, flags | O_RDWR | O_CLOEXEC | O_EXLOCK, mode); | ||||
if (fd == -1 || _fstat(fd, &sb) == -1) | if (fd == -1 || _fstat(fd, &sb) == -1) | ||||
goto error; | goto error; | ||||
} | } | ||||
if (sb.st_size < sizeof(sem_t)) { | if ((size_t)sb.st_size < sizeof(sem_t)) { | ||||
tmp._magic = SEM_MAGIC; | tmp._magic = SEM_MAGIC; | ||||
tmp._kern._count = value; | tmp._kern._count = value; | ||||
tmp._kern._flags = USYNC_PROCESS_SHARED | SEM_NAMED; | tmp._kern._flags = USYNC_PROCESS_SHARED | SEM_NAMED; | ||||
if (_write(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) | if (_write(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) | ||||
goto error; | goto error; | ||||
} | } | ||||
flock(fd, LOCK_UN); | flock(fd, LOCK_UN); | ||||
sem = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, | sem = mmap(NULL, sizeof(sem_t), PROT_READ | PROT_WRITE, | ||||
▲ Show 20 Lines • Show All 247 Lines • Show Last 20 Lines |