Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (C) 2013, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef LATINIME_FILE_UTILS_H
     18 #define LATINIME_FILE_UTILS_H
     19 
     20 #include "defines.h"
     21 
     22 namespace latinime {
     23 
     24 class FileUtils {
     25  public:
     26     // Returns -1 on error.
     27     static int getFileSize(const char *const filePath);
     28 
     29     static bool existsDir(const char *const dirPath);
     30 
     31     // Remove a directory and all files in the directory.
     32     static bool removeDirAndFiles(const char *const dirPath);
     33 
     34     static int getFilePathWithSuffixBufSize(const char *const filePath, const char *const suffix);
     35 
     36     static void getFilePathWithSuffix(const char *const filePath, const char *const suffix,
     37             const int filePathBufSize, char *const outFilePath);
     38 
     39     static int getFilePathBufSize(const char *const dirPath, const char *const fileName);
     40 
     41     static void getFilePath(const char *const dirPath, const char *const fileName,
     42             const int filePathBufSize, char *const outFilePath);
     43 
     44     // Returns whether the filePath have the suffix.
     45     static bool getFilePathWithoutSuffix(const char *const filePath, const char *const suffix,
     46             const int dirPathBufSize, char *const outDirPath);
     47 
     48     static void getDirPath(const char *const filePath, const int dirPathBufSize,
     49             char *const outDirPath);
     50 
     51     static void getBasename(const char *const filePath, const int outNameBufSize,
     52             char *const outName);
     53 
     54  private:
     55     DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtils);
     56 
     57     static bool removeDirAndFiles(const char *const dirPath, const int maxTries);
     58 };
     59 } // namespace latinime
     60 #endif /* LATINIME_FILE_UTILS_H */
     61