summaryrefslogtreecommitdiff
path: root/toxcore/tox.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-08-31 20:40:20 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-02 11:02:56 +0100
commita9fbdaf46b23db5c598bf33d6bc5c4555b06e674 (patch)
treee7894501bd010d9904fe0069fc1b8121d2da4040 /toxcore/tox.c
parent6f42eadc54e81be50b7a817c72b0cf4d7ec5feb4 (diff)
Do not use `else` after `return`.
http://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r--toxcore/tox.c51
1 files changed, 27 insertions, 24 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 94cb7261..40bfaf70 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -379,10 +379,10 @@ bool tox_bootstrap(Tox *tox, const char *address, uint16_t port, const uint8_t *
379 if (count) { 379 if (count) {
380 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_OK); 380 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_OK);
381 return 1; 381 return 1;
382 } else {
383 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
384 return 0;
385 } 382 }
383
384 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
385 return 0;
386} 386}
387 387
388bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key, 388bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8_t *public_key,
@@ -436,10 +436,10 @@ bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8
436 if (count) { 436 if (count) {
437 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_OK); 437 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_OK);
438 return 1; 438 return 1;
439 } else {
440 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
441 return 0;
442 } 439 }
440
441 SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
442 return 0;
443} 443}
444 444
445TOX_CONNECTION tox_self_get_connection_status(const Tox *tox) 445TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
@@ -450,11 +450,13 @@ TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
450 450
451 if (ret == 2) { 451 if (ret == 2) {
452 return TOX_CONNECTION_UDP; 452 return TOX_CONNECTION_UDP;
453 } else if (ret == 1) { 453 }
454
455 if (ret == 1) {
454 return TOX_CONNECTION_TCP; 456 return TOX_CONNECTION_TCP;
455 } else {
456 return TOX_CONNECTION_NONE;
457 } 457 }
458
459 return TOX_CONNECTION_NONE;
458} 460}
459 461
460 462
@@ -529,10 +531,10 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, TOX_ERR_SET
529 send_name_all_groups(m->group_chat_object); 531 send_name_all_groups(m->group_chat_object);
530 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); 532 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK);
531 return 1; 533 return 1;
532 } else {
533 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG);
534 return 0;
535 } 534 }
535
536 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG);
537 return 0;
536} 538}
537 539
538size_t tox_self_get_name_size(const Tox *tox) 540size_t tox_self_get_name_size(const Tox *tox)
@@ -561,10 +563,10 @@ bool tox_self_set_status_message(Tox *tox, const uint8_t *status_message, size_t
561 if (m_set_statusmessage(m, status_message, length) == 0) { 563 if (m_set_statusmessage(m, status_message, length) == 0) {
562 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); 564 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK);
563 return 1; 565 return 1;
564 } else {
565 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG);
566 return 0;
567 } 566 }
567
568 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_TOO_LONG);
569 return 0;
568} 570}
569 571
570size_t tox_self_get_status_message_size(const Tox *tox) 572size_t tox_self_get_status_message_size(const Tox *tox)
@@ -623,7 +625,6 @@ static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error)
623 case FAERR_NOMEM: 625 case FAERR_NOMEM:
624 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_MALLOC); 626 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_ADD_MALLOC);
625 break; 627 break;
626
627 } 628 }
628} 629}
629 630
@@ -1095,7 +1096,9 @@ bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_
1095 if (ret == 0) { 1096 if (ret == 0) {
1096 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_OK); 1097 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_OK);
1097 return 1; 1098 return 1;
1098 } else if (ret == -1) { 1099 }
1100
1101 if (ret == -1) {
1099 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_FRIEND_NOT_FOUND); 1102 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_FRIEND_NOT_FOUND);
1100 } else { 1103 } else {
1101 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NOT_FOUND); 1104 SET_ERROR_PARAMETER(error, TOX_ERR_FILE_GET_NOT_FOUND);
@@ -1268,9 +1271,9 @@ bool tox_friend_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_
1268 1271
1269 if (ret == 0) { 1272 if (ret == 0) {
1270 return 1; 1273 return 1;
1271 } else {
1272 return 0;
1273 } 1274 }
1275
1276 return 0;
1274} 1277}
1275 1278
1276void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback, void *user_data) 1279void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *callback, void *user_data)
@@ -1300,9 +1303,9 @@ bool tox_friend_send_lossless_packet(Tox *tox, uint32_t friend_number, const uin
1300 1303
1301 if (ret == 0) { 1304 if (ret == 0) {
1302 return 1; 1305 return 1;
1303 } else {
1304 return 0;
1305 } 1306 }
1307
1308 return 0;
1306} 1309}
1307 1310
1308void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback, void *user_data) 1311void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *callback, void *user_data)
@@ -1340,8 +1343,8 @@ uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error)
1340 if (m->tcp_server) { 1343 if (m->tcp_server) {
1341 SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK); 1344 SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_OK);
1342 return m->options.tcp_server_port; 1345 return m->options.tcp_server_port;
1343 } else {
1344 SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_NOT_BOUND);
1345 return 0;
1346 } 1346 }
1347
1348 SET_ERROR_PARAMETER(error, TOX_ERR_GET_PORT_NOT_BOUND);
1349 return 0;
1347} 1350}