From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27, 11 canonical families), 38 skipped for scope or duplication. Each task has at least one independent contract-edge defect, boundary types rotate, and public docs state trap clauses as plain contract prose. Claude reviewed 63/63 USABLE against current digests. Difficulty is unmeasured. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
#include "descriptor.h"
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
static int descriptor_flags(int fd)
|
|
{
|
|
int result;
|
|
do {
|
|
result = fcntl(fd, F_GETFD);
|
|
} while (result < 0 && errno == EINTR);
|
|
return result;
|
|
}
|
|
|
|
int dr_raw_cloexec(int fd, int enabled)
|
|
{
|
|
if (enabled != 0 && enabled != 1) {
|
|
errno = EINVAL;
|
|
return -1;
|
|
}
|
|
int flags = descriptor_flags(fd);
|
|
if (flags < 0) {
|
|
return -1;
|
|
}
|
|
if (enabled) {
|
|
flags |= FD_CLOEXEC;
|
|
} else {
|
|
flags &= ~FD_CLOEXEC;
|
|
}
|
|
int result;
|
|
do {
|
|
result = fcntl(fd, F_SETFD, flags);
|
|
} while (result < 0 && errno == EINTR);
|
|
return result;
|
|
}
|
|
|
|
int dr_raw_replace(int source, int target)
|
|
{
|
|
int temporary;
|
|
do {
|
|
temporary = fcntl(source, F_DUPFD, 64);
|
|
} while (temporary < 0 && errno == EINTR);
|
|
if (temporary < 0) {
|
|
return -1;
|
|
}
|
|
int result;
|
|
do {
|
|
result = dup2(temporary, target);
|
|
} while (result < 0 && errno == EINTR);
|
|
int saved = errno;
|
|
close(temporary);
|
|
errno = saved;
|
|
return result;
|
|
}
|