[llvm-commits] [llvm] r130879 - /llvm/trunk/runtime/libprofile/GCDAProfiling.c

Nick Lewycky nicholas at mxc.ca
Wed May 4 15:34:29 PDT 2011


Author: nicholas
Date: Wed May  4 17:34:29 2011
New Revision: 130879

URL: http://llvm.org/viewvc/llvm-project?rev=130879&view=rev
Log:
Create the parent directories to place the .gcda files in if they don't exist.
That's kinda weird because the .gcno files are supposed to already be there,
but libgcov does this and somehow Google has managed to depend on it.

Modified:
    llvm/trunk/runtime/libprofile/GCDAProfiling.c

Modified: llvm/trunk/runtime/libprofile/GCDAProfiling.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/runtime/libprofile/GCDAProfiling.c?rev=130879&r1=130878&r2=130879&view=diff
==============================================================================
--- llvm/trunk/runtime/libprofile/GCDAProfiling.c (original)
+++ llvm/trunk/runtime/libprofile/GCDAProfiling.c Wed May  4 17:34:29 2011
@@ -24,6 +24,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
 /* #define DEBUG_GCDAPROFILING */
 
@@ -64,6 +66,21 @@
   return filename;
 }
 
+static void recursive_mkdir(const char *filename) {
+  char *pathname;
+  int i, e;
+
+  for (i = 1, e = strlen(filename); i != e; ++i) {
+    if (filename[i] == '/') {
+      pathname = malloc(i + 1);
+      strncpy(pathname, filename, i);
+      pathname[i] = '\0';
+      mkdir(pathname, 0750);  /* some of these will fail, ignore it. */
+      free(pathname);
+    }
+  }
+}
+
 /*
  * --- LLVM line counter API ---
  */
@@ -75,6 +92,7 @@
 void llvm_gcda_start_file(const char *orig_filename) {
   char *filename;
   filename = mangle_filename(orig_filename);
+  recursive_mkdir(filename);
   output_file = fopen(filename, "wb");
 
   /* gcda file, version 404*, stamp LLVM. */





More information about the llvm-commits mailing list