~ubuntu-branches/ubuntu/hardy/transmission/hardy-updates

« back to all changes in this revision

Viewing changes to libtransmission/inout.c

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Benner
  • Date: 2007-12-05 14:37:05 UTC
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20071205143705-env7ahsls1gyb2eo
Tags: upstream-0.95.dfsg
ImportĀ upstreamĀ versionĀ 0.95.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: inout.c 3780 2007-11-10 14:59:14Z charles $
 
10
 * $Id: inout.c 3917 2007-11-21 16:16:57Z charles $
11
11
 */
12
12
 
13
13
#include <assert.h>
25
25
#include "fdlimit.h"
26
26
#include "inout.h"
27
27
#include "list.h"
28
 
#include "net.h"
29
28
#include "platform.h"
30
29
#include "peer-mgr.h"
31
30
#include "utils.h"
32
31
 
33
 
struct tr_io
34
 
{
35
 
    tr_torrent * tor;
36
 
};
37
 
 
38
32
/****
39
33
*****  Low-level IO functions
40
34
****/
72
66
        return 0;
73
67
    else if ((ioMode==TR_IO_READ) && stat( path, &sb ) ) /* does file exist? */
74
68
        ret = tr_ioErrorFromErrno ();
75
 
    else if ((fd = tr_fdFileOpen ( path, ioMode==TR_IO_WRITE )) < 0)
 
69
    else if ((fd = tr_fdFileCheckout ( path, ioMode==TR_IO_WRITE )) < 0)
76
70
        ret = fd;
77
71
    else if( lseek( fd, (off_t)fileOffset, SEEK_SET ) == ((off_t)-1) )
78
72
        ret = TR_ERROR_IO_OTHER;
79
73
    else if( func( fd, buf, buflen ) != buflen )
80
 
        ret = tr_ioErrorFromErrno ();
 
74
        ret = tr_ioErrorFromErrno( );
81
75
    else
82
76
        ret = TR_OK;
83
77
 
84
78
    if( fd >= 0 )
85
 
        tr_fdFileRelease( fd );
 
79
        tr_fdFileReturn( fd );
86
80
 
87
81
    return ret;
88
82
}
131
125
 
132
126
    tr_buildPath( path, sizeof(path), tor->destination, file->name, NULL );
133
127
 
134
 
    fd = tr_fdFileOpen( path, TRUE );
 
128
    fd = tr_fdFileCheckout( path, TRUE );
135
129
    if( fd < 0 ) /* bad fd */
136
130
        ret = fd;
137
131
    else if (fstat (fd, &sb) ) /* how big is the file? */
144
138
        ret = tr_ioErrorFromErrno ();
145
139
 
146
140
    if( fd >= 0 )
147
 
        tr_fdFileRelease( fd );
 
141
        tr_fdFileReturn( fd );
148
142
 
149
143
    return ret;
150
144
}