fixed nonsense with truncation

This commit is contained in:
phanes committed 2024-02-08 05:57:09 -05:00
1 parent bb324087a8
commit 344cbfc56e
5 files changed
+20 -30

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
#include "helpers.h"
ssize_t write_all(int fd, const void *buf, size_t count) {
const char *p = (const char *)buf;
while (count > 0) {
ssize_t written = write(fd, p, count);
if (written == -1) {
if (errno == EINTR || errno == EAGAIN) continue; // Retry
return -1; // Other errors
}
count -= written;
p += written;
}
return 0;
}
+4 -13
View File
@@ -1,6 +1,9 @@
#ifndef LCPEX_HELPERS_H
#define LCPEX_HELPERS_H
#include <unistd.h>
#include "errno.h"
// helper for sanity
enum PIPE_ENDS {
READ_END = 0,
@@ -16,18 +19,6 @@ enum CHILD_PIPE_NAMES {
#define BUFFER_SIZE 1024
ssize_t write_all(int fd, const void *buf, size_t count) {
const char *p = (const char *)buf;
while (count > 0) {
ssize_t written = write(fd, p, count);
if (written == -1) {
if (errno == EINTR || errno == EAGAIN) continue; // Retry
return -1; // Other errors
}
count -= written;
p += written;
}
return 0;
}
ssize_t write_all(int fd, const void *buf, size_t count);
#endif //LCPEX_HELPERS_H
-14
View File
@@ -138,17 +138,3 @@ std::string get_absolute_path(const std::string &relative_path)
return std::string(resolved_path);
}
ssize_t write_all(int fd, const void *buf, size_t count) {
const char *p = (const char *)buf;
while (count > 0) {
ssize_t written = write(fd, p, count);
if (written == -1) {
if (errno == EINTR || errno == EAGAIN) continue; // Retry
return -1; // Other errors
}
count -= written;
p += written;
}
return 0;
}
-2
View File
@@ -67,6 +67,4 @@ const char * command2args( std::string input_string );
*/
std::string get_absolute_path(const std::string &relative_path);
ssize_t write_all(int fd, const void *buf, size_t count);
#endif //REX_HELPERS_H