summaryrefslogtreecommitdiff
path: root/lockfile.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2014-10-01 10:28:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-10-01 20:45:11 (GMT)
commit7108ad232fc7a4c889e82b40c52125adc9796ff5 (patch)
tree21a15d1fe052aa839d0b4f536da92695b74d0f1b /lockfile.c
parent0a06f148373285822baf5f3e83696732a556a2d1 (diff)
downloadgit-7108ad232fc7a4c889e82b40c52125adc9796ff5.zip
git-7108ad232fc7a4c889e82b40c52125adc9796ff5.tar.gz
git-7108ad232fc7a4c889e82b40c52125adc9796ff5.tar.bz2
cache.h: define constants LOCK_SUFFIX and LOCK_SUFFIX_LEN
There are a few places that use these values, so define constants for them. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'lockfile.c')
-rw-r--r--lockfile.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lockfile.c b/lockfile.c
index 2680dc9..23847fc 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -166,10 +166,11 @@ static char *resolve_symlink(char *p, size_t s)
static int lock_file(struct lock_file *lk, const char *path, int flags)
{
/*
- * subtract 5 from size to make sure there's room for adding
- * ".lock" for the lock file name
+ * subtract LOCK_SUFFIX_LEN from size to make sure there's
+ * room for adding ".lock" for the lock file name:
*/
- static const size_t max_path_len = sizeof(lk->filename) - 5;
+ static const size_t max_path_len = sizeof(lk->filename) -
+ LOCK_SUFFIX_LEN;
if (!lock_file_list) {
/* One-time initialization */
@@ -194,7 +195,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
strcpy(lk->filename, path);
if (!(flags & LOCK_NODEREF))
resolve_symlink(lk->filename, max_path_len);
- strcat(lk->filename, ".lock");
+ strcat(lk->filename, LOCK_SUFFIX);
lk->fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
if (0 <= lk->fd) {
lk->owner = getpid();
@@ -308,7 +309,7 @@ int commit_lock_file(struct lock_file *lk)
if (close_lock_file(lk))
return -1;
strcpy(result_file, lk->filename);
- i = strlen(result_file) - 5; /* .lock */
+ i = strlen(result_file) - LOCK_SUFFIX_LEN; /* .lock */
result_file[i] = 0;
if (rename(lk->filename, result_file))
return -1;