From c7ae64ef122b5c65137509a05692bc8d357a04f8 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Wed, 25 Jul 2012 14:51:40 -0500 Subject: Use TQFile object to read PID instead of standard C++ file functions --- twin/client.cpp | 65 ++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/twin/client.cpp b/twin/client.cpp index 749942643..35b588db5 100644 --- a/twin/client.cpp +++ b/twin/client.cpp @@ -17,6 +17,7 @@ License. See the file "COPYING" for the exact licensing terms. #include #include #include +#include #include #include #include @@ -1855,26 +1856,17 @@ bool Client::isSuspendable() const } else { - FILE *procfile; - if(chdir(TQString("/proc/%1").arg(pid).ascii()) == 0) + TQFile procStatFile(TQString("/proc/%1/stat").arg(pid)); + if (procStatFile.open(IO_ReadOnly)) { - procfile = fopen("stat", "r"); - } - if(!procfile) - { - return false; - } - else - { - long long int procpid; - char tcomm[PATH_MAX]; - char state; - fscanf(procfile, "%lld ", &procpid); - fscanf(procfile, "%s ", tcomm); - fscanf(procfile, "%c ", &state); - if( state != 'T' ) + TQByteArray statRaw = procStatFile.readAll(); + procStatFile.close(); + TQString statString(statRaw); + TQStringList statFields = TQStringList::split(" ", statString, TRUE); + TQString tcomm = statFields[1]; + TQString state = statFields[2]; + if( state != "T" ) { - fclose(procfile); // Make sure no windows of this process are special for ( ClientList::ConstIterator it = workspace()->clients.begin(); it != workspace()->clients.end(); ++it) { @@ -1902,10 +1894,13 @@ bool Client::isSuspendable() const } else { - fclose(procfile); return false; } } + else + { + return false; + } } } @@ -1922,34 +1917,28 @@ bool Client::isResumeable() const } else { - FILE *procfile; - if(chdir(TQString("/proc/%1").arg(pid).ascii()) == 0) + TQFile procStatFile(TQString("/proc/%1/stat").arg(pid)); + if (procStatFile.open(IO_ReadOnly)) { - procfile = fopen("stat", "r"); - } - if(!procfile) - { - return false; - } - else - { - long long int procpid; - char tcomm[PATH_MAX]; - char state; - fscanf(procfile, "%lld ", &procpid); - fscanf(procfile, "%s ", tcomm); - fscanf(procfile, "%c ", &state); - if( state == 'T' ) + TQByteArray statRaw = procStatFile.readAll(); + procStatFile.close(); + TQString statString(statRaw); + TQStringList statFields = TQStringList::split(" ", statString, TRUE); + TQString tcomm = statFields[1]; + TQString state = statFields[2]; + if( state == "T" ) { - fclose(procfile); return true; } else { - fclose(procfile); return false; } } + else + { + return false; + } } } -- cgit v1.2.1