2023-05-16 00:27:49 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
bool cat_file(FILE* fp)
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
size_t n_read;
|
|
|
|
while ((n_read = fread(buffer, 1, sizeof(buffer) - 1, fp)) > 0)
|
|
|
|
{
|
|
|
|
buffer[n_read] = '\0';
|
|
|
|
fputs(buffer, stdout);
|
|
|
|
}
|
|
|
|
if (ferror(fp))
|
|
|
|
{
|
|
|
|
perror("fread");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
{
|
|
|
|
for (int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
FILE* fp = fopen(argv[i], "r");
|
|
|
|
if (fp == nullptr)
|
|
|
|
{
|
|
|
|
perror(argv[i]);
|
|
|
|
ret = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2023-06-10 17:34:10 +03:00
|
|
|
if (!cat_file(fp))
|
2023-05-16 00:27:49 +03:00
|
|
|
ret = 1;
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-06-10 17:34:10 +03:00
|
|
|
if (!cat_file(stdin))
|
|
|
|
ret = 1;
|
2023-05-16 00:27:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|