uint8_t * buf;
struct stat sb;
int fd;
+ ssize_t n;
const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" );
/* try to stat the file */
errno = err;
return NULL;
}
+ tr_inf( "at the end of stat(%s), errno is %d", path, errno );
if( ( sb.st_mode & S_IFMT ) != S_IFREG )
{
errno = EISDIR;
return NULL;
}
+ tr_inf( "looks like %s is a regular file... now we'll try to read it", path );
/* Load the torrent file into our buffer */
fd = tr_open_file_for_scanning( path );
errno = err;
return NULL;
}
+ tr_inf( "after trying to open the file for reading, fd is %d and errno is %d", fd, errno );
buf = malloc( sb.st_size + 1 );
if( !buf )
{
errno = err;
return NULL;
}
- if( read( fd, buf, sb.st_size ) != sb.st_size )
+ n = read( fd, buf, sb.st_size );
+ tr_inf( "file size is %"PRId64"; read is %"PRId64", errno is %d", (int64_t)sb.st_size, (int64_t)n, errno );
+ if( n == -1 )
{
const int err = errno;
tr_err( err_fmt, path, tr_strerror( errno ) );
return NULL;
}
+ tr_inf( "nearing the end, and errno is %d", errno );
tr_close_file( fd );
buf[ sb.st_size ] = '\0';
*size = sb.st_size;