[llvm-commits] [compiler-rt] r157571 - /compiler-rt/trunk/lib/profile/GCDAProfiling.c
Bill Wendling
isanbard at gmail.com
Mon May 28 02:41:48 PDT 2012
Author: void
Date: Mon May 28 04:41:48 2012
New Revision: 157571
URL: http://llvm.org/viewvc/llvm-project?rev=157571&view=rev
Log:
* A bit of cleanup of the 'recursive_mkdir'. No functionality change.
* Check for absolute paths before using the GCOV_PREFIX.
* Don't add an ending path separator if there's already one.
Modified:
compiler-rt/trunk/lib/profile/GCDAProfiling.c
Modified: compiler-rt/trunk/lib/profile/GCDAProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/GCDAProfiling.c?rev=157571&r1=157570&r2=157571&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/GCDAProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/GCDAProfiling.c Mon May 28 04:41:48 2012
@@ -68,37 +68,35 @@
static char *mangle_filename(const char *orig_filename) {
/* TODO: handle GCOV_PREFIX_STRIP */
- const char *prefix;
char *filename = 0;
+ int prefix_len = 0;
+ const char *prefix = getenv("GCOV_PREFIX");
- prefix = getenv("GCOV_PREFIX");
-
- if (!prefix)
+ if (!prefix || prefix[0] != '/') /* Ignore non-absolute paths */
return strdup(orig_filename);
- filename = malloc(strlen(prefix) + 1 + strlen(orig_filename) + 1);
+ prefix_len = strlen(prefix);
+ filename = malloc(prefix_len + 1 + strlen(orig_filename) + 1);
strcpy(filename, prefix);
- strcat(filename, "/");
+ if (prefix[prefix_len - 1] != '/')
+ strcat(filename, "/");
strcat(filename, orig_filename);
return filename;
}
-static void recursive_mkdir(const char *filename) {
- char *pathname;
- int i, e;
+static void recursive_mkdir(char *filename) {
+ int i;
- for (i = 1, e = strlen(filename); i != e; ++i) {
+ for (i = 1; filename[i] != '\0'; ++i) {
if (filename[i] != '/') continue;
- pathname = malloc(i + 1);
- strncpy(pathname, filename, i);
- pathname[i] = '\0';
+ filename[i] = '\0';
#ifdef _WIN32
- _mkdir(pathname);
+ _mkdir(filename);
#else
- mkdir(pathname, 0750); /* some of these will fail, ignore it. */
+ mkdir(filename, 0755); /* Some of these will fail, ignore it. */
#endif
- free(pathname);
+ filename[i] = '/';
}
}
@@ -111,13 +109,12 @@
* started at a time.
*/
void llvm_gcda_start_file(const char *orig_filename) {
- char *filename;
- filename = mangle_filename(orig_filename);
- recursive_mkdir(filename);
+ char *filename = mangle_filename(orig_filename);
output_file = fopen(filename, "w+b");
if (!output_file) {
int len = strlen(orig_filename) - 1;
+ recursive_mkdir(filename);
for (; len >= 0 && orig_filename[len] != '/'; --len)
/* empty */;
More information about the llvm-commits
mailing list