changeset 39281:269a01a4ee76

(Ffile_symlink_p): If readlink returns ERANGE, take that to mean that the buffer is too small.
author Gerd Moellmann <gerd@gnu.org>
date Thu, 13 Sep 2001 14:01:34 +0000
parents bc862ea297a8
children 468b3ac5ff23
files src/fileio.c
diffstat 1 files changed, 19 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c	Thu Sep 13 13:05:37 2001 +0000
+++ b/src/fileio.c	Thu Sep 13 14:01:34 2001 +0000
@@ -3096,22 +3096,29 @@
 
   filename = ENCODE_FILE (filename);
 
-  bufsize = 100;
-  while (1)
+  bufsize = 50;
+  buf = NULL;
+  do
     {
-      buf = (char *) xmalloc (bufsize);
+      bufsize *= 2;
+      buf = (char *) xrealloc (buf, bufsize);
       bzero (buf, bufsize);
+      
+      errno = 0;
       valsize = readlink (XSTRING (filename)->data, buf, bufsize);
-      if (valsize < bufsize) break;
-      /* Buffer was not long enough */
-      xfree (buf);
-      bufsize *= 2;
+      if (valsize == -1
+#ifdef ERANGE
+	  /* HP-UX reports ERANGE if buffer is too small.  */
+	  && errno != ERANGE
+#endif
+	  )
+	{
+	  xfree (buf);
+	  return Qnil;
+	}
     }
-  if (valsize == -1)
-    {
-      xfree (buf);
-      return Qnil;
-    }
+  while (valsize >= bufsize);
+  
   val = make_string (buf, valsize);
   if (buf[0] == '/' && index (buf, ':'))
     val = concat2 (build_string ("/:"), val);