diff options
author | Mattias Andrée <maandree@kth.se> | 2016-07-12 10:42:29 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-07-12 10:42:52 +0200 |
commit | d7cf13b968b99cb070c7d5d2e1f7ff1a8072f2f3 (patch) | |
tree | 89b172602b2d5dd2ebeb7450a5247614b9d04d00 /src/util.c | |
parent | Implement state merging (diff) | |
download | coopgammad-d7cf13b968b99cb070c7d5d2e1f7ff1a8072f2f3.tar.gz coopgammad-d7cf13b968b99cb070c7d5d2e1f7ff1a8072f2f3.tar.bz2 coopgammad-d7cf13b968b99cb070c7d5d2e1f7ff1a8072f2f3.tar.xz |
Implement re-exec
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 39 |
1 files changed, 38 insertions, 1 deletions
@@ -82,7 +82,11 @@ void* nread(int fd, size_t* n) got = read(fd, buf + *n, size - *n); if (got < 0) - goto fail; + { + if (errno == EINTR) + continue; + goto fail; + } if (got == 0) break; *n += (size_t)got; @@ -99,6 +103,39 @@ void* nread(int fd, size_t* n) /** + * Write an entire buffer to a file + * + * Not cancelled by `EINTR` + * + * @param fd The file descriptor + * @param buf The buffer which shall be written to the fail + * @param n The size of the buffer + * @return The number of written bytes, less than `n` + * on error, cannot exceed `n` + */ +size_t nwrite(int fd, const void* buf, size_t n) +{ + const char* bs = buf; + ssize_t wrote; + size_t ptr = 0; + + while (ptr < n) + { + wrote = write(fd, bs + ptr, n - ptr); + if (wrote <= 0) + { + if ((wrote < 0) && (errno == EINTR)) + continue; + return ptr; + } + ptr += (size_t)wrote; + } + + return ptr; +} + + +/** * Duplicate a file descriptor an make sure * the new file descriptor's index as a * specified minimum value |