char *other;
};
+struct chfn_control {
+ unsigned int
+ interactive:1; /* whether to prompt for fields or not */
+};
+
/* we do not accept gecos field sizes longer than MAX_FIELD_SIZE */
#define MAX_FIELD_SIZE 256
* parse the command line arguments.
* returns true if no information beyond the username was given.
*/
-static int parse_argv(int argc, char *argv[], struct finfo *pinfo)
+static void parse_argv(struct chfn_control *ctl, int argc, char *argv[], struct finfo *pinfo)
{
int index, c, status;
- int info_given;
static struct option long_options[] = {
{"full-name", required_argument, 0, 'f'},
};
optind = 0;
- info_given = false;
while (true) {
c = getopt_long(argc, argv, "f:r:p:h:o:uv", long_options,
&index);
if (!optarg)
usage(stderr);
/* ok, we were given an argument */
- info_given = true;
+ ctl->interactive = 0;
/* now store the argument */
switch (c) {
usage(stderr);
pinfo->username = argv[optind];
}
- return !info_given;
+ return;
}
/*
{
uid_t uid;
struct finfo oldf, newf;
- int interactive;
+ struct chfn_control ctl = {
+ .interactive = 1
+ };
sanitize_env();
setlocale(LC_ALL, ""); /* both for messages and for iscntrl() below */
memset(&oldf, 0, sizeof(oldf));
memset(&newf, 0, sizeof(newf));
- interactive = parse_argv(argc, argv, &newf);
+ parse_argv(&ctl, argc, argv, &newf);
if (!newf.username) {
parse_passwd(getpwuid(uid), &oldf);
if (!oldf.username)
}
#endif
- if (interactive)
+ if (ctl.interactive)
ask_info(&oldf, &newf);
if (!set_changed_data(&oldf, &newf)) {