42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
// INFO: INVALID SINCE SUBMISSION IS OVER
|
|
|
|
#include "tome_utils_bonus.h"
|
|
|
|
#ifndef OPEN_MAX // If the GCC compiler does not define any value
|
|
#define OPEN_MAX 5 // Give it a default one (lines)
|
|
#endif // This should make clangd shut up about it
|
|
int main(int argc, char *argv[]) {
|
|
char *data;
|
|
int fd[OPEN_MAX];
|
|
// INFO: I'm sorry, I don't have much time left to implement a pipe input.
|
|
if (argc < 2) {
|
|
printer("Usage: ./tome_reader <file1> <file2> ...");
|
|
exit(1);
|
|
} else {
|
|
for (int i = 1; i < argc; i++) {
|
|
fd[i - 1] = get_fd(argv[i], O_RDONLY);
|
|
if (fd[i] == ERR) {
|
|
printer("Error: Unable to open file\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < argc - 1; i++) {
|
|
printer("--------------");
|
|
// Loop until we get nothing
|
|
while ((data = tome_reader(fd[i])) != NULL) {
|
|
|
|
printer("\n");
|
|
printer("New line: ");
|
|
printer(data);
|
|
printer("--------------");
|
|
free(data);
|
|
}
|
|
printer("\n");
|
|
if (fd[i] != 0)
|
|
close(fd[i]); // Close the file descriptor
|
|
}
|
|
return 0;
|
|
}
|