[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdecore
From:       Shaheed Haque <srhaque () iee ! org>
Date:       2005-07-20 22:26:02
Message-ID: 1121898362.508146.462.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 437093 by shaheed:

As per dfaure's suggestion, get rid of some of the shell+tempfile stuff. Tested
using a simulated Solaris environemnt: real tests welcome.


 M  +34 -18    ktimezones.cpp  


--- trunk/KDE/kdelibs/kdecore/ktimezones.cpp #437092:437093
@@ -532,35 +532,51 @@
         return local;
 
     // BSD support.
+    QString fileZone;
     f.setName("/etc/timezone");
     if (!f.open(IO_ReadOnly))
     {
         kdDebug() << "Can't open " << f.name() << endl;
 
-        // Solaris support.
-        //
-        // /bin/fgrep 'TZ=' /etc/default/init | /bin/head -n 1 | /bin/cut -b 4-
-        //
-        KTempFile temp;
-        KShellProcess reader;
-        reader << "/bin/grep" << "^TZ=" << "/etc/default/init" << temp.name() << "|" <<
-            "/bin/head" << "-n" << "1" << "|" <<
-            "/bin/cut" << "-b" << "4-";
-        // Note the use of blocking here...it is a trivial amount of data!
-        temp.close();
-        reader.start(KProcess::Block);
-        f.setName(temp.name());
-        if (!temp.status() || !f.open(IO_ReadOnly))
+        // Solaris support using /etc/default/init.
+        f.setName("/etc/default/init");
+        if (!f.open(IO_ReadOnly))
         {
             kdDebug() << "Can't open " << f.name() << endl;
         }
+        else
+        {
+            QTextStream ts(&f);
+            ts.setEncoding(QTextStream::Latin1);
+
+            // Read the last line starting "TZ=".
+            while (!ts.atEnd())
+            {
+                fileZone = ts.readLine();
+                if (fileZone.startsWith("TZ="))
+                {
+                    fileZone = fileZone.mid(3);
+
+                    // kdError() << "local=" << fileZone << endl;
+                    local = zone(fileZone);
+                }
+            }
+            f.close();
+        }
     }
-    if (f.isOpen())
+    else
     {
-        QString fileZone;
         QTextStream ts(&f);
-        ts >> fileZone;
-        local = zone(fileZone);
+        ts.setEncoding(QTextStream::Latin1);
+
+        // Read the first line.
+        if (!ts.atEnd())
+        {
+            fileZone = ts.readLine();
+
+            // kdError() << "local=" << fileZone << endl;
+            local = zone(fileZone);
+        }
         f.close();
     }
     if (local)
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic