forked from Bananymous/banan-os
tee: indent with tabs
This commit is contained in:
parent
d3bb00cb55
commit
6e1fc2766f
|
@ -9,56 +9,56 @@
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int files[MAX_FILES] {};
|
int files[MAX_FILES] {};
|
||||||
size_t file_count = 0;
|
size_t file_count = 0;
|
||||||
|
|
||||||
int arg = 1;
|
int arg = 1;
|
||||||
|
|
||||||
int oflag = O_WRONLY | O_CREAT;
|
int oflag = O_WRONLY | O_CREAT;
|
||||||
if (arg < argc && strcmp(argv[arg], "-a") == 0)
|
if (arg < argc && strcmp(argv[arg], "-a") == 0)
|
||||||
{
|
{
|
||||||
oflag |= O_APPEND;
|
oflag |= O_APPEND;
|
||||||
arg++;
|
arg++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
oflag |= O_TRUNC;
|
oflag |= O_TRUNC;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = arg; i < argc; i++)
|
for (int i = arg; i < argc; i++)
|
||||||
{
|
{
|
||||||
files[file_count] = open(argv[i], oflag, 0644);
|
files[file_count] = open(argv[i], oflag, 0644);
|
||||||
if (files[file_count] == -1)
|
if (files[file_count] == -1)
|
||||||
perror(argv[i]);
|
perror(argv[i]);
|
||||||
else
|
else
|
||||||
file_count++;
|
file_count++;
|
||||||
|
|
||||||
if (file_count >= MAX_FILES)
|
if (file_count >= MAX_FILES)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "only up to %d files are supported\n", MAX_FILES);
|
fprintf(stderr, "only up to %d files are supported\n", MAX_FILES);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char* buffer = (char*)malloc(BUF_SIZE);
|
char* buffer = (char*)malloc(BUF_SIZE);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
ssize_t nread = read(STDIN_FILENO, buffer, BUF_SIZE);
|
ssize_t nread = read(STDIN_FILENO, buffer, BUF_SIZE);
|
||||||
if (nread == -1)
|
if (nread == -1)
|
||||||
perror("stdin");
|
perror("stdin");
|
||||||
if (nread <= 0)
|
if (nread <= 0)
|
||||||
break;
|
break;
|
||||||
write(STDOUT_FILENO, buffer, nread);
|
write(STDOUT_FILENO, buffer, nread);
|
||||||
for (size_t i = 0; i < file_count; i++)
|
for (size_t i = 0; i < file_count; i++)
|
||||||
write(files[i], buffer, nread);
|
write(files[i], buffer, nread);
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
if (ferror(stdin))
|
if (ferror(stdin))
|
||||||
perror("stdin");
|
perror("stdin");
|
||||||
|
|
||||||
for (size_t i = 0; i < file_count; i++)
|
for (size_t i = 0; i < file_count; i++)
|
||||||
close(files[i]);
|
close(files[i]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue