Don't override 'mode' and cleanup some variable names.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@182599 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/profile/GCDAProfiling.c b/lib/profile/GCDAProfiling.c
index e58ccea..ce1b03c 100644
--- a/lib/profile/GCDAProfiling.c
+++ b/lib/profile/GCDAProfiling.c
@@ -52,8 +52,8 @@
/*
* Buffer that we write things into.
*/
-#define NEW_WRITE_BUFFER_SIZE (128 * 1024)
-static char *new_write_buffer = NULL;
+#define WRITE_BUFFER_SIZE (128 * 1024)
+static char *write_buffer = NULL;
static uint64_t cur_buffer_size = 0;
static uint64_t cur_pos = 0;
static uint64_t file_size = 0;
@@ -90,15 +90,15 @@
if (!new_file) return;
size += cur_pos;
if (size <= cur_buffer_size) return;
- size = (size - 1) / NEW_WRITE_BUFFER_SIZE + 1;
- size *= NEW_WRITE_BUFFER_SIZE;
- new_write_buffer = realloc(new_write_buffer, size);
+ size = (size - 1) / WRITE_BUFFER_SIZE + 1;
+ size *= WRITE_BUFFER_SIZE;
+ write_buffer = realloc(write_buffer, size);
cur_buffer_size = size;
}
static void write_bytes(const char *s, size_t len) {
resize_write_buffer(len);
- memcpy(&new_write_buffer[cur_pos], s, len);
+ memcpy(&write_buffer[cur_pos], s, len);
cur_pos += len;
}
@@ -127,7 +127,7 @@
if (new_file)
return (uint32_t)-1;
- val = *(uint32_t*)&new_write_buffer[cur_pos];
+ val = *(uint32_t*)&write_buffer[cur_pos];
cur_pos += 4;
return val;
}
@@ -138,7 +138,7 @@
if (new_file)
return (uint64_t)-1;
- val = *(uint64_t*)&new_write_buffer[cur_pos];
+ val = *(uint64_t*)&write_buffer[cur_pos];
cur_pos += 8;
return val;
}
@@ -200,14 +200,14 @@
fseek(output_file, 0L, SEEK_END);
file_size = ftell(output_file);
- new_write_buffer = mmap(0, file_size, PROT_READ | PROT_WRITE,
- MAP_FILE | MAP_SHARED, fd, 0);
+ write_buffer = mmap(0, file_size, PROT_READ | PROT_WRITE,
+ MAP_FILE | MAP_SHARED, fd, 0);
}
static void unmap_file() {
- msync(new_write_buffer, file_size, MS_SYNC);
- munmap(new_write_buffer, file_size);
- new_write_buffer = NULL;
+ msync(write_buffer, file_size, MS_SYNC);
+ munmap(write_buffer, file_size);
+ write_buffer = NULL;
file_size = 0;
}
@@ -229,14 +229,13 @@
if (fd == -1) {
/* Try opening the file, creating it if necessary. */
- int mode = 0644;
new_file = 1;
mode = "w+b";
- fd = open(filename, O_RDWR | O_CREAT, mode);
+ fd = open(filename, O_RDWR | O_CREAT, 0644);
if (fd == -1) {
/* Try creating the directories first then opening the file. */
recursive_mkdir(filename);
- fd = open(filename, O_RDWR | O_CREAT, mode);
+ fd = open(filename, O_RDWR | O_CREAT, 0644);
if (!output_file) {
/* Bah! It's hopeless. */
fprintf(stderr, "profiling:%s: cannot open\n", filename);
@@ -249,13 +248,13 @@
output_file = fdopen(fd, mode);
/* Initialize the write buffer. */
- new_write_buffer = NULL;
+ write_buffer = NULL;
cur_buffer_size = 0;
cur_pos = 0;
if (new_file) {
- resize_write_buffer(NEW_WRITE_BUFFER_SIZE);
- memset(new_write_buffer, 0, NEW_WRITE_BUFFER_SIZE);
+ resize_write_buffer(WRITE_BUFFER_SIZE);
+ memset(write_buffer, 0, WRITE_BUFFER_SIZE);
} else {
map_file();
}
@@ -375,15 +374,15 @@
write_bytes("\0\0\0\0\0\0\0\0", 8);
if (new_file) {
- fwrite(new_write_buffer, cur_pos, 1, output_file);
- free(new_write_buffer);
+ fwrite(write_buffer, cur_pos, 1, output_file);
+ free(write_buffer);
} else {
unmap_file();
}
fclose(output_file);
output_file = NULL;
- new_write_buffer = NULL;
+ write_buffer = NULL;
#ifdef DEBUG_GCDAPROFILING
fprintf(stderr, "llvmgcda: -----\n");