xref: /aosp_15_r20/system/libbase/process.cpp (revision 8f0ba417480079999ba552f1087ae592091b9d02)
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "android-base/process.h"
18 
19 #include <stdlib.h>
20 
21 namespace android {
22 namespace base {
23 
Increment()24 void AllPids::PidIterator::Increment() {
25   if (!dir_) {
26     return;
27   }
28 
29   dirent* de;
30   while ((de = readdir(dir_.get())) != nullptr) {
31     pid_t pid = atoi(de->d_name);
32     if (pid != 0) {
33       pid_ = pid;
34       return;
35     }
36   }
37   pid_ = -1;
38 }
39 
40 }  // namespace base
41 }  // namespace android
42