Bug#844038: ocamlnet: FTBFS on hurd-i386: PATH_MAX
Hello,
Agreed, here is a fixed patch.
Samuel
--- ./src/netsys/netsys_c.c.original 2016-11-20 18:55:38.789583992 +0100
+++ ./src/netsys/netsys_c.c 2016-11-20 19:00:46.708028548 +0100
@@ -607,12 +607,34 @@
CAMLprim value netsys_readlinkat(value dirfd, value path)
{
#ifdef HAVE_AT
- char buffer[PATH_MAX];
- int len;
- len = readlinkat(Int_val(dirfd), String_val(path), buffer, sizeof(buffer)-1);
- if (len == -1) uerror("readlinkat", path);
+ char *buffer;
+ int buflen, len;
+ struct stat sb;
+ value ret;
+ if (fstatat(Int_val(dirfd), String_val(path), &sb, AT_SYMLINK_NOFOLLOW) != -1) {
+ if (!S_ISLNK(sb.st_mode))
+ unix_error(EINVAL, "readlinkat", path);
+ buflen = sb.st_size + 1;
+ }
+ else {
+ buflen = 64;
+ }
+ while (1) {
+ buffer = malloc(buflen);
+ len = readlinkat(Int_val(dirfd), String_val(path), buffer, buflen);
+ if (len == -1) {
+ free(buffer);
+ uerror("readlinkat", path);
+ }
+ if (len < buflen)
+ break;
+ free(buffer);
+ buflen *= 2;
+ }
buffer[len] = '\0';
- return copy_string(buffer);
+ ret = copy_string(buffer);
+ free(buffer);
+ return ret;
#else
invalid_argument("Netsys_posix.readlinkat not available");
#endif
Reply to: