X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=util.c;h=7d102b129afd2d33bee3536f678859fdf59d3c00;hp=e34336c77e4cc171f69555ad87b00d1e6f762e5d;hb=f54d5adadd831fd0fa55d70d3aaffe60636818f5;hpb=5e7a5e2d42c1b06f249debca72c10ad33d157402 diff --git a/util.c b/util.c index e34336c..7d102b1 100644 --- a/util.c +++ b/util.c @@ -177,13 +177,17 @@ int32_t write_mpbin(MP_INT *a, uint8_t *buffer, int32_t buflen) return i; } -void setcloexec(int fd) { - int r=fcntl(fd, F_GETFD); - if (r<0) fatal_perror("fcntl(,F_GETFD) failed"); - r=fcntl(fd, F_SETFD, r|FD_CLOEXEC); - if (r<0) fatal_perror("fcntl(,F_SETFD,|FD_CLOEXEC) failed"); +#define DEFINE_SETFDFLAG(fn,FL,FLAG) \ +void fn(int fd) { \ + int r=fcntl(fd, F_GET##FL); \ + if (r<0) fatal_perror("fcntl(,F_GET" #FL ") failed"); \ + r=fcntl(fd, F_SET##FL, r|FLAG); \ + if (r<0) fatal_perror("fcntl(,F_SET" #FL ",|" #FLAG ") failed"); \ } +DEFINE_SETFDFLAG(setcloexec,FD,FD_CLOEXEC); +DEFINE_SETFDFLAG(setnonblock,FL,O_NONBLOCK); + void pipe_cloexec(int fd[2]) { int r=pipe(fd); if (r) fatal_perror("pipe");