Luna/apps/edit.cpp

36 lines
595 B
C++
Raw Normal View History

#include <os/ArgumentParser.h>
2023-03-23 23:52:26 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv)
{
FILE* f;
StringView pathname;
2023-03-23 23:52:26 +00:00
ArgumentParser parser;
parser.add_positional_argument(pathname, "file"_sv, true);
parser.parse(argc, argv);
2023-03-23 23:52:26 +00:00
f = fopen(pathname.chars(), "w");
2023-03-23 23:52:26 +00:00
if (!f)
{
perror(pathname.chars());
2023-03-23 23:52:26 +00:00
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;
}