[compiler-rt] r276027 - [Profile] introduce reusable internal interfaces to find dir separator \NFC

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 19 13:48:03 PDT 2016


Author: davidxl
Date: Tue Jul 19 15:48:00 2016
New Revision: 276027

URL: http://llvm.org/viewvc/llvm-project?rev=276027&view=rev
Log:
[Profile] introduce reusable internal interfaces to find dir separator \NFC

Modified:
    compiler-rt/trunk/lib/profile/InstrProfilingFile.c
    compiler-rt/trunk/lib/profile/InstrProfilingUtil.c
    compiler-rt/trunk/lib/profile/InstrProfilingUtil.h

Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=276027&r1=276026&r2=276027&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Tue Jul 19 15:48:00 2016
@@ -229,11 +229,7 @@ static void truncateCurrentFile(void) {
     return;
 
   /* Create the directory holding the file, if needed. */
-  if (strchr(Filename, DIR_SEPARATOR)
-#if defined(DIR_SEPARATOR_2)
-      || strchr(Filename, DIR_SEPARATOR_2)
-#endif
-          ) {
+  if (lprofFindFirstDirSeparator(Filename)) {
     char *Copy = (char *)COMPILER_RT_ALLOCA(Length + 1);
     strncpy(Copy, Filename, Length + 1);
     __llvm_profile_recursive_mkdir(Copy);

Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.c?rev=276027&r1=276026&r2=276027&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingUtil.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.c Tue Jul 19 15:48:00 2016
@@ -184,3 +184,26 @@ lprofApplyPathPrefix(char *Dest, const c
 
   memcpy(Dest + PrefixLen, StrippedPathStr, strlen(StrippedPathStr) + 1);
 }
+
+COMPILER_RT_VISIBILITY const char *
+lprofFindFirstDirSeparator(const char *Path) {
+  const char *Sep;
+  Sep = strchr(Path, DIR_SEPARATOR);
+  if (Sep)
+    return Sep;
+#if defined(DIR_SEPARATOR_2)
+  Sep = strchr(Path, DIR_SEPARATOR_2);
+#endif
+  return Sep;
+}
+
+COMPILER_RT_VISIBILITY const char *lprofFindLastDirSeparator(const char *Path) {
+  const char *Sep;
+  Sep = strrchr(Path, DIR_SEPARATOR);
+  if (Sep)
+    return Sep;
+#if defined(DIR_SEPARATOR_2)
+  Sep = strrchr(Path, DIR_SEPARATOR_2);
+#endif
+  return Sep;
+}

Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.h?rev=276027&r1=276026&r2=276027&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingUtil.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.h Tue Jul 19 15:48:00 2016
@@ -39,6 +39,13 @@ const char *lprofGetPathPrefix(int *Pref
 void lprofApplyPathPrefix(char *Dest, const char *PathStr, const char *Prefix,
                           size_t PrefixLen, int PrefixStrip);
 
+/* Returns a pointer to the first occurrence of \c DIR_SEPARATOR char in
+ * the string \c Path, or NULL if the char is not found. */
+const char *lprofFindFirstDirSeparator(const char *Path);
+/* Returns a pointer to the last occurrence of \c DIR_SEPARATOR char in
+ * the string \c Path, or NULL if the char is not found. */
+const char *lprofFindLastDirSeparator(const char *Path);
+
 int lprofGetHostName(char *Name, int Len);
 
 unsigned lprofBoolCmpXchg(void **Ptr, void *OldV, void *NewV);




More information about the llvm-commits mailing list