On Wed, Nov 01, 2023 at 02:02:12PM +0000, Helge Kreutzmann wrote: > Without further ado, the following was found: > > Issue: the link target → link target Fixed: Thanks, Alex > > "#include Elimits.hE\n" > "#include Estdio.hE\n" > "#include Estdlib.hE\n" > "#include Esys/stat.hE\n" > "#include Eunistd.hE\n" > "\\&\n" > "int\n" > "main(int argc, char *argv[])\n" > "{\n" > " char *buf;\n" > " ssize_t nbytes, bufsiz;\n" > " struct stat sb;\n" > "\\&\n" > " if (argc != 2) {\n" > " fprintf(stderr, \"Usage: %s EpathnameE\\en\", argv[0]);\n" > " exit(EXIT_FAILURE);\n" > " }\n" > "\\&\n" > " if (lstat(argv[1], &sb) == -1) {\n" > " perror(\"lstat\");\n" > " exit(EXIT_FAILURE);\n" > " }\n" > "\\&\n" > " /* Add one to the link size, so that we can determine whether\n" > " the buffer returned by readlink() was truncated. */\n" > "\\&\n" > " bufsiz = sb.st_size + 1;\n" > "\\&\n" > " /* Some magic symlinks under (for example) /proc and /sys\n" > " report \\[aq]st_size\\[aq] as zero. In that case, take PATH_MAX as\n" > " a \"good enough\" estimate. */\n" > "\\&\n" > " if (sb.st_size == 0)\n" > " bufsiz = PATH_MAX;\n" > "\\&\n" > " buf = malloc(bufsiz);\n" > " if (buf == NULL) {\n" > " perror(\"malloc\");\n" > " exit(EXIT_FAILURE);\n" > " }\n" > "\\&\n" > " nbytes = readlink(argv[1], buf, bufsiz);\n" > " if (nbytes == -1) {\n" > " perror(\"readlink\");\n" > " exit(EXIT_FAILURE);\n" > " }\n" > "\\&\n" > " /* Print only \\[aq]nbytes\\[aq] of \\[aq]buf\\[aq], as it doesn't contain a terminating\n" > " null byte (\\[aq]\\e0\\[aq]). */\n" > " printf(\"\\[aq]%s\\[aq] points to \\[aq]%.*s\\[aq]\\en\", argv[1], (int) nbytes, buf);\n" > "\\&\n" > " /* If the return value was equal to the buffer size, then the\n" > " the link target was larger than expected (perhaps because the\n" > " target was changed between the call to lstat() and the call to\n" > " readlink()). Warn the user that the returned target may have\n" > " been truncated. */\n" > "\\&\n" > " if (nbytes == bufsiz)\n" > " printf(\"(Returned buffer may have been truncated)\\en\");\n" > "\\&\n" > " free(buf);\n" > " exit(EXIT_SUCCESS);\n" > "}\n" --