int readf() { // Read the next cluster of a file uint32_t nextsect; if (endoffile()) return -1; filesectorcount++; if (++curfilesectorcluster == fat.BPB_SecPerClus) { if ((nextsect = getnextsect(curfilesect))==0) return -1; curfilesect=nextsect; curfilesectorcluster=0; } if (sdmmc_sdcard_readsectors(curfilesect+curfilesectorcluster,1,(void*)&filesect)) return -1; else return 0; }
// wait for end of process // if kill is true, kill if not already ended int ProcessBuf::close(bool kill) { #ifdef WIN32 if (processInformation.hProcess == 0) return -1; LOG(DBG,"ProcessBuf::close for process " << processInformation.hProcess << "(" << kill << ")"); if (processInformation.hProcess != 0) { if (kill) { TerminateProcess(processInformation.hProcess, 1); } else { WaitForSingleObject(processInformation.hProcess, INFINITE); } // send EOF to stdin of child process CloseHandle(processInformation.hProcess); processInformation.hProcess = 0; if (processInformation.hThread != 0) { CloseHandle(processInformation.hThread); processInformation.hThread = 0; } } if (g_hChildStd_IN_Rd != 0) { CloseHandle(g_hChildStd_IN_Rd); g_hChildStd_IN_Rd = 0; } if (g_hChildStd_OUT_Wr != 0) { CloseHandle(g_hChildStd_OUT_Wr); g_hChildStd_OUT_Wr = 0; } return 0; #elif defined(POSIX) if( process == -1 ) return -1; LOG(DBG,"ProcessBuf::close for process " << process << "(" << kill << ")"); // we're done writing endoffile(); // reset input buffer setg(ibuf, ibuf, ibuf); // we're done reading if (outpipes[0] != -1) { ::close(outpipes[0]); outpipes[0] = -1; } // try to waitpid without waiting (just see if the process is still there) if( ::waitpid(process, &status, WNOHANG) == 0 ) { int sig = SIGTERM; LOG(INFO,"sending signal " << sig << " to process " << process); ::kill(process, sig); } // obviously we do not want to leave zombies around, so get status // code of the process // (if the process no longer exists, this will simply fail, // if a new process grabbed the same pid, we are doomed and will wait for that // unrelated process to exit) ::waitpid(process, &status, 0); int exitstatus = WEXITSTATUS(status); LOG(DBG,"ProcessBuf::close for process " << process << ": exit status " << exitstatus); process = -1; // exit code of process return exitstatus; #else #error Either POSIX or WIN32 must be defined #endif }