shell function name length, question
Roberto A. Foglietta
roberto.foglietta at gmail.com
Sat Aug 14 13:54:02 UTC 2021
Il giorno sab 14 ago 2021 alle ore 15:37 Emmanuel Deloget <logout at free.fr>
ha scritto:
> Hello,
>
> On Sat, Aug 14, 2021 at 12:19 PM Roberto A. Foglietta
> <roberto.foglietta at gmail.com> wrote:
> >
> > Hi all,
> >
> > how long could be a shell function name?
> >
> > In my last patch, I used 256 characters because: "On Linux: The maximum
> length for a file name is 255 bytes". So, I have extended the concept to a
> function name but it is not the same.
> >
> > Thank you,
>
> According to the discussion in [1], both bash and NETBSD sh can be
> used with identifiers that are longer than 1000 characters. Bash seems
> to not have any limit on identifier names. The POSIX sh standard
> itself does not define anything related to the length of any
> identifier (be it a variable name or a function name).
>
> (I would totally accept shorter identifiers ; mine rarely goes larger
> than 30-40 bytes, and these are the longest ; yet it's not difficult
> to image a processor that could create longer identifier names).
>
I checked what happens when the function name is longer than the size of
the buffer: nothing bad.
The buffer is going to be filled but I did not see any buffer overrun. Thus
it is safe, AFAIK.
Reporting only the first 256 characters of the function name seems also to
me enough.
roberto at vm-ubuntu18:~/tinycore-editor/busybox$ gcc -o test6 test6.c
roberto at vm-ubuntu18:~/tinycore-editor/busybox$ ./test6
output: 'FUNCNAME=ciao'
Ciao,
-R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210814/b7a35b1e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test6.c
Type: application/octet-stream
Size: 548 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210814/b7a35b1e/attachment.obj>
More information about the busybox
mailing list