From 45f1316bcecf173761e697d7a1a1b45f526e9685 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 16 Jun 2009 17:10:47 +0000 Subject: [PATCH] (trunk libT) #2196: add a fallback implementation of preallocateFileFull() in case the os-specific and fs-specific approaches don't work. --- libtransmission/fdlimit.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index ac53513a7..6ab9ce792 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -183,6 +183,19 @@ preallocateFileFull( const char * filename, uint64_t length ) } # endif + if( !success ) /* if nothing else works, do it the old-fashioned way */ + { + uint8_t buf[ 4096 ]; + memset( buf, 0, sizeof( buf ) ); + success = TRUE; + while ( success && ( length > 0 ) ) + { + const int thisPass = MIN( length, sizeof( buf ) ); + success = write( fd, buf, thisPass ) == thisPass; + length -= thisPass; + } + } + close( fd ); }