~vcs-imports/busybox/trunk

« back to all changes in this revision

Viewing changes to miscutils/getfattr.c

  • Committer: Denys Vlasenko
  • Date: 2023-07-17 07:36:17 UTC
  • Revision ID: git-v1:a6a102ec4c8d96fcfb968c88fbdae80f6142c7bf
getfattr: fix "getfattr NOTEXIST" - now prints error msg

function                                             old     new   delta
getfattr_main                                        309     307      -2
.rodata                                           105395  105391      -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-6)               Total: -6 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
enum {
32
32
        OPT_h = (1 << 0),
33
33
        OPT_d = (1 << 1),
 
34
        OPT_n = (1 << 2),
34
35
};
35
36
 
36
37
static int print_attr(const char *file, const char *name, char **buf, size_t *bufsize)
85
86
 
86
87
        opt = getopt32(argv, "^"
87
88
                "hdn:"
88
 
                /* Min one arg; exactly one of -n or -d is required. */
89
 
                "\0" "-1:d:n:n--d:d--n"
 
89
                /* Min one arg; -d and -n are exclusive */
 
90
                "\0" "-1:n--d:d--n"
 
91
                        //getfattr 2.5.1 does not enforce this: ":d:n" /* exactly one of -n or -d is required */
90
92
                , &name
91
93
        );
92
94
        argv += optind;
94
96
 
95
97
        do {
96
98
                int r;
97
 
                if (opt & OPT_d) {
 
99
//getfattr 2.5.1 with no -n/-d defaults to -d
 
100
                if (!(opt & OPT_n)) {
98
101
                        ssize_t len = list_attr(*argv, &list, &listsize);
 
102
                        if (len < 0)
 
103
                                goto err;
99
104
                        if (len > 0) {
100
105
                                char *key;
101
106
                                printf("# file: %s\n", *argv);
118
123
 err:
119
124
                                bb_simple_perror_msg(*argv);
120
125
                                status = EXIT_FAILURE;
121
 
                                // continue; maybe?
 
126
                                continue;
122
127
                        }
123
128
                        bb_putchar('\n');
124
129
                }