diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-25 14:51:40 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-25 14:51:40 -0500 |
commit | c7ae64ef122b5c65137509a05692bc8d357a04f8 (patch) | |
tree | 19e2ff24bd9943e70783cc0bf30c6f5106e9ab95 /twin/client.cpp | |
parent | eeabba1c7801d248989c5e6bfc69fa86224809c2 (diff) | |
download | tdebase-c7ae64ef122b5c65137509a05692bc8d357a04f8.tar.gz tdebase-c7ae64ef122b5c65137509a05692bc8d357a04f8.zip |
Use TQFile object to read PID instead of standard C++ file functions
Diffstat (limited to 'twin/client.cpp')
-rw-r--r-- | twin/client.cpp | 65 |
1 files 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 <tqpainter.h> #include <tqdatetime.h> #include <tqimage.h> +#include <tqfile.h> #include <kprocess.h> #include <unistd.h> #include <kstandarddirs.h> @@ -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; + } } } |