[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH attr] tools: mark local vars & funcs static
From: |
Mike Frysinger |
Subject: |
[PATCH attr] tools: mark local vars & funcs static |
Date: |
Wed, 31 Jan 2024 23:44:17 -0500 |
These programs have a lot of local vars & funcs that don't need to
be exported. Mark them static to cleanup, and the compiler is able
to produce smaller code as a result.
---
tools/attr.c | 2 +-
tools/getfattr.c | 48 ++++++++++++++++++++++---------------------
tools/setfattr.c | 53 ++++++++++++++++++++++++------------------------
3 files changed, 52 insertions(+), 51 deletions(-)
diff --git a/tools/attr.c b/tools/attr.c
index 312aef16ccb3..f12e4afa44ed 100644
--- a/tools/attr.c
+++ b/tools/attr.c
@@ -42,7 +42,7 @@
static char *progname;
-void
+static void
usage(void)
{
fprintf(stderr, _(
diff --git a/tools/getfattr.c b/tools/getfattr.c
index c0b733dbcb44..540e2dcc1acf 100644
--- a/tools/getfattr.c
+++ b/tools/getfattr.c
@@ -55,19 +55,19 @@ static const struct option long_options[] = {
{ NULL, 0, 0, 0 }
};
-int walk_flags = WALK_TREE_DEREFERENCE;
-int opt_dump; /* dump attribute values (or only list the names) */
-char *opt_name; /* dump named attributes */
-char *opt_name_pattern = "^user\\."; /* include only matching names */
-char *opt_encoding; /* encode values automatically (NULL), or as "text",
- "hex", or "base64" */
-char opt_value_only; /* dump the value only, without any decoration */
-int opt_strip_leading_slash = 1; /* strip leading '/' from path names */
+static int walk_flags = WALK_TREE_DEREFERENCE;
+static int opt_dump; /* dump attribute values (or only list the names) */
+static char *opt_name; /* dump named attributes */
+static char *opt_name_pattern = "^user\\."; /* include only matching names */
+static char *opt_encoding; /* encode values automatically (NULL), or as
"text",
+ "hex", or "base64" */
+static char opt_value_only; /* dump the value only, without any decoration */
+static int opt_strip_leading_slash = 1; /* strip leading '/' from path names
*/
-const char *progname;
-int absolute_warning;
-int had_errors;
-regex_t name_regex;
+static const char *progname;
+static int absolute_warning;
+static int had_errors;
+static regex_t name_regex;
static const char *xquote(const char *str, const char *quote_chars)
@@ -80,19 +80,20 @@ static const char *xquote(const char *str, const char
*quote_chars)
return q;
}
-int do_getxattr(const char *path, const char *name, void *value, size_t size)
+static int do_getxattr(const char *path, const char *name, void *value,
+ size_t size)
{
return ((walk_flags & WALK_TREE_DEREFERENCE) ?
getxattr : lgetxattr)(path, name, value, size);
}
-int do_listxattr(const char *path, char *list, size_t size)
+static int do_listxattr(const char *path, char *list, size_t size)
{
return ((walk_flags & WALK_TREE_DEREFERENCE) ?
listxattr : llistxattr)(path, list, size);
}
-const char *strerror_ea(int err)
+static const char *strerror_ea(int err)
{
#ifdef __linux__
/* The Linux kernel does not define ENOATTR, but maps it to ENODATA. */
@@ -102,12 +103,12 @@ const char *strerror_ea(int err)
return strerror(err);
}
-int pstrcmp(const void *a, const void *b)
+static int pstrcmp(const void *a, const void *b)
{
return strcmp(*(const char **)a, *(const char **)b);
}
-int well_enough_printable(const char *value, size_t size)
+static int well_enough_printable(const char *value, size_t size)
{
size_t n, nonpr = 0;
@@ -122,7 +123,7 @@ int well_enough_printable(const char *value, size_t size)
return (size >= nonpr*8); /* no more than 1/8 non-printable chars */
}
-const char *encode(const char *value, size_t *size)
+static const char *encode(const char *value, size_t *size)
{
static char *encoded;
static size_t encoded_size;
@@ -229,7 +230,8 @@ const char *encode(const char *value, size_t *size)
return encoded;
}
-int print_attribute(const char *path, const char *name, int *header_printed)
+static int print_attribute(const char *path, const char *name,
+ int *header_printed)
{
static char *value;
static size_t value_size;
@@ -294,7 +296,7 @@ int print_attribute(const char *path, const char *name, int
*header_printed)
return 0;
}
-int list_attributes(const char *path, int *header_printed)
+static int list_attributes(const char *path, int *header_printed)
{
static char *list;
static size_t list_size;
@@ -356,8 +358,8 @@ int list_attributes(const char *path, int *header_printed)
return 0;
}
-int do_print(const char *path, const struct stat *stat, int walk_flags,
- void *unused)
+static int do_print(const char *path, const struct stat *stat, int walk_flags,
+ void *unused)
{
int header_printed = 0;
int err = 0;
@@ -378,7 +380,7 @@ int do_print(const char *path, const struct stat *stat, int
walk_flags,
return err;
}
-void help(void)
+static void help(void)
{
printf(_("%s %s -- get extended attributes\n"),
progname, VERSION);
diff --git a/tools/setfattr.c b/tools/setfattr.c
index c4e2d79d9f9d..737344e2dd68 100644
--- a/tools/setfattr.c
+++ b/tools/setfattr.c
@@ -50,24 +50,23 @@ static const struct option long_options[] = {
{ NULL, 0, 0, 0 }
};
-char *opt_name; /* attribute name to set */
-char *opt_value; /* attribute value */
-int opt_set; /* set an attribute */
-int opt_remove; /* remove an attribute */
-int opt_restore; /* restore has been run */
-int opt_deref = 1; /* dereference symbolic links */
-int opt_raw; /* attribute value is not encoded */
-
-int had_errors;
-const char *progname;
-
-int do_set(const char *path, const char *name, const char *value);
-const char *decode(const char *value, size_t *size);
-int restore(const char *filename);
-int hex_digit(char c);
-int base64_digit(char c);
-
-const char *strerror_ea(int err)
+static char *opt_name; /* attribute name to set */
+static char *opt_value; /* attribute value */
+static int opt_set; /* set an attribute */
+static int opt_remove; /* remove an attribute */
+static int opt_restore; /* restore has been run */
+static int opt_deref = 1; /* dereference symbolic links */
+static int opt_raw; /* attribute value is not encoded */
+
+static int had_errors;
+static const char *progname;
+
+static int do_set(const char *path, const char *name, const char *value);
+static const char *decode(const char *value, size_t *size);
+static int hex_digit(char c);
+static int base64_digit(char c);
+
+static const char *strerror_ea(int err)
{
#ifdef __linux__
/* The Linux kernel does not define ENOATTR, but maps it to ENODATA. */
@@ -87,18 +86,18 @@ static const char *xquote(const char *str, const char
*quote_chars)
return q;
}
-int do_setxattr(const char *path, const char *name,
- const void *value, size_t size)
+static int do_setxattr(const char *path, const char *name,
+ const void *value, size_t size)
{
return (opt_deref ? setxattr : lsetxattr)(path, name, value, size, 0);
}
-int do_removexattr(const char *path, const char *name)
+static int do_removexattr(const char *path, const char *name)
{
return (opt_deref ? removexattr : lremovexattr)(path, name);
}
-int restore(const char *filename)
+static int restore(const char *filename)
{
static char *path;
static size_t path_size;
@@ -175,7 +174,7 @@ cleanup:
return status;
}
-void help(void)
+static void help(void)
{
printf(_("%s %s -- set extended attributes\n"), progname, VERSION);
printf(_("Usage: %s %s\n"), progname, CMD_LINE_SPEC1);
@@ -268,7 +267,7 @@ synopsis:
return 2;
}
-int do_set(const char *path, const char *name, const char *value)
+static int do_set(const char *path, const char *name, const char *value)
{
size_t size = 0;
int error;
@@ -294,7 +293,7 @@ int do_set(const char *path, const char *name, const char
*value)
return 0;
}
-const char *decode(const char *value, size_t *size)
+static const char *decode(const char *value, size_t *size)
{
static char *decoded;
static size_t decoded_size;
@@ -444,7 +443,7 @@ const char *decode(const char *value, size_t *size)
return decoded;
}
-int hex_digit(char c)
+static int hex_digit(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
@@ -456,7 +455,7 @@ int hex_digit(char c)
return -1;
}
-int base64_digit(char c)
+static int base64_digit(char c)
{
if (c >= 'A' && c <= 'Z')
return c - 'A';
--
2.43.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH attr] tools: mark local vars & funcs static,
Mike Frysinger <=