Home | History | Annotate | Download | only in src
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CRAZY_LINKER_SEARCH_PATH_LIST_H
      6 #define CRAZY_LINKER_SEARCH_PATH_LIST_H
      7 
      8 #include <string.h>
      9 
     10 #include "crazy_linker_util.h"  // for String
     11 
     12 namespace crazy {
     13 
     14 // A simple class to model a list of search paths, and perform
     15 // file system probing with it.
     16 class SearchPathList {
     17  public:
     18   SearchPathList() : list_(), env_list_(), full_path_() {}
     19 
     20   // Reset the list, i.e. make it empty.
     21   void Reset();
     22 
     23   // Reset the list from an environment variable value.
     24   void ResetFromEnv(const char* var_name);
     25 
     26   // Add one or more paths to the list.
     27   // |path_list| contains a list of paths separated by columns.
     28   // |path_list_end| points after the list's last character.
     29   void AddPaths(const char* path_list, const char* path_list_end);
     30 
     31   // Convenience function that takes a 0-terminated string.
     32   void AddPaths(const char* path_list) {
     33     AddPaths(path_list, path_list + ::strlen(path_list));
     34   }
     35 
     36   // Try to find a file named |file_name| by probing the file system
     37   // with every item in the list as a suffix. On success, returns the
     38   // full path string, or NULL on failure.
     39   const char* FindFile(const char* file_name);
     40 
     41  private:
     42   String list_;
     43   String env_list_;
     44   String full_path_;
     45 };
     46 
     47 }  // namespace crazy
     48 
     49 #endif  // CRAZY_LINKER_SEARCH_PATH_LIST_H