-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from davidgiven/cpmfs
Avoid a weird mkfs.cpm bug where it doesn't always create the directory.
- Loading branch information
Showing
4 changed files
with
84 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <fstream> | ||
#include <fmt/format.h> | ||
|
||
static std::string filename; | ||
static int byteCount; | ||
static int byteValue; | ||
|
||
static void parseArgs(int argc, char* argv[]) | ||
{ | ||
for (;;) | ||
{ | ||
switch (getopt(argc, argv, "f:n:b:")) | ||
{ | ||
case -1: | ||
return; | ||
|
||
case 'f': | ||
filename = optarg; | ||
break; | ||
|
||
case 'n': | ||
byteCount = strtol(optarg, nullptr, 0); | ||
break; | ||
|
||
case 'b': | ||
byteValue = strtol(optarg, nullptr, 0); | ||
break; | ||
|
||
default: | ||
fmt::print(stderr, | ||
"Usage: fillfile -f <img> -n <count> -b <byte>\n"); | ||
exit(1); | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
parseArgs(argc, argv); | ||
|
||
std::ofstream of(filename); | ||
if (!of) | ||
{ | ||
fmt::print(stderr, | ||
"fillfile: cannot open output file: {}\n", strerror(errno)); | ||
exit(1); | ||
} | ||
|
||
for (int i=0; i<byteCount; i++) | ||
of.put(byteValue); | ||
|
||
of.close(); | ||
return 0; | ||
} |