summaryrefslogtreecommitdiff
path: root/libopie2
authorerik <erik>2007-01-19 01:18:01 (UTC)
committer erik <erik>2007-01-19 01:18:01 (UTC)
commit32343107b30904806d02672955c57ed53d39fe79 (patch) (unidiff)
tree9114a0ea170e3adc807a2445b49360f1bfde9626 /libopie2
parentac0ce844e90a64247c0adb210e0a23021b011d57 (diff)
downloadopie-32343107b30904806d02672955c57ed53d39fe79.zip
opie-32343107b30904806d02672955c57ed53d39fe79.tar.gz
opie-32343107b30904806d02672955c57ed53d39fe79.tar.bz2
Every file in this commit has a change to check the return value of a call.
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/oglobal.cpp2
-rw-r--r--libopie2/opiecore/oprocess.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opiecore/oglobal.cpp b/libopie2/opiecore/oglobal.cpp
index 706ac6c..b7d59fc 100644
--- a/libopie2/opiecore/oglobal.cpp
+++ b/libopie2/opiecore/oglobal.cpp
@@ -251,172 +251,172 @@ QByteArray OGlobal::decodeBase64( const QByteArray& in) {
251 251
252 // Deal with possible *nix "BEGIN" marker!! 252 // Deal with possible *nix "BEGIN" marker!!
253 while ( count < len && (data[count] == '\n' || data[count] == '\r' || 253 while ( count < len && (data[count] == '\n' || data[count] == '\r' ||
254 data[count] == '\t' || data[count] == ' ') ) 254 data[count] == '\t' || data[count] == ' ') )
255 count++; 255 count++;
256 256
257 if ( strncasecmp(data+count, "begin", 5) == 0 ) 257 if ( strncasecmp(data+count, "begin", 5) == 0 )
258 { 258 {
259 count += 5; 259 count += 5;
260 while ( count < len && data[count] != '\n' && data[count] != '\r' ) 260 while ( count < len && data[count] != '\n' && data[count] != '\r' )
261 count++; 261 count++;
262 262
263 while ( count < len && (data[count] == '\n' || data[count] == '\r') ) 263 while ( count < len && (data[count] == '\n' || data[count] == '\r') )
264 count ++; 264 count ++;
265 265
266 data += count; 266 data += count;
267 tail = (len -= count); 267 tail = (len -= count);
268 } 268 }
269 269
270 // Find the tail end of the actual encoded data even if 270 // Find the tail end of the actual encoded data even if
271 // there is/are trailing CR and/or LF. 271 // there is/are trailing CR and/or LF.
272 while ( data[tail-1] == '=' || data[tail-1] == '\n' || 272 while ( data[tail-1] == '=' || data[tail-1] == '\n' ||
273 data[tail-1] == '\r' ) 273 data[tail-1] == '\r' )
274 if ( data[--tail] != '=' ) len = tail; 274 if ( data[--tail] != '=' ) len = tail;
275 275
276 unsigned int outIdx = 0; 276 unsigned int outIdx = 0;
277 out.resize( (count=len) ); 277 out.resize( (count=len) );
278 for (unsigned int idx = 0; idx < count; idx++) 278 for (unsigned int idx = 0; idx < count; idx++)
279 { 279 {
280 // Adhere to RFC 2045 and ignore characters 280 // Adhere to RFC 2045 and ignore characters
281 // that are not part of the encoding table. 281 // that are not part of the encoding table.
282 unsigned char ch = data[idx]; 282 unsigned char ch = data[idx];
283 if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) || 283 if ( (ch > 47 && ch < 58) || (ch > 64 && ch < 91 ) ||
284 (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=') 284 (ch > 96 && ch < 123)|| ch == '+' || ch == '/' || ch == '=')
285 { 285 {
286 out[outIdx++] = Base64DecMap[ch]; 286 out[outIdx++] = Base64DecMap[ch];
287 } 287 }
288 else 288 else
289 { 289 {
290 len--; 290 len--;
291 tail--; 291 tail--;
292 } 292 }
293 } 293 }
294 294
295 // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl; 295 // kdDebug() << "Tail size = " << tail << ", Length size = " << len << endl;
296 296
297 // 4-byte to 3-byte conversion 297 // 4-byte to 3-byte conversion
298 len = (tail>(len/4)) ? tail-(len/4) : 0; 298 len = (tail>(len/4)) ? tail-(len/4) : 0;
299 unsigned int sidx = 0, didx = 0; 299 unsigned int sidx = 0, didx = 0;
300 if ( len > 1 ) 300 if ( len > 1 )
301 { 301 {
302 while (didx < len-2) 302 while (didx < len-2)
303 { 303 {
304 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); 304 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
305 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); 305 out[didx+1] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
306 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077)); 306 out[didx+2] = (((out[sidx+2] << 6) & 255) | (out[sidx+3] & 077));
307 sidx += 4; 307 sidx += 4;
308 didx += 3; 308 didx += 3;
309 } 309 }
310 } 310 }
311 311
312 if (didx < len) 312 if (didx < len)
313 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003)); 313 out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx+1] >> 4) & 003));
314 314
315 if (++didx < len ) 315 if (++didx < len )
316 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017)); 316 out[didx] = (((out[sidx+1] << 4) & 255) | ((out[sidx+2] >> 2) & 017));
317 317
318 // Resize the output buffer 318 // Resize the output buffer
319 if ( len == 0 || len < out.size() ) 319 if ( len == 0 || len < out.size() )
320 out.resize(len); 320 out.resize(len);
321 321
322 return out; 322 return out;
323} 323}
324 324
325bool OGlobal::isAppLnkFileName( const QString& str ) 325bool OGlobal::isAppLnkFileName( const QString& str )
326{ 326{
327 if (str.isEmpty()||str.at(str.length()-1)==QDir::separator()) return false; 327 if (str.isEmpty()||str.at(str.length()-1)==QDir::separator()) return false;
328 return str.startsWith(MimeType::appsFolderName()+QDir::separator()); 328 return str.startsWith(MimeType::appsFolderName()+QDir::separator());
329} 329}
330 330
331/* ToDo: 331/* ToDo:
332 * This fun should check the document-path value for the mounted media 332 * This fun should check the document-path value for the mounted media
333 * which has to be implemented later. this moment we just check for a 333 * which has to be implemented later. this moment we just check for a
334 * mounted media name. 334 * mounted media name.
335 */ 335 */
336bool OGlobal::isDocumentFileName( const QString& file ) 336bool OGlobal::isDocumentFileName( const QString& file )
337{ 337{
338 if (file.isEmpty()||file.at(file.length()-1)==QDir::separator()) return false; 338 if (file.isEmpty()||file.at(file.length()-1)==QDir::separator()) return false;
339 if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true; 339 if (file.startsWith(QPEApplication::documentDir()+QDir::separator())) return true;
340 StorageInfo si; 340 StorageInfo si;
341 QList< FileSystem > fl = si.fileSystems(); 341 QList< FileSystem > fl = si.fileSystems();
342 FileSystem*fs; 342 FileSystem*fs;
343 for (fs = fl.first();fs!=0;fs=fl.next()) { 343 for (fs = fl.first();fs!=0;fs=fl.next()) {
344 if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator())) 344 if (fs->isRemovable()&&file.startsWith(fs->name()+QDir::separator()))
345 return true; 345 return true;
346 } 346 }
347 if (file.startsWith(homeDirPath())+"/Documents/") return true; 347 if (file.startsWith(homeDirPath()+"/Documents/")) return true;
348 return false; 348 return false;
349} 349}
350 350
351QString OGlobal::tempDirPath() 351QString OGlobal::tempDirPath()
352{ 352{
353 static QString defstring="/tmp"; 353 static QString defstring="/tmp";
354 char * tmpp = 0; 354 char * tmpp = 0;
355 if ( (tmpp=getenv("TEMP"))) { 355 if ( (tmpp=getenv("TEMP"))) {
356 return tmpp; 356 return tmpp;
357 } 357 }
358 return defstring; 358 return defstring;
359} 359}
360 360
361QString OGlobal::homeDirPath() 361QString OGlobal::homeDirPath()
362{ 362{
363 char * tmpp = getenv("HOME"); 363 char * tmpp = getenv("HOME");
364 return (tmpp?tmpp:"/"); 364 return (tmpp?tmpp:"/");
365} 365}
366 366
367bool OGlobal::weekStartsOnMonday() 367bool OGlobal::weekStartsOnMonday()
368{ 368{
369 OConfig*conf=OGlobal::qpe_config(); 369 OConfig*conf=OGlobal::qpe_config();
370 if (!conf)return false; 370 if (!conf)return false;
371 conf->setGroup("Time"); 371 conf->setGroup("Time");
372 return conf->readBoolEntry("MONDAY",true); 372 return conf->readBoolEntry("MONDAY",true);
373} 373}
374 374
375void OGlobal::setWeekStartsOnMonday( bool what) 375void OGlobal::setWeekStartsOnMonday( bool what)
376{ 376{
377 OConfig*conf=OGlobal::qpe_config(); 377 OConfig*conf=OGlobal::qpe_config();
378 if (!conf)return; 378 if (!conf)return;
379 conf->setGroup("Time"); 379 conf->setGroup("Time");
380 return conf->writeEntry("MONDAY",what); 380 return conf->writeEntry("MONDAY",what);
381} 381}
382 382
383bool OGlobal::useAMPM() 383bool OGlobal::useAMPM()
384{ 384{
385 OConfig*conf=OGlobal::qpe_config(); 385 OConfig*conf=OGlobal::qpe_config();
386 if (!conf)return false; 386 if (!conf)return false;
387 conf->setGroup("Time"); 387 conf->setGroup("Time");
388 return conf->readBoolEntry("AMPM",false); 388 return conf->readBoolEntry("AMPM",false);
389} 389}
390 390
391void OGlobal::setUseAMPM( bool what) 391void OGlobal::setUseAMPM( bool what)
392{ 392{
393 OConfig*conf=OGlobal::qpe_config(); 393 OConfig*conf=OGlobal::qpe_config();
394 if (!conf)return; 394 if (!conf)return;
395 conf->setGroup("Time"); 395 conf->setGroup("Time");
396 return conf->writeEntry("AMPM",what); 396 return conf->writeEntry("AMPM",what);
397} 397}
398 398
399OConfig* OGlobal::qpe_config() 399OConfig* OGlobal::qpe_config()
400{ 400{
401 if ( !OGlobal::_qpe_config ) { 401 if ( !OGlobal::_qpe_config ) {
402 OGlobal::_qpe_config = new OConfig( "qpe" ); 402 OGlobal::_qpe_config = new OConfig( "qpe" );
403 } 403 }
404 return OGlobal::_qpe_config; 404 return OGlobal::_qpe_config;
405} 405}
406 406
407bool OGlobal::truncateFile( QFile &f, off_t size ) 407bool OGlobal::truncateFile( QFile &f, off_t size )
408{ 408{
409 /* or should we let enlarge Files? then remove this 409 /* or should we let enlarge Files? then remove this
410 f.size()< part! - Alwin 410 f.size()< part! - Alwin
411 */ 411 */
412 if (!f.exists()||f.size()<(unsigned)size) return false; 412 if (!f.exists()||f.size()<(unsigned)size) return false;
413 bool closeit=false; 413 bool closeit=false;
414 if (!f.isOpen()) { 414 if (!f.isOpen()) {
415 closeit=true; 415 closeit=true;
416 f.open(IO_Raw | IO_ReadWrite | IO_Append); 416 f.open(IO_Raw | IO_ReadWrite | IO_Append);
417 } 417 }
418 if (!f.isOpen()) { return false; } 418 if (!f.isOpen()) { return false; }
419 int r = ftruncate(f.handle(),size); 419 int r = ftruncate(f.handle(),size);
420 if (closeit) f.close(); 420 if (closeit) f.close();
421 return r==0; 421 return r==0;
422} 422}
diff --git a/libopie2/opiecore/oprocess.cpp b/libopie2/opiecore/oprocess.cpp
index b3f9724..56f9883 100644
--- a/libopie2/opiecore/oprocess.cpp
+++ b/libopie2/opiecore/oprocess.cpp
@@ -835,117 +835,117 @@ void OProcess::commClose()
835 } 835 }
836 836
837 if ( b_in ) 837 if ( b_in )
838 { 838 {
839 communication = ( Communication ) ( communication & ~Stdin ); 839 communication = ( Communication ) ( communication & ~Stdin );
840 close( in[ 1 ] ); 840 close( in[ 1 ] );
841 } 841 }
842 if ( b_out ) 842 if ( b_out )
843 { 843 {
844 communication = ( Communication ) ( communication & ~Stdout ); 844 communication = ( Communication ) ( communication & ~Stdout );
845 close( out[ 0 ] ); 845 close( out[ 0 ] );
846 } 846 }
847 if ( b_err ) 847 if ( b_err )
848 { 848 {
849 communication = ( Communication ) ( communication & ~Stderr ); 849 communication = ( Communication ) ( communication & ~Stderr );
850 close( err[ 0 ] ); 850 close( err[ 0 ] );
851 } 851 }
852 } 852 }
853} 853}
854 854
855void OProcess::setUseShell( bool useShell, const char *shell ) 855void OProcess::setUseShell( bool useShell, const char *shell )
856{ 856{
857 if ( !d ) 857 if ( !d )
858 d = new OProcessPrivate; 858 d = new OProcessPrivate;
859 d->useShell = useShell; 859 d->useShell = useShell;
860 d->shell = shell; 860 d->shell = shell;
861 if ( d->shell.isEmpty() ) 861 if ( d->shell.isEmpty() )
862 d->shell = searchShell(); 862 d->shell = searchShell();
863} 863}
864 864
865QString OProcess::quote( const QString &arg ) 865QString OProcess::quote( const QString &arg )
866{ 866{
867 QString res = arg; 867 QString res = arg;
868 res.replace( QRegExp( QString::fromLatin1( "\'" ) ), 868 res.replace( QRegExp( QString::fromLatin1( "\'" ) ),
869 QString::fromLatin1( "'\"'\"'" ) ); 869 QString::fromLatin1( "'\"'\"'" ) );
870 res.prepend( '\'' ); 870 res.prepend( '\'' );
871 res.append( '\'' ); 871 res.append( '\'' );
872 return res; 872 return res;
873} 873}
874 874
875QCString OProcess::searchShell() 875QCString OProcess::searchShell()
876{ 876{
877 QCString tmpShell = QCString( getenv( "SHELL" ) ).stripWhiteSpace(); 877 QCString tmpShell = QCString( getenv( "SHELL" ) ).stripWhiteSpace();
878 if ( !isExecutable( tmpShell ) ) 878 if ( !isExecutable( tmpShell ) )
879 { 879 {
880 tmpShell = "/bin/sh"; 880 tmpShell = "/bin/sh";
881 } 881 }
882 882
883 return tmpShell; 883 return tmpShell;
884} 884}
885 885
886bool OProcess::isExecutable( const QCString &filename ) 886bool OProcess::isExecutable( const QCString &filename )
887{ 887{
888 struct stat fileinfo; 888 struct stat fileinfo;
889 889
890 if ( filename.isEmpty() ) 890 if ( filename.isEmpty() )
891 return false; 891 return false;
892 892
893 // CC: we've got a valid filename, now let's see whether we can execute that file 893 // CC: we've got a valid filename, now let's see whether we can execute that file
894 894
895 if ( -1 == stat( filename.data(), &fileinfo ) ) 895 if ( -1 == stat( filename.data(), &fileinfo ) )
896 return false; 896 return false;
897 // CC: return false if the file does not exist 897 // CC: return false if the file does not exist
898 898
899 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets 899 // CC: anyway, we cannot execute directories, block/character devices, fifos or sockets
900 if ( ( S_ISDIR( fileinfo.st_mode ) ) || 900 if ( ( S_ISDIR( fileinfo.st_mode ) ) ||
901 ( S_ISCHR( fileinfo.st_mode ) ) || 901 ( S_ISCHR( fileinfo.st_mode ) ) ||
902 ( S_ISBLK( fileinfo.st_mode ) ) || 902 ( S_ISBLK( fileinfo.st_mode ) ) ||
903#ifdef S_ISSOCK 903#ifdef S_ISSOCK
904 // CC: SYSVR4 systems don't have that macro 904 // CC: SYSVR4 systems don't have that macro
905 ( S_ISSOCK( fileinfo.st_mode ) ) || 905 ( S_ISSOCK( fileinfo.st_mode ) ) ||
906#endif 906#endif
907 ( S_ISFIFO( fileinfo.st_mode ) ) || 907 ( S_ISFIFO( fileinfo.st_mode ) ) ||
908 ( S_ISDIR( fileinfo.st_mode ) ) ) 908 ( S_ISDIR( fileinfo.st_mode ) ) )
909 { 909 {
910 return false; 910 return false;
911 } 911 }
912 912
913 // CC: now check for permission to execute the file 913 // CC: now check for permission to execute the file
914 if ( access( filename.data(), X_OK ) != 0 ) 914 if ( access( filename.data(), X_OK ) != 0 )
915 return false; 915 return false;
916 916
917 // CC: we've passed all the tests... 917 // CC: we've passed all the tests...
918 return true; 918 return true;
919} 919}
920 920
921int OProcess::processPID( const QString& process ) 921int OProcess::processPID( const QString& process )
922{ 922{
923 QString line; 923 QString line;
924 QDir d = QDir( "/proc" ); 924 QDir d = QDir( "/proc" );
925 QStringList dirs = d.entryList( QDir::Dirs ); 925 QStringList dirs = d.entryList( QDir::Dirs );
926 QStringList::Iterator it; 926 QStringList::Iterator it;
927 for ( it = dirs.begin(); it != dirs.end(); ++it ) 927 for ( it = dirs.begin(); it != dirs.end(); ++it )
928 { 928 {
929 //qDebug( "next entry: %s", (const char*) *it ); 929 //qDebug( "next entry: %s", (const char*) *it );
930 QFile file( "/proc/"+*it+"/cmdline" ); 930 QFile file( "/proc/"+*it+"/cmdline" );
931 file.open( IO_ReadOnly ); 931 if ( !file.open( IO_ReadOnly ) ) continue;
932 if ( !file.isOpen() ) continue; 932 if ( !file.isOpen() ) continue;
933 QTextStream t( &file ); 933 QTextStream t( &file );
934 line = t.readLine(); 934 line = t.readLine();
935 //qDebug( "cmdline = %s", (const char*) line ); 935 //qDebug( "cmdline = %s", (const char*) line );
936 if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;) 936 if ( line.contains( process ) ) break; //FIXME: That may find also other process, if the name is not long enough ;)
937 } 937 }
938 if ( line.contains( process ) ) 938 if ( line.contains( process ) )
939 { 939 {
940 //qDebug( "found process id #%d", (*it).toInt() ); 940 //qDebug( "found process id #%d", (*it).toInt() );
941 return (*it).toInt(); 941 return (*it).toInt();
942 } 942 }
943 else 943 else
944 { 944 {
945 //qDebug( "process '%s' not found", (const char*) process ); 945 //qDebug( "process '%s' not found", (const char*) process );
946 return 0; 946 return 0;
947 } 947 }
948} 948}
949 949
950} 950}
951} 951}