| /* A part of the Native C Library for Windows NT |
| Copyright 2007-2015 PC GO Ld. |
| |
| This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| */ |
| |
| #include <process.h> |
| #include <windows.h> |
| #include <nt.h> |
| #include <errno.h> |
| |
| struct child { |
| //int vaild; |
| pid_t pid; |
| void *handle; |
| }; |
| |
| static struct child child_table[64]; |
| |
| int __child_process_table_add(pid_t pid, void *handle) { |
| int i = 0; |
| while(child_table[i].pid > 0) { |
| if(++i == 64) { |
| errno = EAGAIN; |
| return -1; |
| } |
| } |
| //child_table[i].vaild = 1; |
| child_table[i].pid = pid; |
| child_table[i].handle = handle; |
| return 0; |
| } |
| |
| int __child_process_table_search_handle(pid_t pid, void **handle) { |
| int i; |
| for(i=0; i<64; i++) { |
| if(child_table[i].pid == pid) { |
| *handle = child_table[i].handle; |
| return i; |
| } |
| } |
| return -1; |
| } |
| |
| // Caller should close the handle later |
| int __child_process_table_search_handle_and_clean(pid_t pid, void **handle) { |
| int i = __child_process_table_search_handle(pid, handle); |
| if(i < 0) return -1; |
| child_table[i].pid = -1; |
| child_table[i].handle = (void *)-1; |
| return i; |
| } |