if (tr_variantDictFindReal(t, TR_KEY_recheckProgress, &percent))
{
- tr_snprintf(buf, buflen, "%s (%.0f%%)", str, floor(percent * 100.0));
+ tr_snprintf(buf, buflen, "%s (%.0f%%)", str, (floor)(percent * 100.0));
}
else
{
break;
}
- printf("%3d: %3.0f%% %-8s %-3s %9s %s\n", j, floor(100.0 * percent), pristr, wanted ? "Yes" : "No",
+ printf("%3d: %3.0f%% %-8s %-3s %9s %s\n", j, (floor)(100.0 * percent), pristr, wanted ? "Yes" : "No",
sizestr, filename);
}
}
gdk_threads_add_idle(core_read_rpc_response_idle, response_copy);
}
-static void core_send_rpc_request(TrCore* core, tr_variant const* request, int tag, server_response_func* response_func,
+static void core_send_rpc_request(TrCore* core, tr_variant const* request, int tag, server_response_func response_func,
void* response_func_user_data)
{
tr_session* session = gtr_core_session(core);
g_free(secondary);
}
-typedef void (PopupFunc)(GtkWidget*, GdkEventButton*);
+typedef void (* PopupFunc)(GtkWidget*, GdkEventButton*);
/* pop up the context menu if a user right-clicks.
if the row they right-click on isn't selected, select it. */
if (func != NULL)
{
- ((PopupFunc*)func)(view, event);
+ (*(PopupFunc)func)(view, event);
}
return TRUE;
{
dbgmsg(tracker->key, "DNS lookup succeeded");
tracker->addr = addr;
- tracker->addr_expiration_time = tr_time() + (60 * 60); /* one hour */
+ tracker->addr_expiration_time = tr_time() + 60 * 60; /* one hour */
tau_tracker_upkeep(tracker);
}
}
tau = session->announcer_udp;
transaction_id = evbuffer_read_ntoh_32(buf);
- /*fprintf(stderr, "UDP got a transaction_id %u...\n", transaction_id);*/
+ /* fprintf(stderr, "UDP got a transaction_id %u...\n", transaction_id); */
for (i = 0, n = tr_ptrArraySize(&tau->trackers); i < n; ++i)
{
int j, jn;
return 20;
case 2:
- return tr_rand_int_weak(60) + (60 * 5);
+ return tr_rand_int_weak(60) + 60 * 5;
case 3:
- return tr_rand_int_weak(60) + (60 * 15);
+ return tr_rand_int_weak(60) + 60 * 15;
case 4:
- return tr_rand_int_weak(60) + (60 * 30);
+ return tr_rand_int_weak(60) + 60 * 30;
case 5:
- return tr_rand_int_weak(60) + (60 * 60);
+ return tr_rand_int_weak(60) + 60 * 60;
default:
- return tr_rand_int_weak(60) + (60 * 120);
+ return tr_rand_int_weak(60) + 60 * 120;
}
}
}
}
- rvolatile->cache_val = (unsigned int)((bytes * 1000u) / interval_msec);
+ rvolatile->cache_val = (unsigned int)(bytes * 1000u / interval_msec);
rvolatile->cache_time = now;
}
if (excess_bit_count)
{
- b->bits[b->alloc_count - 1] &= ((0xff) << excess_bit_count);
+ b->bits[b->alloc_count - 1] &= 0xff << excess_bit_count;
}
}
{
if (!tr_bitfieldHas(b, nth) && tr_bitfieldEnsureNthBitAlloced(b, nth))
{
- b->bits[nth >> 3u] |= (0x80 >> (nth & 7u));
+ b->bits[nth >> 3u] |= 0x80 >> (nth & 7u);
tr_bitfieldIncTrueCount(b, 1);
}
}
if (sb == eb)
{
- b->bits[sb] |= (sm & em);
+ b->bits[sb] |= sm & em;
}
else
{
if (tr_bitfieldHas(b, nth) && tr_bitfieldEnsureNthBitAlloced(b, nth))
{
- b->bits[nth >> 3u] &= (0xff7f >> (nth & 7u));
+ b->bits[nth >> 3u] &= 0xff7f >> (nth & 7u);
tr_bitfieldDecTrueCount(b, 1);
}
}
if (sb == eb)
{
- b->bits[sb] &= (sm | em);
+ b->bits[sb] &= sm | em;
}
else
{
if (l == cp->tor->blockCount - 1 && tr_bitfieldHas(&cp->blockBitfield, l))
{
- n -= (cp->tor->blockSize - cp->tor->lastBlockSize);
+ n -= cp->tor->blockSize - cp->tor->lastBlockSize;
}
}
static ReadState readPadA(tr_handshake* handshake, struct evbuffer* inbuf)
{
- /* resynchronizing on HASH('req1',S) */
+ /* resynchronizing on HASH('req1', S) */
struct evbuffer_ptr ptr = evbuffer_search(inbuf, (char const*)handshake->myReq1, SHA_DIGEST_LENGTH, NULL);
if (ptr.pos != -1) /* match */
{
unsigned int n;
time_t date;
- } slices[TR_RECENT_HISTORY_PERIOD_SEC];
+ }
+ slices[TR_RECENT_HISTORY_PERIOD_SEC];
}
tr_recentHistory;
if (deepLoggingIsActive < 0)
{
- deepLoggingIsActive = IsDebuggerPresent() || (tr_logGetFile() != TR_BAD_SYS_FILE);
+ deepLoggingIsActive = IsDebuggerPresent() || tr_logGetFile() != TR_BAD_SYS_FILE;
}
return deepLoggingIsActive != 0;
else
{
index = (index + 5) % 8;
- out[offset] |= (digit >> index);
+ out[offset] |= digit >> index;
offset++;
if (offset >= outlen)
}
else
{
- memset(io->peerId, 0, 20);
+ memset(io->peerId, '\0', 20);
}
}
}
/* In most cases we've just changed the weights of a small number of pieces.
- * So rather than qsort ()ing the entire array, it's faster to apply an
+ * So rather than qsort()ing the entire array, it's faster to apply an
* adaptive insertion sort algorithm. */
if (got > 0)
{
/* disconnect if it's been too long since piece data has been transferred.
* this is on a sliding scale based on number of available peers... */
{
- int const relaxStrictnessIfFewerThanN = (int)((getMaxPeerCount(tor) * 0.9) + 0.5);
+ int const relaxStrictnessIfFewerThanN = (int)(getMaxPeerCount(tor) * 0.9 + 0.5);
/* if we have >= relaxIfFewerThan, strictness is 100%.
* if we have zero connections, strictness is 0% */
float const strictness = peerCount >= relaxStrictnessIfFewerThanN ? 1.0 :
peerCount / (float)relaxStrictnessIfFewerThanN;
int const lo = MIN_UPLOAD_IDLE_SECS;
int const hi = MAX_UPLOAD_IDLE_SECS;
- int const limit = hi - ((hi - lo) * strictness);
+ int const limit = hi - (hi - lo) * strictness;
int const idleTime = now - MAX(atom->time, atom->piece_data_time);
/*
static inline uint64_t addValToKey(uint64_t value, int width, uint64_t addme)
{
- value = (value << (uint64_t)width);
+ value = value << (uint64_t)width;
value |= addme;
return value;
}
void tr_peerMsgsCancel(tr_peerMsgs* msgs, tr_block_index_t block)
{
struct peer_request req;
- // fprintf(stderr, "SENDING CANCEL MESSAGE FOR BLOCK %zu\n\t\tFROM PEER %p ------------------------------------\n", (size_t)block,
- // msgs->peer);
+ // fprintf(stderr, "SENDING CANCEL MESSAGE FOR BLOCK %zu\n\t\tFROM PEER %p ------------------------------------\n",
+ // (size_t)block, msgs->peer);
blockToReq(msgs->torrent, block, &req);
protocolSendCancel(msgs, &req);
}
uint32_t msglen = msgs->incoming.length;
uint8_t const id = msgs->incoming.id;
#ifndef NDEBUG
- size_t const startBufLen = evbuffer_get_length(inbuf);
+ size_t const startBufLen = evbuffer_get_length(inbuf);
#endif
bool const fext = tr_peerIoSupportsFEXT(msgs->io);
diffs->elements[diffs->elementCount++] = *pex;
}
-typedef void (tr_set_func)(void* element, void* userData);
+typedef void (* tr_set_func)(void* element, void* userData);
/**
* @brief find the differences and commonalities in two sorted sets
if (quotactl(device, QCMD(Q_GETQUOTA, USRQUOTA), getuid(), (caddr_t)&dq) == 0)
{
+
#elif defined(__sun)
struct quotctl op;
if (quotactl(QCMD(Q_GETQUOTA, USRQUOTA), device, getuid(), (caddr_t)&dq) == 0)
{
+
#endif
if (dq.dqb_bsoftlimit > 0)
memmove(t->items + begin, t->items + end, sizeof(void*) * (t->n_items - end));
- t->n_items -= (end - begin);
+ t->n_items -= end - begin;
}
/**
for (i = 0; i < count && numAdded < MAX_REMEMBERED_PEERS; ++i)
{
tr_pex pex;
- memcpy(&pex, buf + (i * sizeof(tr_pex)), sizeof(tr_pex));
+ memcpy(&pex, buf + i * sizeof(tr_pex), sizeof(tr_pex));
if (tr_isPex(&pex))
{
size_t part_len;
char const* part = delim + boundary_len;
- inlen -= (part - in);
+ inlen -= part - in;
in = part;
delim = tr_memmem(in, inlen, boundary, boundary_len);
#endif
- evhttp_add_header(req->output_headers,
- "Content-Encoding", "gzip");
+ evhttp_add_header(req->output_headers, "Content-Encoding", "gzip");
}
else
{
#define RECENTLY_ACTIVE_SECONDS 60
-#define TR_N_ELEMENTS(ary)(sizeof(ary) / sizeof(*ary))
+#define TR_N_ELEMENTS(ary) (sizeof(ary) / sizeof(*ary))
#if 0
if (session->rpc_func != NULL)
{
- status = session->rpc_func(session, type, tor, session->rpc_func_user_data);
+ status = (*session->rpc_func)(session, type, tor, session->rpc_func_user_data);
}
return status;
if (!tr_sys_file_lock(lock_file, TR_SYS_FILE_LOCK_SH | TR_SYS_FILE_LOCK_NB, &error))
{
#ifndef _WIN32
-
if (error->code == EWOULDBLOCK)
#else
-
if (error->code == ERROR_LOCK_VIOLATION)
#endif
{
return isLimited;
}
+
bool tr_sessionGetActiveSpeedLimit_KBps(tr_session const* session, tr_direction dir, double* setme_KBps)
{
unsigned int Bps = 0;
}
else
{
- ttl = (int)difftime(tor->peer_id_creation_time + (tor->session->peer_id_ttl_hours * 3600), tr_time());
+ ttl = (int)difftime(tor->peer_id_creation_time + tor->session->peer_id_ttl_hours * 3600, tr_time());
}
return ttl;
/* maybe notify the client */
if (tor->ratio_limit_hit_func != NULL)
{
- tor->ratio_limit_hit_func(tor, tor->ratio_limit_hit_func_user_data);
+ (*tor->ratio_limit_hit_func)(tor, tor->ratio_limit_hit_func_user_data);
}
}
/* if we're seeding and reach our inactiviy limit, stop the torrent */
/* maybe notify the client */
if (tor->idle_limit_hit_func != NULL)
{
- tor->idle_limit_hit_func(tor, tor->idle_limit_hit_func_user_data);
+ (*tor->idle_limit_hit_func)(tor, tor->idle_limit_hit_func_user_data);
}
}
}
if (disappeared)
{
tr_deeplog_tor(tor, "%s", "[LAZY] uh oh, the files disappeared");
- tr_torrentSetLocalError(tor, "%s",
- _(
- "No data found! Ensure your drives are connected or use \"Set Location\". To re-download, remove the torrent and re-add it."));
+ tr_torrentSetLocalError(tor, "%s", _("No data found! Ensure your drives are connected or use \"Set Location\". "
+ "To re-download, remove the torrent and re-add it."));
}
return disappeared;
/* the first block */
if (tr_torrentBlockIsComplete(tor, first))
{
- total += tor->blockSize - (f->offset % tor->blockSize);
+ total += tor->blockSize - f->offset % tor->blockSize;
}
/* the middle blocks */
/* the last block */
if (tr_torrentBlockIsComplete(tor, last))
{
- total += (f->offset + f->length) - ((uint64_t)tor->blockSize * last);
+ total += f->offset + f->length - (uint64_t)tor->blockSize * last;
}
}
}
if (tor->completeness_func != NULL)
{
- tor->completeness_func(tor, status, wasRunning, tor->completeness_func_user_data);
+ (*tor->completeness_func)(tor, status, wasRunning, tor->completeness_func_user_data);
}
}
if (tor->metadata_func != NULL)
{
- tor->metadata_func(tor, tor->metadata_func_user_data);
+ (*tor->metadata_func)(tor, tor->metadata_func_user_data);
}
}
uint64_t pos = block;
pos *= tor->blockSize;
*piece = pos / tor->info.pieceSize;
- *offset = pos - (*piece * tor->info.pieceSize);
+ *offset = pos - *piece * tor->info.pieceSize;
*length = tr_torBlockCountBytes(tor, block);
}
assert(tr_isTorrent(tor));
ret = index;
- ret *= (tor->info.pieceSize / tor->blockSize);
+ ret *= tor->info.pieceSize / tor->blockSize;
ret += offset / tor->blockSize;
return ret;
}
uint64_t offset = tor->info.pieceSize;
offset *= piece;
*first = offset / tor->blockSize;
- offset += (tr_torPieceCountBytes(tor, piece) - 1);
+ offset += tr_torPieceCountBytes(tor, piece) - 1;
*last = offset / tor->blockSize;
}
if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0)
{
char* file = tr_buildPath(tmpdir, name, NULL);
- func(file, NULL);
+ (*func)(file, NULL);
tr_free(file);
}
}
while (tr_sys_path_exists(walk, NULL) && !tr_sys_path_is_same(tmpdir, walk, NULL))
{
char* tmp = tr_sys_path_dirname(walk, NULL);
- func(walk, NULL);
+ (*func)(walk, NULL);
tr_free(walk);
walk = tmp;
}
}
}
- tor->queuePosition = MIN(pos, (back + 1));
+ tor->queuePosition = MIN(pos, back + 1);
tor->anyDate = now;
assert(queueIsSequenced(tor->session));
if (!eh->die && ngot == (ev_ssize_t)nwant)
{
dbgmsg("invoking function in libevent thread");
- (data.func)(data.user_data);
+ (*data.func)(data.user_data);
}
break;
for (i = left; i <= right - 1; ++i)
{
- if (compar(base + (size * i), base + (size * right)) <= 0)
+ if ((*compar)(base + (size * i), base + (size * right)) <= 0)
{
SWAP(base + (size * storeIndex), base + (size * i), size);
++storeIndex;
for (i = left; i < storeIndex; ++i)
{
- assert(compar(base + (size * i), base + (size * storeIndex)) <= 0);
+ assert((*compar)(base + (size * i), base + (size * storeIndex)) <= 0);
}
for (i = storeIndex + 1; i <= right; ++i)
{
- assert(compar(base + (size * i), base + (size * storeIndex)) >= 0);
+ assert((*compar)(base + (size * i), base + (size * storeIndex)) >= 0);
}
#endif
for (i = 1; i < k; ++i)
{
- if (compar(base + (size * worstFirstPos), base + (size * i)) < 0)
+ if ((*compar)(base + (size * worstFirstPos), base + (size * i)) < 0)
{
worstFirstPos = i;
}
for (i = 0; i < k; ++i)
{
- assert(compar(base + (size * i), base + (size * worstFirstPos)) <= 0);
+ assert((*compar)(base + (size * i), base + (size * worstFirstPos)) <= 0);
}
for (i = k; i < nmemb; ++i)
{
- assert(compar(base + (size * i), base + (size * worstFirstPos)) >= 0);
+ assert((*compar)(base + (size * i), base + (size * worstFirstPos)) >= 0);
}
}
tr_win32_make_args_utf8(&argc, &argv);
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
- return real_main(argc, argv);
+ return (*real_main)(argc, argv);
}
#endif
main_impl(__VA_ARGS__); \
int main(int argc, char* argv[]) \
{ \
- return tr_main_win32(argc, argv, & main_impl); \
+ return tr_main_win32(argc, argv, &main_impl); \
} \
int main_impl(__VA_ARGS__)
void* tr_memdup(void const* src, size_t byteCount);
#define tr_new(struct_type, n_structs) \
- ((struct_type*)tr_malloc(sizeof(struct_type)* ((size_t)(n_structs))))
+ ((struct_type*)tr_malloc(sizeof(struct_type) * (size_t)(n_structs)))
#define tr_new0(struct_type, n_structs) \
- ((struct_type*)tr_malloc0(sizeof(struct_type)* ((size_t)(n_structs))))
+ ((struct_type*)tr_malloc0(sizeof(struct_type) * (size_t)(n_structs)))
#define tr_renew(struct_type, mem, n_structs) \
- ((struct_type*)tr_realloc((mem), sizeof(struct_type)* ((size_t)(n_structs))))
+ ((struct_type*)tr_realloc((mem), sizeof(struct_type) * (size_t)(n_structs)))
void* tr_valloc(size_t bufLen);
if ('0' <= *in && *in <= '9')
{
- val += (*in - '0');
+ val += *in - '0';
}
else if ('a' <= *in && *in <= 'f')
{
- val += (*in - 'a') + 10u;
+ val += *in - 'a' + 10u;
}
else if ('A' <= *in && *in <= 'F')
{
- val += (*in - 'A') + 10u;
+ val += *in - 'A' + 10u;
}
else
{
break;
default /* TR_VARIANT_FMT_BENC */:
- err = tr_variantParseBenc(buf, ((char const*)buf) + buflen, setme, setme_end);
+ err = tr_variantParseBenc(buf, (char const*)buf + buflen, setme, setme_end);
break;
}
if (task->done_func != NULL)
{
- task->done_func(task->session, task->did_connect, task->did_timeout, task->code, evbuffer_pullup(task->response, -1),
+ (*task->done_func)(task->session, task->did_connect, task->did_timeout, task->code, evbuffer_pullup(task->response, -1),
evbuffer_get_length(task->response), task->done_func_user_data);
}
{
if (w->callback != NULL)
{
- w->callback(&w->parent, e, w->callback_data);
+ (*w->callback)(&w->parent, e, w->callback_data);
}
}
data->webseed = w;
data->real_url = tr_strdup(url);
data->piece_index = task->piece_index;
- data->piece_offset = task->piece_offset + (task->blocks_done * task->block_size) + (len - 1);
+ data->piece_offset = task->piece_offset + task->blocks_done * task->block_size + len - 1;
/* processing this uses a tr_torrent pointer,
so push the work to the libevent thread... */
task->webseed = w;
task->block = b;
task->piece_index = tr_torBlockPiece(tor, b);
- task->piece_offset = (tor->blockSize * b) - (tor->info.pieceSize * task->piece_index);
+ task->piece_offset = tor->blockSize * b - tor->info.pieceSize * task->piece_index;
task->length = (be - b) * tor->blockSize + tr_torBlockCountBytes(tor, be);
task->blocks_done = 0;
task->response_code = 0;
uint64_t const total_offset = tr_pieceOffset(tor, t->piece_index, t->piece_offset, t->length - remain);
tr_piece_index_t const step_piece = total_offset / inf->pieceSize;
- uint64_t const step_piece_offset = total_offset - (inf->pieceSize * step_piece);
+ uint64_t const step_piece_offset = total_offset - inf->pieceSize * step_piece;
tr_file_index_t file_index;
tr_file const* file;
namespace
{
+
void setIfIdle(QComboBox* box, int i)
{
if (!box->hasFocus())
spin->blockSignals(false);
}
}
-}
+
+} // namespace
void DetailsDialog::refresh()
{
// update the "All" row
myTrackerModel->setData(myTrackerModel->index(0, 0), myTorrents.rowCount(), FilterBarComboBox::CountRole);
- myTrackerModel->setData(myTrackerModel->index(0, 0), getCountString(
- myTorrents.rowCount()), FilterBarComboBox::CountStringRole);
+ myTrackerModel->setData(myTrackerModel->index(0, 0), getCountString(myTorrents.rowCount()),
+ FilterBarComboBox::CountStringRole);
// rows to update
for (QString const& host : oldHosts & newHosts)
d->show();
}
+namespace
+{
+
// Open Folder & select torrent's file or top folder
#undef HAVE_OPEN_SELECT
#endif
+} // namespace
+
void MainWindow::openFolder()
{
QSet<int> const selectedTorrents = getSelectedTorrents();
{
if (seconds > 60)
{
- seconds -= (seconds % 60);
+ seconds -= seconds % 60;
}
return Formatter::timeToString(seconds);
{
if (tr_variantGetStr(node, &str, NULL) && strcmp(str, url) == 0)
{
- printf("\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, (tierIndex + 1));
+ printf("\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, tierIndex + 1);
tr_variantListRemove(tier, nodeIndex);
changed = true;
}
if (tr_variantListSize(tier) == 0)
{
- printf("\tNo URLs left in tier #%d... removing tier\n", (tierIndex + 1));
+ printf("\tNo URLs left in tier #%d... removing tier\n", tierIndex + 1);
tr_variantListRemove(announce_list, tierIndex);
}
else