(trunk libT) #1976: build problem with r8173: "erreur: ‘POSIX_FADV_SEQUENTIAL’ undeclared"

This commit is contained in:
Charles Kerr 2009-04-07 20:25:32 +00:00
parent 7936dddd57
commit 87e4c99fbb
3 changed files with 40 additions and 5 deletions

View File

@ -205,6 +205,42 @@ preallocateFileFull( const char * filename, uint64_t length )
return success;
}
FILE*
tr_open_file_for_reading( const char * filename, tr_bool sequential )
{
int fd;
int flags;
/* build the flags */
flags = O_RDONLY;
#ifdef O_SEQUENTIAL
if( sequential ) flags |= O_SEQUENTIAL;
#endif
#ifdef O_RANDOM
if( !sequential ) flags |= O_RANDOM
#endif
#ifdef O_BINARY
flags |= O_BINARY;
#endif
#ifdef O_LARGEFILE
flags |= O_LARGEFILE;
#endif
/* open the file */
fd = open( filename, flags, 0666 );
if( fd < 0 )
return NULL;
#if defined( SYS_DARWIN )
fcntl( fd, F_NOCACHE, 1 );
fcntl( fd, F_RDAHEAD, sequential );
#elif defined( HAVE_POSIX_FADVISE )
posix_fadvise( fd, 0, 0, sequential ? POSIX_FADV_SEQUENTIAL : POSIX_FADV_RANDOM );
#endif
return fdopen( fd, "r" );
}
/**
* returns 0 on success, or an errno value on failure.
* errno values include ENOENT if the parent folder doesn't exist,

View File

@ -32,6 +32,8 @@
void tr_fdInit( size_t openFileLimit,
size_t globalPeerLimit );
FILE* tr_open_file_for_reading( const char * filename, tr_bool sequential );
/**
* Returns an fd to the specified filename.
*

View File

@ -22,6 +22,7 @@
#include "transmission.h"
#include "completion.h"
#include "fdlimit.h"
#include "resume.h" /* tr_torrentSaveResume() */
#include "inout.h"
#include "list.h"
@ -74,11 +75,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag )
if( !filePos && !fp )
{
char * filename = tr_buildPath( tor->downloadDir, file->name, NULL );
fp = fopen( filename, "rb" );
#ifdef HAVE_POSIX_FADVISE
if( fp != NULL )
posix_fadvise( fileno( fp ), 0, 0, POSIX_FADV_SEQUENTIAL );
#endif
fp = tr_open_file_for_reading( filename, TRUE );
/* fprintf( stderr, "opening file #%d (%s) -- %p\n", fileIndex, filename, fp ); */
tr_free( filename );
}