summaryrefslogtreecommitdiff
path: root/lock.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@sun.com>2007-11-26 13:21:18 -0800
committerAlan Coopersmith <alan.coopersmith@sun.com>2007-11-26 13:21:18 -0800
commit6f4560e2ad81736127d2d3544415a05d41e8a2a7 (patch)
tree6c53b2585d1081cf9296c09cd22acee1e9ac9a4f /lock.c
parentfab9dcb15024996ac3a4f94d65ba73f484820534 (diff)
Use snprintf, strdup & remove instead of sprintf, malloc/strcpy & unlink
Diffstat (limited to 'lock.c')
-rw-r--r--lock.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/lock.c b/lock.c
index f4d3848..3170458 100644
--- a/lock.c
+++ b/lock.c
@@ -59,10 +59,13 @@ LockSession(char *session_name, Bool write_id)
path = GetPath ();
#ifndef __UNIXOS2__
- sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
- sprintf (temp_lock_file, "%s/.XSMtlock-%s", path, session_name);
+ snprintf (lock_file, sizeof(lock_file), "%s/.XSMlock-%s",
+ path, session_name);
+ snprintf (temp_lock_file, sizeof(temp_lock_file), "%s/.XSMtlock-%s",
+ path, session_name);
#else
- sprintf (temp_lock_file, "%s/%s.slk", path, session_name);
+ snprintf (temp_lock_file, sizeof(temp_lock_file), "%s/%s.slk",
+ path, session_name);
#endif
if ((fd = creat (temp_lock_file, 0444)) < 0)
@@ -84,7 +87,7 @@ LockSession(char *session_name, Bool write_id)
if (link (temp_lock_file, lock_file) < 0)
status = 0;
- if (unlink (temp_lock_file) < 0)
+ if (remove (temp_lock_file) < 0)
status = 0;
#else
status = 0;
@@ -102,9 +105,10 @@ UnlockSession(char *session_name)
path = GetPath ();
- sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
+ snprintf (lock_file, sizeof(lock_file), "%s/.XSMlock-%s",
+ path, session_name);
- unlink (lock_file);
+ remove (lock_file);
}
@@ -119,7 +123,8 @@ GetLockId(char *session_name)
path = GetPath ();
- sprintf (lock_file, "%s/.XSMlock-%s", path, session_name);
+ snprintf (lock_file, sizeof(lock_file), "%s/.XSMlock-%s",
+ path, session_name);
if ((fp = fopen (lock_file, "r")) == NULL)
{