]> Savannah Git Hosting - gnulib.git/commit
areadlink-with-size: guess a buffer size with 0 size
authorPádraig Brady <P@draigBrady.com>
Sat, 6 Jul 2019 18:43:11 +0000 (19:43 +0100)
committerPádraig Brady <P@draigBrady.com>
Sat, 6 Jul 2019 18:53:41 +0000 (19:53 +0100)
commit0ccc444f3d2dc3ad1b4d682f7d8403633942ed39
tree98d4760515344ebc05a51e0ee63ad74585522af1
parent32a64c67192c9d9a892a9f52473cc402d7e9c135
areadlink-with-size: guess a buffer size with 0 size

The size is usually taken from st_size, which can be zero,
resulting in inefficient operation as seen with:

  $ strace -e readlink stat -c %N /proc/$$/cwd
  readlink("/proc/9036/cwd", "/", 1)      = 1
  readlink("/proc/9036/cwd", "/h", 2)     = 2
  readlink("/proc/9036/cwd", "/hom", 4)   = 4
  readlink("/proc/9036/cwd", "/home/pa", 8) = 8
  readlink("/proc/9036/cwd", "/home/padraig", 16) = 13

Instead let zero select an initial memory allocation
of 128 bytes, which most symlinks fit within.

* lib/areadlink-with-size.c (areadlink_with_size):
Start with a 128 byte buffer, for SIZE == 0.
* lib/areadlinkat-with-size.c (areadlinkat_with_size): Likewise.
ChangeLog
lib/areadlink-with-size.c
lib/areadlinkat-with-size.c