OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_OPENBSD) |
7 | 7 |
8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
9 | 9 |
10 #include <dirent.h> // NOLINT | 10 #include <dirent.h> // NOLINT |
11 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
12 #include <string.h> // NOLINT | 12 #include <string.h> // NOLINT |
13 #include <sys/param.h> // NOLINT | 13 #include <sys/param.h> // NOLINT |
14 #include <sys/stat.h> // NOLINT | 14 #include <sys/stat.h> // NOLINT |
15 #include <unistd.h> // NOLINT | 15 #include <unistd.h> // NOLINT |
16 | 16 |
17 #include "bin/file.h" | 17 #include "bin/file.h" |
18 #include "bin/platform.h" | 18 #include "bin/platform.h" |
19 | 19 |
20 #include "platform/signal_blocker.h" | 20 #include "platform/signal_blocker.h" |
21 | 21 |
22 | 22 |
23 namespace dart { | 23 namespace dart { |
24 namespace bin { | 24 namespace bin { |
25 | 25 |
26 | 26 |
27 PathBuffer::PathBuffer() : length_(0) { | 27 PathBuffer::PathBuffer() : length_(0) { |
28 data_ = calloc(PATH_MAX + 1, sizeof(char)); // NOLINT | 28 data_ = calloc(PATH_MAX + 1, sizeof(char)); // NOLINT |
29 } | 29 } |
30 | 30 |
| 31 |
31 bool PathBuffer::AddW(const wchar_t* name) { | 32 bool PathBuffer::AddW(const wchar_t* name) { |
32 UNREACHABLE(); | 33 UNREACHABLE(); |
33 return false; | 34 return false; |
34 } | 35 } |
35 | 36 |
| 37 |
36 char* PathBuffer::AsString() const { | 38 char* PathBuffer::AsString() const { |
37 return reinterpret_cast<char*>(data_); | 39 return reinterpret_cast<char*>(data_); |
38 } | 40 } |
39 | 41 |
| 42 |
40 wchar_t* PathBuffer::AsStringW() const { | 43 wchar_t* PathBuffer::AsStringW() const { |
41 UNREACHABLE(); | 44 UNREACHABLE(); |
42 return NULL; | 45 return NULL; |
43 } | 46 } |
44 | 47 |
| 48 |
45 bool PathBuffer::Add(const char* name) { | 49 bool PathBuffer::Add(const char* name) { |
46 char* data = AsString(); | 50 char* data = AsString(); |
47 int written = snprintf(data + length_, | 51 int written = snprintf(data + length_, |
48 PATH_MAX - length_, | 52 PATH_MAX - length_, |
49 "%s", | 53 "%s", |
50 name); | 54 name); |
51 data[PATH_MAX] = '\0'; | 55 data[PATH_MAX] = '\0'; |
52 if (written <= PATH_MAX - length_ && | 56 if (written <= PATH_MAX - length_ && |
53 written >= 0 && | 57 written >= 0 && |
54 static_cast<size_t>(written) == strlen(name)) { | 58 static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1)) { |
55 length_ += written; | 59 length_ += written; |
56 return true; | 60 return true; |
57 } else { | 61 } else { |
58 errno = ENAMETOOLONG; | 62 errno = ENAMETOOLONG; |
59 return false; | 63 return false; |
60 } | 64 } |
61 } | 65 } |
62 | 66 |
| 67 |
63 void PathBuffer::Reset(int new_length) { | 68 void PathBuffer::Reset(int new_length) { |
64 length_ = new_length; | 69 length_ = new_length; |
65 AsString()[length_] = '\0'; | 70 AsString()[length_] = '\0'; |
66 } | 71 } |
67 | 72 |
68 | 73 |
69 // A linked list of symbolic links, with their unique file system identifiers. | 74 // A linked list of symbolic links, with their unique file system identifiers. |
70 // These are scanned to detect loops while doing a recursive directory listing. | 75 // These are scanned to detect loops while doing a recursive directory listing. |
71 struct LinkList { | 76 struct LinkList { |
72 dev_t dev; | 77 dev_t dev; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 | 429 |
425 bool Directory::Rename(const char* path, const char* new_path) { | 430 bool Directory::Rename(const char* path, const char* new_path) { |
426 ExistsResult exists = Exists(path); | 431 ExistsResult exists = Exists(path); |
427 if (exists != EXISTS) return false; | 432 if (exists != EXISTS) return false; |
428 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); | 433 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); |
429 } | 434 } |
430 | 435 |
431 } // namespace bin | 436 } // namespace bin |
432 } // namespace dart | 437 } // namespace dart |
433 | 438 |
434 #endif // defined(TARGET_OS_MACOS) | 439 #endif // defined(TARGET_OS_OPENBSD) |
OLD | NEW |