Sync: Add some argument parsing to sync(1)

You can specify --block to make the program wait until sync is
complete.
This commit is contained in:
Bananymous 2023-09-27 00:37:23 +03:00
parent a69e5fb288
commit b573701625
1 changed files with 25 additions and 2 deletions

View File

@ -1,6 +1,29 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main()
void usage(int ret, char* cmd)
{
sync();
FILE* fout = (ret == 0) ? stdout : stderr;
fprintf(fout, "usage: %s [OPTION]...\n", cmd);
fprintf(fout, "Tells the kernel to start a disk sync as soon as possible\n");
fprintf(fout, " -b, --block return only after sync is complete\n");
fprintf(fout, " -h, --help show this message and exit\n");
exit(ret);
}
int main(int argc, char** argv)
{
bool block = false;
for (int i = 1; i < argc; i++)
{
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--block") == 0)
block = true;
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
usage(0, argv[0]);
else
usage(1, argv[0]);
}
syncsync(block);
return 0;
}