policycoreutils/hll/pp: use argv[optind] appropriately
Stephen Smalley
maintainerPATCH 1/1 policycoreutils/hll/pp: use argv[optind] appropriately
The input and output filenames are read from argv[1] and argv[2] regardless of what getopt consumed so "pp -- foo.pp" tries to open "--". Use optind.
Signed-off-by Stephen Smalley <[email protected]>
--- policycoreutils/hll/pp/pp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
policycoreutils/hll/pp/pp.c +4 -4
@@ -90,8 +90,8 @@ int main(int argc, char **argv) } } -if (argc >= optind +1 &&strcmp (argv[1 ],"-" ) !=0 ) { - ifile = argv[1 ]; +if (argc >= optind +1 &&strcmp (argv[optind],"-" ) !=0 ) { + ifile = argv[optind]; in =fopen (ifile,"rb" );if (in ==NULL ) { log_err("Failed to open %s: %s", ifile,
@@ -104,8 +104,8 @@ int main(int argc, char **argv) in = stdin; } -if (argc >= optind +2 &&strcmp (argv[2 ],"-" ) !=0 ) { - ofile = argv[2 ]; +if (argc >= optind +2 &&strcmp (argv[optind +1 ],"-" ) !=0 ) { + ofile = argv[optind +1 ]; out =fopen (ofile,"w" );if (out ==NULL ) { log_err("Failed to open %s: %s", ofile,
Signature · 1 line
2.55.0
Stephen Smalley
maintainerQuoted 6 lines · Stephen Smalley
The input and output filenames are read from argv[1] and argv[2] regardless of what getopt consumed so "pp -- foo.pp" tries to open "--". Use optind.
Signed-off-by Stephen Smalley <[email protected]>
Merged.
Quoted 33 lines
--- policycoreutils/hll/pp/pp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)policycoreutils/hll/pp/pp.c +4
-5@@ -90,8 +90,8 @@ int main(int argc, char **argv) } } -if (argc >= optind +1 &&strcmp (argv[1 ],"-" ) !=0 ) { - ifile = argv[1 ]; +if (argc >= optind +1 &&strcmp (argv[optind],"-" ) !=0 ) { + ifile = argv[optind]; in =fopen (ifile,"rb" );if (in ==NULL ) { log_err("Failed to open %s: %s", ifile,@@ -104,8 +104,8 @@ int main(int argc, char **argv) in = stdin; } -if (argc >= optind +2 &&strcmp (argv[2 ],"-" ) !=0 ) { - ofile = argv[2 ]; +if (argc >= optind +2 &&strcmp (argv[optind +1 ],"-" ) !=0 ) { + ofile = argv[optind +1 ]; out =fopen (ofile,"w" );if (out ==NULL ) { log_err("Failed to open %s: %s", ofile, --2.55.0