X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=util.c;h=94f9e35679acf34c7d500fade5e25919087cd9cc;hb=027a218fa84628b1bb8af6f27ef9947d859c535d;hp=094870ff213cbc41c9f011aa1b316f646ee30992;hpb=100683441c5b1445a8d6c970aea6c7fa92e974e0;p=secnet.git diff --git a/util.c b/util.c index 094870f..94f9e35 100644 --- a/util.c +++ b/util.c @@ -162,6 +162,20 @@ 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"); +} + +void pipe_cloexec(int fd[2]) { + int r=pipe(fd); + if (r) fatal_perror("pipe"); + setcloexec(fd[0]); + setcloexec(fd[1]); +} + static const char *phases[NR_PHASES]={ "PHASE_INIT", "PHASE_GETOPTS", @@ -289,7 +303,7 @@ void buf_append_string(struct buffer_if *buf, cstring_t s) len=strlen(s); /* fixme: if string is longer than 65535, result is a corrupted packet */ buf_append_uint16(buf,len); - memcpy(buf_append(buf,len),s,len); + BUF_ADD_BYTES(append,buf,s,len); } void buffer_new(struct buffer_if *buf, int32_t len)