[PATCH] convert local constant arrays to static

Denis Vlasenko vda at ilport.com.ua
Wed Feb 22 14:07:57 UTC 2006


On Wednesday 22 February 2006 11:30, Bernd Petrovitsch wrote:
> On Wed, 2006-02-22 at 09:00 +0200, Denis Vlasenko wrote:
> [...]
> > Patch basically does this:
> Nice - "const"ing is always a good thing.
> > -               char *extn[] = {"", ".zip", ".ZIP"};
> > +               static const char *const extn[] = {"", ".zip", ".ZIP"};
> 
> <anal>
> Probably in this one case
> ----  snip  ----
> static const char extn[5] = {"", ".zip", ".ZIP"};
> ----  snip  ----
> saves a few bytes since there are no 4-byte pointers in between.
> </anal>

You will need to change the code:

        } else {
                static const char *const extn[] = {"", ".zip", ".ZIP"};
                int orig_src_fn_len = strlen(src_fn);
                for(i = 0; (i < 3) && (src_fd == -1); i++) {
                        strcpy(src_fn + orig_src_fn_len, extn[i]);
                        src_fd = open(src_fn, O_RDONLY);
                }
                if (src_fd == -1) {
                        src_fn[orig_src_fn_len] = 0;
                        bb_error_msg_and_die("Cannot open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
                }
        }

--
vda



More information about the busybox mailing list