summaryrefslogtreecommitdiffstats
path: root/src/idevice.c
diff options
context:
space:
mode:
authorGravatar Rosen Penev2020-12-23 17:39:01 -0800
committerGravatar Nikias Bassen2022-04-30 13:34:21 +0200
commitcf2c7d48380969200034afeab93169e68c34c397 (patch)
treea96f518be279922d00898a3ce81dc0ff483a40b2 /src/idevice.c
parent6cb13f9e6d3939930aecf91d8e23d1896a3b92e5 (diff)
downloadlibimobiledevice-cf2c7d48380969200034afeab93169e68c34c397.tar.gz
libimobiledevice-cf2c7d48380969200034afeab93169e68c34c397.tar.bz2
[clang-tidy] Do not use else after return
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Diffstat (limited to 'src/idevice.c')
-rw-r--r--src/idevice.c76
1 files changed, 39 insertions, 37 deletions
diff --git a/src/idevice.c b/src/idevice.c
index f64570b..adf47f4 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -473,7 +473,8 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t
473 new_connection->status = IDEVICE_E_SUCCESS; 473 new_connection->status = IDEVICE_E_SUCCESS;
474 *connection = new_connection; 474 *connection = new_connection;
475 return IDEVICE_E_SUCCESS; 475 return IDEVICE_E_SUCCESS;
476 } else if (device->conn_type == CONNECTION_NETWORK) { 476 }
477 if (device->conn_type == CONNECTION_NETWORK) {
477 struct sockaddr_storage saddr_storage; 478 struct sockaddr_storage saddr_storage;
478 struct sockaddr* saddr = (struct sockaddr*)&saddr_storage; 479 struct sockaddr* saddr = (struct sockaddr*)&saddr_storage;
479 480
@@ -529,10 +530,9 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t
529 *connection = new_connection; 530 *connection = new_connection;
530 531
531 return IDEVICE_E_SUCCESS; 532 return IDEVICE_E_SUCCESS;
532 } else {
533 debug_info("Unknown connection type %d", device->conn_type);
534 } 533 }
535 534
535 debug_info("Unknown connection type %d", device->conn_type);
536 return IDEVICE_E_UNKNOWN_ERROR; 536 return IDEVICE_E_UNKNOWN_ERROR;
537} 537}
538 538
@@ -583,7 +583,8 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection,
583 return IDEVICE_E_UNKNOWN_ERROR; 583 return IDEVICE_E_UNKNOWN_ERROR;
584 } 584 }
585 return IDEVICE_E_SUCCESS; 585 return IDEVICE_E_SUCCESS;
586 } else if (connection->type == CONNECTION_NETWORK) { 586 }
587 if (connection->type == CONNECTION_NETWORK) {
587 int s = socket_send((int)(long)connection->data, (void*)data, len); 588 int s = socket_send((int)(long)connection->data, (void*)data, len);
588 if (s < 0) { 589 if (s < 0) {
589 *sent_bytes = 0; 590 *sent_bytes = 0;
@@ -591,9 +592,9 @@ static idevice_error_t internal_connection_send(idevice_connection_t connection,
591 } 592 }
592 *sent_bytes = s; 593 *sent_bytes = s;
593 return IDEVICE_E_SUCCESS; 594 return IDEVICE_E_SUCCESS;
594 } else {
595 debug_info("Unknown connection type %d", connection->type);
596 } 595 }
596
597 debug_info("Unknown connection type %d", connection->type);
597 return IDEVICE_E_UNKNOWN_ERROR; 598 return IDEVICE_E_UNKNOWN_ERROR;
598 599
599} 600}
@@ -638,27 +639,26 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_send(idevice_connection_
638 } 639 }
639 *sent_bytes = sent; 640 *sent_bytes = sent;
640 return IDEVICE_E_SUCCESS; 641 return IDEVICE_E_SUCCESS;
641 } else { 642 }
642 uint32_t sent = 0; 643 uint32_t sent = 0;
643 while (sent < len) { 644 while (sent < len) {
644 uint32_t bytes = 0; 645 uint32_t bytes = 0;
645 int s = internal_connection_send(connection, data+sent, len-sent, &bytes); 646 int s = internal_connection_send(connection, data+sent, len-sent, &bytes);
646 if (s < 0) { 647 if (s < 0) {
647 break; 648 break;
648 }
649 sent += bytes;
650 }
651 debug_info("len %d, sent %d", len, sent);
652 if (sent < len) {
653 *sent_bytes = sent;
654 if (sent == 0) {
655 return IDEVICE_E_UNKNOWN_ERROR;
656 }
657 return IDEVICE_E_NOT_ENOUGH_DATA;
658 } 649 }
650 sent += bytes;
651 }
652 debug_info("internal_connection_send %d, sent %d", len, sent);
653 if (sent < len) {
659 *sent_bytes = sent; 654 *sent_bytes = sent;
660 return IDEVICE_E_SUCCESS; 655 if (sent == 0) {
656 return IDEVICE_E_UNKNOWN_ERROR;
657 }
658 return IDEVICE_E_NOT_ENOUGH_DATA;
661 } 659 }
660 *sent_bytes = sent;
661 return IDEVICE_E_SUCCESS;
662} 662}
663 663
664static inline idevice_error_t socket_recv_to_idevice_error(int conn_error, uint32_t len, uint32_t received) 664static inline idevice_error_t socket_recv_to_idevice_error(int conn_error, uint32_t len, uint32_t received)
@@ -698,7 +698,8 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t
698 debug_info("ERROR: usbmuxd_recv_timeout returned %d (%s)", conn_error, strerror(-conn_error)); 698 debug_info("ERROR: usbmuxd_recv_timeout returned %d (%s)", conn_error, strerror(-conn_error));
699 } 699 }
700 return error; 700 return error;
701 } else if (connection->type == CONNECTION_NETWORK) { 701 }
702 if (connection->type == CONNECTION_NETWORK) {
702 int res = socket_receive_timeout((int)(long)connection->data, data, len, 0, timeout); 703 int res = socket_receive_timeout((int)(long)connection->data, data, len, 0, timeout);
703 idevice_error_t error = socket_recv_to_idevice_error(res, 0, 0); 704 idevice_error_t error = socket_recv_to_idevice_error(res, 0, 0);
704 if (error == IDEVICE_E_SUCCESS) { 705 if (error == IDEVICE_E_SUCCESS) {
@@ -707,9 +708,9 @@ static idevice_error_t internal_connection_receive_timeout(idevice_connection_t
707 debug_info("ERROR: socket_receive_timeout returned %d (%s)", res, strerror(-res)); 708 debug_info("ERROR: socket_receive_timeout returned %d (%s)", res, strerror(-res));
708 } 709 }
709 return error; 710 return error;
710 } else {
711 debug_info("Unknown connection type %d", connection->type);
712 } 711 }
712
713 debug_info("Unknown connection type %d", connection->type);
713 return IDEVICE_E_UNKNOWN_ERROR; 714 return IDEVICE_E_UNKNOWN_ERROR;
714} 715}
715 716
@@ -793,7 +794,8 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti
793 return IDEVICE_E_UNKNOWN_ERROR; 794 return IDEVICE_E_UNKNOWN_ERROR;
794 } 795 }
795 return IDEVICE_E_SUCCESS; 796 return IDEVICE_E_SUCCESS;
796 } else if (connection->type == CONNECTION_NETWORK) { 797 }
798 if (connection->type == CONNECTION_NETWORK) {
797 int res = socket_receive((int)(long)connection->data, data, len); 799 int res = socket_receive((int)(long)connection->data, data, len);
798 if (res < 0) { 800 if (res < 0) {
799 debug_info("ERROR: socket_receive returned %d (%s)", res, strerror(-res)); 801 debug_info("ERROR: socket_receive returned %d (%s)", res, strerror(-res));
@@ -801,9 +803,9 @@ static idevice_error_t internal_connection_receive(idevice_connection_t connecti
801 } 803 }
802 *recv_bytes = (uint32_t)res; 804 *recv_bytes = (uint32_t)res;
803 return IDEVICE_E_SUCCESS; 805 return IDEVICE_E_SUCCESS;
804 } else {
805 debug_info("Unknown connection type %d", connection->type);
806 } 806 }
807
808 debug_info("Unknown connection type %d", connection->type);
807 return IDEVICE_E_UNKNOWN_ERROR; 809 return IDEVICE_E_UNKNOWN_ERROR;
808} 810}
809 811
@@ -846,17 +848,17 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_get_fd(idevice_connectio
846 return IDEVICE_E_INVALID_ARG; 848 return IDEVICE_E_INVALID_ARG;
847 } 849 }
848 850
849 idevice_error_t result = IDEVICE_E_UNKNOWN_ERROR;
850 if (connection->type == CONNECTION_USBMUXD) { 851 if (connection->type == CONNECTION_USBMUXD) {
851 *fd = (int)(long)connection->data; 852 *fd = (int)(long)connection->data;
852 result = IDEVICE_E_SUCCESS; 853 return IDEVICE_E_SUCCESS;
853 } else if (connection->type == CONNECTION_NETWORK) { 854 }
855 if (connection->type == CONNECTION_NETWORK) {
854 *fd = (int)(long)connection->data; 856 *fd = (int)(long)connection->data;
855 result = IDEVICE_E_SUCCESS; 857 return IDEVICE_E_SUCCESS;
856 } else {
857 debug_info("Unknown connection type %d", connection->type);
858 } 858 }
859 return result; 859
860 debug_info("Unknown connection type %d", connection->type);
861 return IDEVICE_E_UNKNOWN_ERROR;
860} 862}
861 863
862LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle) 864LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle)