diff options
author | Alan Coopersmith <alan.coopersmith@sun.com> | 2007-11-26 13:21:18 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@sun.com> | 2007-11-26 13:21:18 -0800 |
commit | 6f4560e2ad81736127d2d3544415a05d41e8a2a7 (patch) | |
tree | 6c53b2585d1081cf9296c09cd22acee1e9ac9a4f /lock.c | |
parent | fab9dcb15024996ac3a4f94d65ba73f484820534 (diff) |
Use snprintf, strdup & remove instead of sprintf, malloc/strcpy & unlink
Diffstat (limited to 'lock.c')
-rw-r--r-- | lock.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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) { |