diff options
Diffstat (limited to 'libXau/AuLock.c')
-rw-r--r-- | libXau/AuLock.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/libXau/AuLock.c b/libXau/AuLock.c index 7bf9e5d30..5dfc1747e 100644 --- a/libXau/AuLock.c +++ b/libXau/AuLock.c @@ -33,15 +33,12 @@ in this Software without prior written authorization from The Open Group. #include <errno.h> #include <time.h> #define Time_t time_t -#ifndef X_NOT_POSIX -#include <unistd.h> -#else -#ifndef WIN32 -extern unsigned sleep (); -#else -#include <X11/Xwindows.h> -#define link rename +#ifdef HAVE_UNISTD_H +# include <unistd.h> #endif +#ifdef WIN32 +# include <X11/Xwindows.h> +# define link rename #endif int @@ -58,10 +55,8 @@ long dead) if (strlen (file_name) > 1022) return LOCK_ERROR; - (void) strcpy (creat_name, file_name); - (void) strcat (creat_name, "-c"); - (void) strcpy (link_name, file_name); - (void) strcat (link_name, "-l"); + snprintf (creat_name, sizeof(creat_name), "%s-c", file_name); + snprintf (link_name, sizeof(link_name), "%s-l", file_name); if (stat (creat_name, &statb) != -1) { now = time ((Time_t *) 0); /* @@ -69,8 +64,8 @@ long dead) * case a 0 deadtime to force lock removal */ if (dead == 0 || now - statb.st_ctime > dead) { - (void) unlink (creat_name); - (void) unlink (link_name); + (void) remove (creat_name); + (void) remove (link_name); } } @@ -84,7 +79,7 @@ long dead) (void) close (creat_fd); } if (creat_fd != -1) { -#ifndef X_NOT_POSIX +#ifdef HAVE_PATHCONF /* The file system may not support hard links, and pathconf should tell us that. */ if (1 == pathconf(creat_name, _PC_LINK_MAX)) { if (-1 == rename(creat_name, link_name)) { @@ -93,8 +88,9 @@ long dead) } else { return LOCK_SUCCESS; } - } else { + } else #endif + { if (link (creat_name, link_name) != -1) return LOCK_SUCCESS; if (errno == ENOENT) { @@ -103,9 +99,7 @@ long dead) } if (errno != EEXIST) return LOCK_ERROR; -#ifndef X_NOT_POSIX } -#endif } (void) sleep ((unsigned) timeout); --retries; |