Provide helper wrappers for basename(3) and dirname(3)

This hides the need to provide mutable C strings, and unifies
existing basename calls and variations in a single location.

Change-Id: Idfb449c47b1421f1a751efc3d7404f15f8b369ca
Reviewed-on: https://chromium-review.googlesource.com/725731
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Tobias Sargeant 2017-10-18 16:39:09 +01:00 committed by Tobias Sargeant
parent 9b23ca3a7c
commit 072f86ca83
10 changed files with 220 additions and 31 deletions

View file

@ -66,6 +66,7 @@
#include "common/linux/file_id.h"
#include "common/memory_allocator.h"
#include "common/module.h"
#include "common/path_helper.h"
#include "common/scoped_ptr.h"
#ifndef NO_STABS_SUPPORT
#include "common/stabs_reader.h"
@ -877,16 +878,6 @@ const char* ElfArchitecture(const typename ElfClass::Ehdr* elf_header) {
}
}
// Return the non-directory portion of FILENAME: the portion after the
// last slash, or the whole filename if there are no slashes.
string BaseFileName(const string &filename) {
// Lots of copies! basename's behavior is less than ideal.
char* c_filename = strdup(filename.c_str());
string base = basename(c_filename);
free(c_filename);
return base;
}
template<typename ElfClass>
bool SanitizeDebugFile(const typename ElfClass::Ehdr* debug_elf_header,
const string& debuglink_file,
@ -937,7 +928,7 @@ bool InitModuleForElfClass(const typename ElfClass::Ehdr* elf_header,
return false;
}
string name = BaseFileName(obj_filename);
string name = google_breakpad::BaseName(obj_filename);
string os = "Linux";
// Add an extra "0" at the end. PDB files on Windows have an 'age'
// number appended to the end of the file identifier; this isn't