| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkTypes.h" |
| 9 |
| 8 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_
FOR_ANDROID) | 10 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_
FOR_ANDROID) |
| 9 # include <unistd.h> | 11 # include <unistd.h> |
| 10 # include <sys/time.h> | 12 # include <sys/time.h> |
| 11 # include <dirent.h> | 13 # include <dirent.h> |
| 12 #endif | 14 #endif |
| 13 | 15 |
| 14 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) | 16 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) |
| 15 # include <glob.h> | 17 # include <glob.h> |
| 16 #endif | 18 #endif |
| 17 | 19 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 LARGE_INTEGER frequency; | 92 LARGE_INTEGER frequency; |
| 91 QueryPerformanceCounter(¤tTime); | 93 QueryPerformanceCounter(¤tTime); |
| 92 QueryPerformanceFrequency(&frequency); | 94 QueryPerformanceFrequency(&frequency); |
| 93 return (double)currentTime.QuadPart / (double)frequency.QuadPart; | 95 return (double)currentTime.QuadPart / (double)frequency.QuadPart; |
| 94 #elif _POSIX_TIMERS > 0 && defined(CLOCK_REALTIME) | 96 #elif _POSIX_TIMERS > 0 && defined(CLOCK_REALTIME) |
| 95 struct timespec currentTime; | 97 struct timespec currentTime; |
| 96 clock_gettime(CLOCK_REALTIME, ¤tTime); | 98 clock_gettime(CLOCK_REALTIME, ¤tTime); |
| 97 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; | 99 return currentTime.tv_sec + (double)currentTime.tv_nsec / 1e9; |
| 98 #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUIL
D_FOR_ANDROID) | 100 #elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUIL
D_FOR_ANDROID) |
| 99 struct timeval currentTime; | 101 struct timeval currentTime; |
| 100 gettimeofday(¤tTime, NULL); | 102 gettimeofday(¤tTime, nullptr); |
| 101 return currentTime.tv_sec + (double)currentTime.tv_usec / 1e6; | 103 return currentTime.tv_sec + (double)currentTime.tv_usec / 1e6; |
| 102 #else | 104 #else |
| 103 return clock() / (double)CLOCKS_PER_SEC; | 105 return clock() / (double)CLOCKS_PER_SEC; |
| 104 #endif | 106 #endif |
| 105 } | 107 } |
| 106 | 108 |
| 107 bool get_directory(const char path[], SkTArray<SkString>* entries) { | 109 bool get_directory(const char path[], SkTArray<SkString>* entries) { |
| 108 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_
FOR_ANDROID) | 110 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_
FOR_ANDROID) |
| 109 // Open the directory and check for success | 111 // Open the directory and check for success |
| 110 DIR* dir = opendir(path); | 112 DIR* dir = opendir(path); |
| 111 if (NULL == dir) { | 113 if (nullptr == dir) { |
| 112 return false; | 114 return false; |
| 113 } | 115 } |
| 114 | 116 |
| 115 // Loop through dir entries until there are none left (i.e. readdir returns
NULL) | 117 // Loop through dir entries until there are none left (i.e. readdir returns
nullptr) |
| 116 struct dirent* entry; | 118 struct dirent* entry; |
| 117 while ((entry = readdir(dir))) { | 119 while ((entry = readdir(dir))) { |
| 118 // dirent only gives relative paths, we need to join them to the base pa
th to check if they | 120 // dirent only gives relative paths, we need to join them to the base pa
th to check if they |
| 119 // are directories. | 121 // are directories. |
| 120 SkString joinedPath = SkOSPath::Join(path, entry->d_name); | 122 SkString joinedPath = SkOSPath::Join(path, entry->d_name); |
| 121 | 123 |
| 122 // We only care about files | 124 // We only care about files |
| 123 if (!sk_isdir(joinedPath.c_str())) { | 125 if (!sk_isdir(joinedPath.c_str())) { |
| 124 entries->push_back(SkString(entry->d_name)); | 126 entries->push_back(SkString(entry->d_name)); |
| 125 } | 127 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return true; | 162 return true; |
| 161 #else | 163 #else |
| 162 return false; | 164 return false; |
| 163 #endif | 165 #endif |
| 164 } | 166 } |
| 165 | 167 |
| 166 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { | 168 bool glob_files(const char globPattern[], SkTArray<SkString>* entries) { |
| 167 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) | 169 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) |
| 168 // TODO Make sure this works on windows. This may require use of FindNextFil
e windows function. | 170 // TODO Make sure this works on windows. This may require use of FindNextFil
e windows function. |
| 169 glob_t globBuffer; | 171 glob_t globBuffer; |
| 170 if (glob(globPattern, 0, NULL, &globBuffer) != 0) { | 172 if (glob(globPattern, 0, nullptr, &globBuffer) != 0) { |
| 171 return false; | 173 return false; |
| 172 } | 174 } |
| 173 | 175 |
| 174 // Note these paths are in sorted order by default according to http://linux
.die.net/man/3/glob | 176 // Note these paths are in sorted order by default according to http://linux
.die.net/man/3/glob |
| 175 // Check under the flag GLOB_NOSORT | 177 // Check under the flag GLOB_NOSORT |
| 176 char** paths = globBuffer.gl_pathv; | 178 char** paths = globBuffer.gl_pathv; |
| 177 while(*paths) { | 179 while(*paths) { |
| 178 entries->push_back(SkString(*paths)); | 180 entries->push_back(SkString(*paths)); |
| 179 paths++; | 181 paths++; |
| 180 } | 182 } |
| 181 | 183 |
| 182 globfree(&globBuffer); | 184 globfree(&globBuffer); |
| 183 | 185 |
| 184 return true; | 186 return true; |
| 185 #else | 187 #else |
| 186 return false; | 188 return false; |
| 187 #endif | 189 #endif |
| 188 } | 190 } |
| 189 | 191 |
| 190 SkString get_absolute_path(const SkString& path) { | 192 SkString get_absolute_path(const SkString& path) { |
| 191 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_
FOR_ANDROID) | 193 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_
FOR_ANDROID) |
| 192 SkString fullPath(PATH_MAX + 1); | 194 SkString fullPath(PATH_MAX + 1); |
| 193 if (realpath(path.c_str(), fullPath.writable_str()) == NULL) { | 195 if (realpath(path.c_str(), fullPath.writable_str()) == nullptr) { |
| 194 fullPath.reset(); | 196 fullPath.reset(); |
| 195 } | 197 } |
| 196 return fullPath; | 198 return fullPath; |
| 197 #elif defined(SK_BUILD_FOR_WIN32) | 199 #elif defined(SK_BUILD_FOR_WIN32) |
| 198 SkString fullPath(MAX_PATH); | 200 SkString fullPath(MAX_PATH); |
| 199 if (_fullpath(fullPath.writable_str(), path.c_str(), MAX_PATH) == NULL) { | 201 if (_fullpath(fullPath.writable_str(), path.c_str(), MAX_PATH) == nullptr) { |
| 200 fullPath.reset(); | 202 fullPath.reset(); |
| 201 } | 203 } |
| 202 return fullPath; | 204 return fullPath; |
| 203 #else | 205 #else |
| 204 return SkString(); | 206 return SkString(); |
| 205 #endif | 207 #endif |
| 206 } | 208 } |
| OLD | NEW |