summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-11-21 23:41:53 +0100
committerTyge Løvset <[email protected]>2021-11-21 23:41:53 +0100
commitddeb0603e1ce90cee843e59708ce80c24589d14d (patch)
tree51ecaf865fb131fdb6cbd211efd5220a6c006551
parent49ec46c2bb291a4faaec7741f764d07029dc0208 (diff)
downloadSTC-modified-ddeb0603e1ce90cee843e59708ce80c24589d14d.tar.gz
STC-modified-ddeb0603e1ce90cee843e59708ce80c24589d14d.zip
Fixed option_mkdir.c return value.
-rw-r--r--examples/option_mkdir.c88
1 files changed, 44 insertions, 44 deletions
diff --git a/examples/option_mkdir.c b/examples/option_mkdir.c
index 308348b0..e28c09e9 100644
--- a/examples/option_mkdir.c
+++ b/examples/option_mkdir.c
@@ -3,16 +3,16 @@
// mkdir option parsing.
struct AppArgs {
- const char *mode;
- bool parent;
- bool verbose;
- const char *context;
- int index;
+ const char *mode;
+ bool parent;
+ bool verbose;
+ const char *context;
+ int index;
};
int parseArgs(int argc, char *argv[], struct AppArgs *args)
{
- const char *shortopts = "pvm:Z";
+ const char *shortopts = "pvm:Z";
coption_long longopts[] = {
{"mode", coption_required_argument, 'm'},
{"parent", coption_no_argument, 'p'},
@@ -32,58 +32,58 @@ int parseArgs(int argc, char *argv[], struct AppArgs *args)
case 'v': args->verbose = true; break;
case 'Z': args->context = opt.arg? opt.arg : "DEFAULT"; break;
case 'H':
- printf( "Usage: mkdir [OPTION]... DIRECTORY...\n"
- "Create the DIRECTORY(ies), if they do not already exist.\n\n"
- "Mandatory arguments to long options are mandatory for short options too.\n"
- " -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask\n"
- " -p, --parents no error if existing, make parent directories as needed\n"
- " -v, --verbose print a message for each created directory\n"
- " -Z set SELinux security context of each created directory\n"
- " to the default type\n"
- " --context[=CTX] like -Z, or if CTX is specified then set the SELinux\n"
- " or SMACK security context to CTX\n"
- " --help display this help and exit\n"
- " --version output version information and exit\n\n"
- "GNU coreutils online help: <https://www.gnu.org/software/coreutils/>\n"
- "Full documentation at: <https://www.gnu.org/software/coreutils/mkdir>\n"
- "or available locally via: info '(coreutils) mkdir invocation'\n" );
- return 1;
+ printf( "Usage: mkdir [OPTION]... DIRECTORY...\n"
+ "Create the DIRECTORY(ies), if they do not already exist.\n\n"
+ "Mandatory arguments to long options are mandatory for short options too.\n"
+ " -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask\n"
+ " -p, --parents no error if existing, make parent directories as needed\n"
+ " -v, --verbose print a message for each created directory\n"
+ " -Z set SELinux security context of each created directory\n"
+ " to the default type\n"
+ " --context[=CTX] like -Z, or if CTX is specified then set the SELinux\n"
+ " or SMACK security context to CTX\n"
+ " --help display this help and exit\n"
+ " --version output version information and exit\n\n"
+ "GNU coreutils online help: <https://www.gnu.org/software/coreutils/>\n"
+ "Full documentation at: <https://www.gnu.org/software/coreutils/mkdir>\n"
+ "or available locally via: info '(coreutils) mkdir invocation'\n" );
+ return 1;
case 'V':
- printf( "mkdir (GNU coreutils) 8.30\n"
- "Copyright (C) 2018 Free Software Foundation, Inc.\n"
- "License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\n"
- "This is free software: you are free to change and redistribute it.\n"
- "There is NO WARRANTY, to the extent permitted by law.\n" );
- return 1;
+ printf( "mkdir (GNU coreutils) 8.30\n"
+ "Copyright (C) 2018 Free Software Foundation, Inc.\n"
+ "License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\n"
+ "This is free software: you are free to change and redistribute it.\n"
+ "There is NO WARRANTY, to the extent permitted by law.\n" );
+ return 1;
case ':':
printf("mkdir: option '%s' requires an argument\n"
- "Try 'mkdir --help' for more information.\n", opt.optstr);
- return -2;
+ "Try 'mkdir --help' for more information.\n", opt.optstr);
+ return -1;
case '?':
- printf("mkdir: invalid option '%s'\n"
- "Try 'mkdir --help' for more information.\n", opt.optstr);
- return -3;
+ printf("mkdir: invalid option '%s'\n"
+ "Try 'mkdir --help' for more information.\n", opt.optstr);
+ return -2;
}
}
- if (opt.ind == argc) {
- printf("mkdir: missing operand\n"
- "Try 'mkdir --help' for more information.\n");
- return -1;
- }
- args->index = opt.ind;
+ if (opt.ind == argc) {
+ printf("mkdir: missing operand\n"
+ "Try 'mkdir --help' for more information.\n");
+ return 2;
+ }
+ args->index = opt.ind;
return 0;
}
int main(int argc, char* argv[])
{
- struct AppArgs args;
- int ret = parseArgs(argc, argv, &args);
- if (ret != 0)
- return ret < 0? ret : 0;
+ struct AppArgs args;
+ int ret = parseArgs(argc, argv, &args);
+ if (ret != 0)
+ return ret < 0? ret : 0;
- printf("mkdir:");
+ printf("mkdir:");
for (int i=args.index; i < argc; ++i) {
printf(" %s\n", argv[i]);
}