[uclibc-ng-devel] about "implement fexecve from glibc"

Waldemar Brodkorb wbx at uclibc-ng.org
Sun Nov 17 17:26:00 CET 2019

Hi Yann,
Yann Sionneau wrote,

> Hello,
> About https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/commit/?id=858ffad217076227089cc17eb832db0bd1497792
> I'm not sure why exactly sizeof(int)*3 in the following line:
> char buf[sizeof "/proc/self/fd/" + sizeof (int) * 3];
> IIUC, this is supposed to give room for the ascii decimal representation of
> the file descriptor number.
> Maybe we could read the max file descriptor number configured in the kernel
> from "/proc/sys/fs/file-max" (or "/proc/sys/file-max" for old systems?).
> So:
> 1/ fopen("/proc/sys/fs/file-max", "r");
> 2/ fscanf(fp, "%d", &fdmax);
> 3/ fdmax_length = log10(fdmax);
> Then use fdmax_length
> Or, much simpler: take for granted that fd is always an int, and thus max 32
> bits, and hard code that max "string length" of a file descriptor is 10
> chars.
> But in any case maybe add a comment on top of the line to explain the "magic
> number".

I checked with glibc/musl and both seems to use this magic number
for granted. Could you sent a patch with a comment to the existing

best regards

More information about the devel mailing list