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

Side by Side Diff: base/linux_util.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/json/json_writer_unittest.cc ('k') | base/mac/dispatch_source_mach_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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/linux_util.h" 5 #include "base/linux_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <limits.h> 10 #include <limits.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <sys/stat.h> 12 #include <sys/stat.h>
13 #include <sys/types.h> 13 #include <sys/types.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 15
16 #include <memory>
16 #include <vector> 17 #include <vector>
17 18
18 #include "base/command_line.h" 19 #include "base/command_line.h"
19 #include "base/files/file_util.h" 20 #include "base/files/file_util.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/memory/singleton.h" 21 #include "base/memory/singleton.h"
22 #include "base/process/launch.h" 22 #include "base/process/launch.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/synchronization/lock.h" 24 #include "base/synchronization/lock.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 26
27 namespace { 27 namespace {
28 28
29 // Not needed for OS_CHROMEOS. 29 // Not needed for OS_CHROMEOS.
30 #if defined(OS_LINUX) 30 #if defined(OS_LINUX)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 struct dirent* dent; 148 struct dirent* dent;
149 while ((dent = readdir(task))) { 149 while ((dent = readdir(task))) {
150 char* endptr; 150 char* endptr;
151 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); 151 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10);
152 if (tid_ul == ULONG_MAX || *endptr) 152 if (tid_ul == ULONG_MAX || *endptr)
153 continue; 153 continue;
154 tids.push_back(tid_ul); 154 tids.push_back(tid_ul);
155 } 155 }
156 closedir(task); 156 closedir(task);
157 157
158 scoped_ptr<char[]> syscall_data(new char[expected_data.length()]); 158 std::unique_ptr<char[]> syscall_data(new char[expected_data.length()]);
159 for (std::vector<pid_t>::const_iterator 159 for (std::vector<pid_t>::const_iterator
160 i = tids.begin(); i != tids.end(); ++i) { 160 i = tids.begin(); i != tids.end(); ++i) {
161 const pid_t current_tid = *i; 161 const pid_t current_tid = *i;
162 snprintf(buf, sizeof(buf), "/proc/%d/task/%d/syscall", pid, current_tid); 162 snprintf(buf, sizeof(buf), "/proc/%d/task/%d/syscall", pid, current_tid);
163 int fd = open(buf, O_RDONLY); 163 int fd = open(buf, O_RDONLY);
164 if (fd < 0) 164 if (fd < 0)
165 continue; 165 continue;
166 if (syscall_supported != NULL) 166 if (syscall_supported != NULL)
167 *syscall_supported = true; 167 *syscall_supported = true;
168 bool read_ret = ReadFromFD(fd, syscall_data.get(), expected_data.length()); 168 bool read_ret = ReadFromFD(fd, syscall_data.get(), expected_data.length());
169 close(fd); 169 close(fd);
170 if (!read_ret) 170 if (!read_ret)
171 continue; 171 continue;
172 172
173 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), 173 if (0 == strncmp(expected_data.c_str(), syscall_data.get(),
174 expected_data.length())) { 174 expected_data.length())) {
175 return current_tid; 175 return current_tid;
176 } 176 }
177 } 177 }
178 return -1; 178 return -1;
179 } 179 }
180 180
181 } // namespace base 181 } // namespace base
OLDNEW
« no previous file with comments | « base/json/json_writer_unittest.cc ('k') | base/mac/dispatch_source_mach_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698