commit: 70bae280c13bc7a0fedde87775add3e221c1b1aa
Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 24 18:34:19 2026 +0000
Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Tue Feb 24 18:34:19 2026 +0000
URL: https://gitweb.gentoo.org/proj/install-xattr.git/commit/?id=70bae280
Move variable declartions closer to their use
We can assume everybody has a C99 compiler these days.
Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>
install-xattr.c | 41 +++++++++++++++++------------------------
1 file changed, 17 insertions(+), 24 deletions(-)
diff --git a/install-xattr.c b/install-xattr.c
index 7f9fd31..9361865 100644
--- a/install-xattr.c
+++ b/install-xattr.c
@@ -30,6 +30,7 @@
#include <stdlib.h>
#include <signal.h>
#include <spawn.h>
+#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -198,21 +199,6 @@ spawn(char *path, char *argv[])
int
main(int argc, char* argv[])
{
- int i;
- int status; /* exit status of child "install"
process */
-
- int opts_directory = 0; /* if -d was given, then all arguments
are directories */
- int opts_target_directory = 0; /* if -t was given, then we're
installing to a target directory */
- int target_is_directory = 0; /* is the target a directory?
*/
-
- int first, last; /* argv indices of the first
file/directory and last */
- char *target = NULL; /* the target file or directory
*/
- char *path; /* path to the target file
*/
-
- struct stat s; /* test if a file is a regular file or a
directory */
-
- char *portage_xattr_exclude; /* strings of excluded xattr names from
$PORTAGE_XATTR_EXCLUDE */
-
/* If this is set it means Portage has switched the working directory
* and expects us to switch back. */
char *portage_helper_cwd = getenv("__PORTAGE_HELPER_CWD");
@@ -224,7 +210,7 @@ main(int argc, char* argv[])
if (spawn(argv[0], argv) < 0)
err(1, "failed to spawn install");
- portage_xattr_exclude = getenv("PORTAGE_XATTR_EXCLUDE");
+ char *portage_xattr_exclude = getenv("PORTAGE_XATTR_EXCLUDE");
if (portage_xattr_exclude == NULL)
exclude = xstrdup("btrfs.* security.* trusted.*
system.nfs4_acl");
else
@@ -258,6 +244,11 @@ main(int argc, char* argv[])
{ 0, 0, 0, 0 }
};
+ bool opts_directory = false;
+ bool opts_target_directory = false;
+ bool target_is_directory = false;
+ char *target = NULL;
+
while (1) {
int option_index;
int c = getopt_long(argc, argv, "dt:g:m:o:S:Zb", long_options,
&option_index);
@@ -278,11 +269,11 @@ main(int argc, char* argv[])
break;
case 'd':
- opts_directory = 1;
+ opts_directory = true;
break;
case 't':
- opts_target_directory = 1;
+ opts_target_directory = true;
target = optarg;
break;
@@ -291,9 +282,7 @@ main(int argc, char* argv[])
}
}
- first = optind;
- last = argc - 1;
-
+ int status;
wait(&status);
/* Are there enough files/directories on the cmd line to
@@ -301,6 +290,8 @@ main(int argc, char* argv[])
* arguments or with just --help. In which case there is
* nothing for the parent to do.
*/
+ int first = optind;
+ int last = argc - 1;
if (first >= last)
goto done;
@@ -309,6 +300,7 @@ main(int argc, char* argv[])
goto done;
if (!opts_target_directory) {
+ struct stat s;
target = argv[last];
if (stat(target, &s) != 0) {
err(1, "failed to stat %s", target);
@@ -317,7 +309,7 @@ main(int argc, char* argv[])
target_is_directory = S_ISDIR(s.st_mode);
} else {
/* target was set above with the -t option */
- target_is_directory = 1;
+ target_is_directory = true;
}
if (target_is_directory) {
@@ -327,7 +319,8 @@ main(int argc, char* argv[])
if (opts_target_directory)
last++;
- for (i = first; i < last; i++) {
+ for (int i = first; i < last; i++) {
+ struct stat s;
if (stat(argv[i], &s) != 0) {
err(1, "failed to stat %s", argv[i]);
return EXIT_FAILURE;
@@ -339,7 +332,7 @@ main(int argc, char* argv[])
if (S_ISDIR(s.st_mode))
continue;
- path = path_join(target, basename(argv[i]));
+ char *path = path_join(target, basename(argv[i]));
copyxattr(argv[i], path);
free(path);
}