36 lines
595 B
C++
36 lines
595 B
C++
#include <os/ArgumentParser.h>
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
FILE* f;
|
|
StringView pathname;
|
|
|
|
ArgumentParser parser;
|
|
parser.add_positional_argument(pathname, "file"_sv, true);
|
|
parser.parse(argc, argv);
|
|
|
|
f = fopen(pathname.chars(), "w");
|
|
if (!f)
|
|
{
|
|
perror(pathname.chars());
|
|
return 1;
|
|
}
|
|
|
|
char buffer[4096];
|
|
|
|
while (1)
|
|
{
|
|
char* rc = fgets(buffer, sizeof(buffer), stdin);
|
|
if (rc == 0) break;
|
|
fputs(buffer, f);
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return 0;
|
|
}
|