d8c93b09a75684f395167134d2970181e588bccf
[platform/framework/web/crosswalk-tizen.git] / src / common / file_utils.cc
1 // Copyright 2015 Samsung Electronics Co, Ltd. 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 #include "common/file_utils.h"
6
7 #include <unistd.h>
8 #include <libgen.h>
9 #include <string>
10
11 namespace wrt {
12 namespace utils {
13
14 bool Exists(const std::string& path) {
15   return (access(path.c_str(), F_OK) != -1);
16 }
17
18 std::string BaseName(const std::string& path) {
19   char* p = basename(const_cast<char*>(path.c_str()));
20   return std::string(p);
21 }
22
23 std::string DirName(const std::string& path) {
24   char* p = dirname(const_cast<char*>(path.c_str()));
25   return std::string(p);
26 }
27
28 std::string SchemeName(const std::string& uri) {
29   size_t pos = uri.find(":");
30   if (pos != std::string::npos && pos < uri.length()) {
31     return std::string(uri.substr(0, pos));
32   } else {
33     return std::string();
34   }
35 }
36
37 }  // namespace utils
38 }  // namespace wrt