Separate log and output streams
This commit is contained in:
@@ -5,16 +5,13 @@
|
||||
|
||||
#define BLOCK_SIZE 65536
|
||||
|
||||
#define PRINT_S(s) write(1, s, sizeof(s) - 1);
|
||||
#define PRINT_D(s) write(1, s, string_length(s));
|
||||
|
||||
exit_code_t pass(uint64_t fd) {
|
||||
static char buffer[BLOCK_SIZE];
|
||||
uint64_t bytes;
|
||||
uint64_t total = 0;
|
||||
while ((bytes = read(fd, BLOCK_SIZE, buffer))) {
|
||||
if (bytes == (uint64_t)-1) {
|
||||
PRINT_S("wc: could not read file\n");
|
||||
ERR_S("wc: could not read file\n");
|
||||
return EXIT_CODE_GENERAL_FAILURE;
|
||||
} else {
|
||||
total += bytes;
|
||||
@@ -22,7 +19,7 @@ exit_code_t pass(uint64_t fd) {
|
||||
}
|
||||
|
||||
uint64_t l = string_format("%d\n", BLOCK_SIZE, buffer, total);
|
||||
write(1, buffer, l);
|
||||
write(STDOUT, buffer, l);
|
||||
|
||||
return EXIT_CODE_OK;
|
||||
}
|
||||
@@ -31,7 +28,7 @@ exit_code_t wc(const char *path) {
|
||||
uint64_t fd = open(path, OPEN_FILE);
|
||||
|
||||
if (fd == (uint64_t)-1) {
|
||||
PRINT_S("wc: path does not exist\n");
|
||||
OUT_S("wc: path does not exist\n");
|
||||
return EXIT_CODE_GENERAL_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user