Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: runtime/bin/directory_openbsd.cc

Issue 1559053002: Refs #10260 OpenBSD support #25327 Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Replace // FIXME with // TODO(mulander) Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 27 matching lines...) Expand all
44 44
45 bool PathBuffer::Add(const char* name) { 45 bool PathBuffer::Add(const char* name) {
46 char* data = AsString(); 46 char* data = AsString();
47 int written = snprintf(data + length_, 47 int written = snprintf(data + length_,
48 PATH_MAX - length_, 48 PATH_MAX - length_,
49 "%s", 49 "%s",
50 name); 50 name);
51 data[PATH_MAX] = '\0'; 51 data[PATH_MAX] = '\0';
52 if (written <= PATH_MAX - length_ && 52 if (written <= PATH_MAX - length_ &&
53 written >= 0 && 53 written >= 0 &&
54 static_cast<size_t>(written) == strlen(name)) { 54 static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1)) {
55 length_ += written; 55 length_ += written;
56 return true; 56 return true;
57 } else { 57 } else {
58 errno = ENAMETOOLONG; 58 errno = ENAMETOOLONG;
59 return false; 59 return false;
60 } 60 }
61 } 61 }
62 62
63 void PathBuffer::Reset(int new_length) { 63 void PathBuffer::Reset(int new_length) {
64 length_ = new_length; 64 length_ = new_length;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // Create the directory with the permissions specified by the 357 // Create the directory with the permissions specified by the
358 // process umask. 358 // process umask.
359 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777)); 359 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777));
360 // If the directory already exists, treat it as a success. 360 // If the directory already exists, treat it as a success.
361 if (result == -1 && errno == EEXIST) { 361 if (result == -1 && errno == EEXIST) {
362 return (Exists(dir_name) == EXISTS); 362 return (Exists(dir_name) == EXISTS);
363 } 363 }
364 return (result == 0); 364 return (result == 0);
365 } 365 }
366 366
367
Ivan Posva 2016/01/11 23:58:40 Why? Generally we use two lines between functions.
mulander 2016/01/12 00:22:45 I was not aware of that. Will be fixed.
368 char* Directory::SystemTemp() { 367 char* Directory::SystemTemp() {
369 const char* temp_dir = getenv("TMPDIR"); 368 const char* temp_dir = getenv("TMPDIR");
370 if (temp_dir == NULL) { 369 if (temp_dir == NULL) {
371 temp_dir = getenv("TMP"); 370 temp_dir = getenv("TMP");
372 } 371 }
373 if (temp_dir == NULL) { 372 if (temp_dir == NULL) {
374 temp_dir = "/tmp"; 373 temp_dir = "/tmp";
375 } 374 }
376 char* result = strdup(temp_dir); 375 char* result = strdup(temp_dir);
377 // Remove any trailing slash. 376 // Remove any trailing slash.
378 int length = strlen(result); 377 int length = strlen(result);
379 if (length > 1 && result[length - 1] == '/') { 378 if (length > 1 && result[length - 1] == '/') {
380 result[length - 1] = '\0'; 379 result[length - 1] = '\0';
381 } 380 }
382 return result; 381 return result;
383 } 382 }
384 383
385
Ivan Posva 2016/01/11 23:58:40 ditto
mulander 2016/01/12 00:22:45 Acknowledged.
386 char* Directory::CreateTemp(const char* prefix) { 384 char* Directory::CreateTemp(const char* prefix) {
387 // Returns a new, unused directory name, adding characters to the end 385 // Returns a new, unused directory name, adding characters to the end
388 // of prefix. Creates the directory with the permissions specified 386 // of prefix. Creates the directory with the permissions specified
389 // by the process umask. 387 // by the process umask.
390 // The return value must be freed by the caller. 388 // The return value must be freed by the caller.
391 PathBuffer path; 389 PathBuffer path;
392 path.Add(prefix); 390 path.Add(prefix);
393 if (!path.Add("XXXXXX")) { 391 if (!path.Add("XXXXXX")) {
394 // Pattern has overflowed. 392 // Pattern has overflowed.
395 return NULL; 393 return NULL;
(...skipping 28 matching lines...) Expand all
424 422
425 bool Directory::Rename(const char* path, const char* new_path) { 423 bool Directory::Rename(const char* path, const char* new_path) {
426 ExistsResult exists = Exists(path); 424 ExistsResult exists = Exists(path);
427 if (exists != EXISTS) return false; 425 if (exists != EXISTS) return false;
428 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); 426 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0);
429 } 427 }
430 428
431 } // namespace bin 429 } // namespace bin
432 } // namespace dart 430 } // namespace dart
433 431
434 #endif // defined(TARGET_OS_MACOS) 432 #endif // defined(TARGET_OS_OPENBSD)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698