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

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: 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 ASSERT(errno == ELOOP || 336 ASSERT(errno == ELOOP ||
337 errno == ENAMETOOLONG || 337 errno == ENAMETOOLONG ||
338 errno == ENOENT || 338 errno == ENOENT ||
339 errno == ENOTDIR); 339 errno == ENOTDIR);
340 return DOES_NOT_EXIST; 340 return DOES_NOT_EXIST;
341 } 341 }
342 } 342 }
343 343
344 344
345 char* Directory::Current() { 345 char* Directory::Current() {
346 return getcwd(NULL, 0); 346 // Android's getcwd adheres closely to the POSIX standard. It won't
ricow1 2016/01/05 07:12:13 Android's?
mulander 2016/01/05 16:13:48 You are correct. getcwd(3) on OpenBSD does allocat
mulander 2016/01/05 16:13:48 Acknowledged.
mulander 2016/01/05 16:13:48 Done.
347 // allocate memory. We need to make our own copy.
348
349 char buffer[PATH_MAX];
350 if (NULL == getcwd(buffer, PATH_MAX)) {
351 return NULL;
352 }
353
354 return strdup(buffer);
347 } 355 }
348 356
349 357
350 bool Directory::SetCurrent(const char* path) { 358 bool Directory::SetCurrent(const char* path) {
351 int result = NO_RETRY_EXPECTED(chdir(path)); 359 int result = NO_RETRY_EXPECTED(chdir(path));
352 return result == 0; 360 return result == 0;
353 } 361 }
354 362
355 363
356 bool Directory::Create(const char* dir_name) { 364 bool Directory::Create(const char* dir_name) {
357 // Create the directory with the permissions specified by the 365 // Create the directory with the permissions specified by the
358 // process umask. 366 // process umask.
359 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777)); 367 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777));
360 // If the directory already exists, treat it as a success. 368 // If the directory already exists, treat it as a success.
361 if (result == -1 && errno == EEXIST) { 369 if (result == -1 && errno == EEXIST) {
362 return (Exists(dir_name) == EXISTS); 370 return (Exists(dir_name) == EXISTS);
363 } 371 }
364 return (result == 0); 372 return (result == 0);
365 } 373 }
366 374
367
368 char* Directory::SystemTemp() { 375 char* Directory::SystemTemp() {
369 const char* temp_dir = getenv("TMPDIR"); 376 const char* temp_dir = getenv("TMPDIR");
370 if (temp_dir == NULL) { 377 if (temp_dir == NULL) {
371 temp_dir = getenv("TMP"); 378 temp_dir = getenv("TMP");
372 } 379 }
373 if (temp_dir == NULL) { 380 if (temp_dir == NULL) {
374 temp_dir = "/tmp"; 381 temp_dir = "/tmp";
375 } 382 }
376 char* result = strdup(temp_dir); 383 char* result = strdup(temp_dir);
377 // Remove any trailing slash. 384 // Remove any trailing slash.
378 int length = strlen(result); 385 int length = strlen(result);
379 if (length > 1 && result[length - 1] == '/') { 386 if (length > 1 && result[length - 1] == '/') {
380 result[length - 1] = '\0'; 387 result[length - 1] = '\0';
381 } 388 }
382 return result; 389 return result;
383 } 390 }
384 391
385
386 char* Directory::CreateTemp(const char* prefix) { 392 char* Directory::CreateTemp(const char* prefix) {
387 // Returns a new, unused directory name, adding characters to the end 393 // Returns a new, unused directory name, adding characters to the end
388 // of prefix. Creates the directory with the permissions specified 394 // of prefix. Creates the directory with the permissions specified
389 // by the process umask. 395 // by the process umask.
390 // The return value must be freed by the caller. 396 // The return value must be freed by the caller.
391 PathBuffer path; 397 PathBuffer path;
392 path.Add(prefix); 398 path.Add(prefix);
393 if (!path.Add("XXXXXX")) { 399 if (!path.Add("XXXXXX")) {
394 // Pattern has overflowed. 400 // Pattern has overflowed.
395 return NULL; 401 return NULL;
(...skipping 28 matching lines...) Expand all
424 430
425 bool Directory::Rename(const char* path, const char* new_path) { 431 bool Directory::Rename(const char* path, const char* new_path) {
426 ExistsResult exists = Exists(path); 432 ExistsResult exists = Exists(path);
427 if (exists != EXISTS) return false; 433 if (exists != EXISTS) return false;
428 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); 434 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0);
429 } 435 }
430 436
431 } // namespace bin 437 } // namespace bin
432 } // namespace dart 438 } // namespace dart
433 439
434 #endif // defined(TARGET_OS_MACOS) 440 #endif // defined(TARGET_OS_OPENBSD)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698