summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1995-11-09 23:27:55 +0000
committerJim Meyering <jim@meyering.net>1995-11-09 23:27:55 +0000
commit4796ddfe368143bf7c89d98c8ff23a181dc542f1 (patch)
treeeea78c1e4c7afb6cb9298ddfb2af48948b0574ab /src
parent31856b16c3dc0ef3053c197bb998837c16d610f6 (diff)
downloadcoreutils-4796ddfe368143bf7c89d98c8ff23a181dc542f1.tar.xz
(main): Move to the end.
Remove most fwd dcls.
Diffstat (limited to 'src')
-rw-r--r--src/chown.c166
1 files changed, 82 insertions, 84 deletions
diff --git a/src/chown.c b/src/chown.c
index 536b6ed57..bb2ad6e95 100644
--- a/src/chown.c
+++ b/src/chown.c
@@ -55,10 +55,8 @@ void strip_trailing_slashes ();
char *xmalloc ();
char *xrealloc ();
-static int change_file_owner (char *file, uid_t user, gid_t group);
-static int change_dir_owner (char *dir, uid_t user, gid_t group, struct stat *statp);
-static void describe_change (char *file, int changed);
-static void usage (int status);
+static int change_dir_owner __P ((char *dir, uid_t user, gid_t group,
+ struct stat *statp));
/* The name the program was run with. */
char *program_name;
@@ -99,71 +97,20 @@ static struct option const long_options[] =
{0, 0, 0, 0}
};
-void
-main (int argc, char **argv)
-{
- uid_t user = (uid_t) -1; /* New uid; -1 if not to be changed. */
- gid_t group = (uid_t) -1; /* New gid; -1 if not to be changed. */
- int errors = 0;
- int optc;
- char *e;
-
- program_name = argv[0];
- recurse = force_silent = verbose = changes_only = 0;
-
- while ((optc = getopt_long (argc, argv, "Rcfv", long_options, (int *) 0))
- != EOF)
- {
- switch (optc)
- {
- case 0:
- break;
- case 'R':
- recurse = 1;
- break;
- case 'c':
- verbose = 1;
- changes_only = 1;
- break;
- case 'f':
- force_silent = 1;
- break;
- case 'v':
- verbose = 1;
- break;
- default:
- usage (1);
- }
- }
-
- if (show_version)
- {
- printf ("chown - %s\n", version_string);
- exit (0);
- }
-
- if (show_help)
- usage (0);
-
- if (optind >= argc - 1)
- {
- error (0, 0, "too few arguments");
- usage (1);
- }
-
- e = parse_user_spec (argv[optind], &user, &group, &username, &groupname);
- if (e)
- error (1, 0, "%s: %s", argv[optind], e);
- if (username == NULL)
- username = "";
-
- for (++optind; optind < argc; ++optind)
- {
- strip_trailing_slashes (argv[optind]);
- errors |= change_file_owner (argv[optind], user, group);
- }
+/* Tell the user the user and group names to which ownership of FILE
+ has been given; if CHANGED is zero, FILE had those owners already. */
- exit (errors);
+static void
+describe_change (char *file, int changed)
+{
+ if (changed)
+ printf ("owner of %s changed to ", file);
+ else
+ printf ("owner of %s retained as ", file);
+ if (groupname)
+ printf ("%s.%s\n", username, groupname);
+ else
+ printf ("%s\n", username);
}
/* Change the ownership of FILE to UID USER and GID GROUP.
@@ -258,22 +205,6 @@ change_dir_owner (char *dir, uid_t user, gid_t group, struct stat *statp)
return errors;
}
-/* Tell the user the user and group names to which ownership of FILE
- has been given; if CHANGED is zero, FILE had those owners already. */
-
-static void
-describe_change (char *file, int changed)
-{
- if (changed)
- printf ("owner of %s changed to ", file);
- else
- printf ("owner of %s retained as ", file);
- if (groupname)
- printf ("%s.%s\n", username, groupname);
- else
- printf ("%s\n", username);
-}
-
static void
usage (int status)
{
@@ -302,3 +233,70 @@ to login group if implied by a period. A colon may replace the period.\n");
}
exit (status);
}
+
+void
+main (int argc, char **argv)
+{
+ uid_t user = (uid_t) -1; /* New uid; -1 if not to be changed. */
+ gid_t group = (uid_t) -1; /* New gid; -1 if not to be changed. */
+ int errors = 0;
+ int optc;
+ char *e;
+
+ program_name = argv[0];
+ recurse = force_silent = verbose = changes_only = 0;
+
+ while ((optc = getopt_long (argc, argv, "Rcfv", long_options, (int *) 0))
+ != EOF)
+ {
+ switch (optc)
+ {
+ case 0:
+ break;
+ case 'R':
+ recurse = 1;
+ break;
+ case 'c':
+ verbose = 1;
+ changes_only = 1;
+ break;
+ case 'f':
+ force_silent = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ default:
+ usage (1);
+ }
+ }
+
+ if (show_version)
+ {
+ printf ("chown - %s\n", version_string);
+ exit (0);
+ }
+
+ if (show_help)
+ usage (0);
+
+ if (optind >= argc - 1)
+ {
+ error (0, 0, "too few arguments");
+ usage (1);
+ }
+
+ e = parse_user_spec (argv[optind], &user, &group, &username, &groupname);
+ if (e)
+ error (1, 0, "%s: %s", argv[optind], e);
+ if (username == NULL)
+ username = "";
+
+ for (++optind; optind < argc; ++optind)
+ {
+ strip_trailing_slashes (argv[optind]);
+ errors |= change_file_owner (argv[optind], user, group);
+ }
+
+ exit (errors);
+}