aboutsummaryrefslogtreecommitdiffstats
path: root/src/filelock.c
diff options
context:
space:
mode:
authorPaul Eggert2011-03-31 23:28:48 -0700
committerPaul Eggert2011-03-31 23:28:48 -0700
commitd1fdcab7425f36a34ddeaf304e2c6e3c471ba8db (patch)
treef59643a560ce58433a9a92dfe615dd18aecc0457 /src/filelock.c
parent63139bfa89692ec666815f57d0658996577a80d3 (diff)
downloademacs-d1fdcab7425f36a34ddeaf304e2c6e3c471ba8db.tar.gz
emacs-d1fdcab7425f36a34ddeaf304e2c6e3c471ba8db.zip
Replace two copies of readlink code with single gnulib version.
Diffstat (limited to 'src/filelock.c')
-rw-r--r--src/filelock.c38
1 files changed, 10 insertions, 28 deletions
diff --git a/src/filelock.c b/src/filelock.c
index 2138eaa502b..13b27c72f19 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -396,36 +396,16 @@ within_one_second (time_t a, time_t b)
396static int 396static int
397current_lock_owner (lock_info_type *owner, char *lfname) 397current_lock_owner (lock_info_type *owner, char *lfname)
398{ 398{
399 int len, ret; 399 int ret;
400 size_t len;
400 int local_owner = 0; 401 int local_owner = 0;
401 char *at, *dot, *colon; 402 char *at, *dot, *colon;
402 char *lfinfo = 0; 403 char readlink_buf[READLINK_BUFSIZE];
403 int bufsize = 50; 404 char *lfinfo = emacs_readlink (lfname, readlink_buf);
404 /* Read arbitrarily-long contents of symlink. Similar code in
405 file-symlink-p in fileio.c. */
406 do
407 {
408 bufsize *= 2;
409 lfinfo = (char *) xrealloc (lfinfo, bufsize);
410 errno = 0;
411 len = readlink (lfname, lfinfo, bufsize);
412#ifdef ERANGE
413 /* HP-UX reports ERANGE if the buffer is too small. */
414 if (len == -1 && errno == ERANGE)
415 len = bufsize;
416#endif
417 }
418 while (len >= bufsize);
419 405
420 /* If nonexistent lock file, all is well; otherwise, got strange error. */ 406 /* If nonexistent lock file, all is well; otherwise, got strange error. */
421 if (len == -1) 407 if (!lfinfo)
422 { 408 return errno == ENOENT ? 0 : -1;
423 xfree (lfinfo);
424 return errno == ENOENT ? 0 : -1;
425 }
426
427 /* Link info exists, so `len' is its length. Null terminate. */
428 lfinfo[len] = 0;
429 409
430 /* Even if the caller doesn't want the owner info, we still have to 410 /* Even if the caller doesn't want the owner info, we still have to
431 read it to determine return value, so allocate it. */ 411 read it to determine return value, so allocate it. */
@@ -441,7 +421,8 @@ current_lock_owner (lock_info_type *owner, char *lfname)
441 dot = strrchr (lfinfo, '.'); 421 dot = strrchr (lfinfo, '.');
442 if (!at || !dot) 422 if (!at || !dot)
443 { 423 {
444 xfree (lfinfo); 424 if (lfinfo != readlink_buf)
425 xfree (lfinfo);
445 return -1; 426 return -1;
446 } 427 }
447 len = at - lfinfo; 428 len = at - lfinfo;
@@ -467,7 +448,8 @@ current_lock_owner (lock_info_type *owner, char *lfname)
467 owner->host[len] = 0; 448 owner->host[len] = 0;
468 449
469 /* We're done looking at the link info. */ 450 /* We're done looking at the link info. */
470 xfree (lfinfo); 451 if (lfinfo != readlink_buf)
452 xfree (lfinfo);
471 453
472 /* On current host? */ 454 /* On current host? */
473 if (STRINGP (Fsystem_name ()) 455 if (STRINGP (Fsystem_name ())