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

Side by Side Diff: base/process_util_mac.mm

Issue 8160: Enable stats_tabe_unittest.cc on OS X. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « base/port.h ('k') | base/stats_table_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2008 The Chromium Authors. 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
6 #include "base/process_util.h"
7
8 #import <Cocoa/Cocoa.h>
9 #include <spawn.h>
10 #include <string>
11 #include <sys/types.h>
12 #include <sys/wait.h>
13
14 namespace process_util {
15
16 bool LaunchApp(const std::vector<std::string>& argv,
17 bool wait, ProcessHandle* process_handle) {
18 bool retval = true;
19
20 char* argv_copy[argv.size() + 1];
21 for (size_t i = 0; i < argv.size(); i++) {
22 argv_copy[i] = new char[argv[i].size() + 1];
Amanda Walker 2008/10/27 18:50:52 You should be able to remove this copy by using ar
23 strcpy(argv_copy[i], argv[i].c_str());
24 }
25 argv_copy[argv.size()] = NULL;
26
27 int pid = 0;
28 int spawn_succeeded = (posix_spawn(&pid,
29 argv_copy[0],
30 NULL,
31 NULL,
32 argv_copy,
33 NULL) == 0);
34
35 bool process_handle_valid = pid > 0;
36 if (!spawn_succeeded || !process_handle_valid) {
37 retval = false;
38 } else {
39 if (wait)
40 waitpid(pid, 0, 0);
41
42 if(process_handle)
43 *process_handle = pid;
44 }
45
46 for (size_t i = 0; i < argv.size(); i++)
47 delete[] argv_copy[i];
48
49 return retval;
50 }
51
52 bool LaunchApp(const CommandLine& cl,
53 bool wait, bool start_hidden, ProcessHandle* process_handle) {
54 // TODO(playmobil): Do we need to respect the start_hidden flag?
55 return LaunchApp(cl.argv(), wait, process_handle);
56 }
57
58 bool WaitForSingleProcess(ProcessHandle handle, int wait_milliseconds) {
59 // TODO(playmobil): Do we need to support wait_milliseconds?
60 int status;
61 waitpid(handle, &status, 0);
62 return WIFEXITED(status);
63 }
64
65 } // namespace process_util
OLDNEW
« no previous file with comments | « base/port.h ('k') | base/stats_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698