From kde-commits Thu Sep 02 15:31:17 2004 From: =?utf-8?q?Lu=C3=ADs=20Pedro=20Coelho?= Date: Thu, 02 Sep 2004 15:31:17 +0000 To: kde-commits Subject: kdelibs/kdecore Message-Id: <20040902153117.3761F1EFF () office ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=109413909509604 CVS commit by luis_pedro: Make the code simpler to understand, while fixing a small bug: if ( !kDebug_data->aAreaName.isEmpty() ) { strlcpy( buf, kDebug_data->aAreaName.data(), BUFSIZE ); strlcat( buf, ": ", BUFSIZE ); strlcat( buf, data, BUFSIZE ); - nSize = strlen( buf ); } else - nSize = strlcpy( buf, data, BUFSIZE ); The meaning is not the same. strlcpy returns the number of characters which would have been copied if the buffer was large enough. Not that it ever matters in practice, but it doesn't hurt. M +3 -8 kdebug.cpp 1.141 --- kdelibs/kdecore/kdebug.cpp #1.140:1.141 @@ -250,13 +250,11 @@ static void kDebugBackend( unsigned shor const int BUFSIZE = 4096; char buf[BUFSIZE]; - int nSize; if ( !kDebug_data->aAreaName.isEmpty() ) { strlcpy( buf, kDebug_data->aAreaName.data(), BUFSIZE ); strlcat( buf, ": ", BUFSIZE ); strlcat( buf, data, BUFSIZE ); - nSize = strlen( buf ); } else - nSize = strlcpy( buf, data, BUFSIZE ); + strlcpy( buf, data, BUFSIZE ); @@ -285,8 +283,5 @@ static void kDebugBackend( unsigned shor QFile aOutputFile( kDebug_data->config->readPathEntry(aKey, "kdebug.dbg") ); aOutputFile.open( IO_WriteOnly | IO_Append | IO_Raw ); - if ( ( nSize == -1 ) || ( nSize >= BUFSIZE ) ) - aOutputFile.writeBlock( buf, BUFSIZE-1 ); - else - aOutputFile.writeBlock( buf, nSize ); + aOutputFile.writeBlock( buf, strlen( buf ) ); aOutputFile.close(); break; @@ -303,5 +298,5 @@ static void kDebugBackend( unsigned shor case 2: // Shell { - write( 2, buf, nSize ); //fputs( buf, stderr ); + write( 2, buf, strlen( buf ) ); //fputs( buf, stderr ); break; }