diff --git a/aros/iscsi-ls.c b/aros/iscsi-ls.c index 2acbfa0..43cf048 100644 --- a/aros/iscsi-ls.c +++ b/aros/iscsi-ls.c @@ -37,10 +37,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - int showluns; const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-ls"; @@ -318,7 +314,7 @@ int main(int argc, char *argv[]) struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; struct client_state state; - const char *url = NULL; + char *url = NULL; int c; static int show_help = 0, show_usage = 0, debug = 0; @@ -384,9 +380,7 @@ int main(int argc, char *argv[]) iscsi_url = iscsi_parse_portal_url(iscsi, url); - if (url) { - free(discard_const(url)); - } + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/include/iscsi-private.h b/include/iscsi-private.h index 048aa01..3442db6 100644 --- a/include/iscsi-private.h +++ b/include/iscsi-private.h @@ -31,10 +31,6 @@ extern "C" { #endif -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - #ifndef MIN #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif diff --git a/include/iscsi.h b/include/iscsi.h index da3fb76..35960a0 100644 --- a/include/iscsi.h +++ b/include/iscsi.h @@ -549,12 +549,12 @@ EXTERN int iscsi_logout_sync(struct iscsi_context *iscsi); struct iscsi_target_portal { struct iscsi_target_portal *next; - const char *portal; + char *portal; }; struct iscsi_discovery_address { struct iscsi_discovery_address *next; - const char *target_name; + char *target_name; struct iscsi_target_portal *portals; }; diff --git a/lib/discovery.c b/lib/discovery.c index afaec56..0bf4d59 100644 --- a/lib/discovery.c +++ b/lib/discovery.c @@ -89,14 +89,14 @@ iscsi_free_discovery_addresses(struct iscsi_context *iscsi, struct iscsi_discove while (addresses != NULL) { struct iscsi_discovery_address *next = addresses->next; - iscsi_free(iscsi, discard_const(addresses->target_name)); + iscsi_free(iscsi, addresses->target_name); addresses->target_name = NULL; while (addresses->portals != NULL) { struct iscsi_target_portal *next_portal = addresses->portals->next; - iscsi_free(iscsi, discard_const(addresses->portals->portal)); - iscsi_free(iscsi, discard_const(addresses->portals)); + iscsi_free(iscsi, addresses->portals->portal); + iscsi_free(iscsi, addresses->portals); addresses->portals = next_portal; } diff --git a/lib/sync.c b/lib/sync.c index 8bd3369..e46a206 100644 --- a/lib/sync.c +++ b/lib/sync.c @@ -1828,11 +1828,12 @@ void iscsi_free_discovery_data(struct iscsi_context *iscsi _U_, while (da->portals) { struct iscsi_target_portal *ponext = da->portals->next; - free(discard_const(da->portals->portal)); + + free(da->portals->portal); free(da->portals); da->portals = ponext; } - free(discard_const(da->target_name)); + free(da->target_name); free(da); da = danext; } diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 2e92335..0d4c9c1 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -298,10 +298,8 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi if (sdev->iscsi_url) { time_t current_time = time(NULL); - if (sdev->error_str != NULL) { - free(discard_const(sdev->error_str)); - sdev->error_str = NULL; - } + free(sdev->error_str); + sdev->error_str = NULL; task = iscsi_scsi_command_sync(sdev->iscsi_ctx, sdev->iscsi_lun, task, NULL); if (task == NULL) { sdev->error_str = strdup(iscsi_get_error(sdev->iscsi_ctx)); @@ -372,9 +370,7 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi if(ioctl(sdev->sgio_fd, SG_IO, &io_hdr) < 0){ int err = errno; - if (sdev->error_str != NULL) { - free(discard_const(sdev->error_str)); - } + free(sdev->error_str); if (asprintf(&sdev->error_str, "SG_IO ioctl failed: %s", strerror(err)) < 0) sdev->error_str = NULL; @@ -401,18 +397,14 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi task->sense.key, scsi_sense_ascq_str(task->sense.ascq), task->sense.ascq); - if (sdev->error_str != NULL) { - free(discard_const(sdev->error_str)); - } + free(sdev->error_str); sdev->error_str = strdup(buf); return task; } if(io_hdr.status == SCSI_STATUS_RESERVATION_CONFLICT){ task->status = SCSI_STATUS_RESERVATION_CONFLICT; - if (sdev->error_str != NULL) { - free(discard_const(sdev->error_str)); - } + free(sdev->error_str); sdev->error_str = strdup("Reservation Conflict"); return task; } @@ -422,9 +414,7 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi task->sense.key = 0x0f; task->sense.ascq = 0xffff; - if (sdev->error_str != NULL) { - free(discard_const(sdev->error_str)); - } + free(sdev->error_str); sdev->error_str = strdup("SCSI masked error"); return NULL; } @@ -434,9 +424,7 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi task->sense.ascq = 0xffff; snprintf(buf, sizeof(buf), "SCSI host error. Status=0x%x", io_hdr.host_status); - if (sdev->error_str != NULL) { - free(discard_const(sdev->error_str)); - } + free(sdev->error_str); sdev->error_str = strdup(buf); return task; } @@ -445,9 +433,7 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi task->sense.key = 0x0f; task->sense.ascq = 0xffff; - if (sdev->error_str != NULL) { - free(discard_const(sdev->error_str)); - } + free(sdev->error_str); sdev->error_str = strdup("SCSI driver error"); return NULL; } diff --git a/test-tool/iscsi-support.h b/test-tool/iscsi-support.h index 9c3a461..7b9c4de 100644 --- a/test-tool/iscsi-support.h +++ b/test-tool/iscsi-support.h @@ -30,10 +30,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - extern const char *initiatorname1; extern const char *initiatorname2; diff --git a/tests/prog_header_digest.c b/tests/prog_header_digest.c index 495fe37..9668654 100644 --- a/tests/prog_header_digest.c +++ b/tests/prog_header_digest.c @@ -37,10 +37,6 @@ #include "iscsi-private.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-header-digest"; struct client_state { @@ -136,7 +132,7 @@ int main(int argc, char *argv[]) struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; struct client_state state; - const char *url = NULL; + char *url = NULL; int c; static int show_help = 0, show_usage = 0, debug = 0; @@ -210,10 +206,8 @@ int main(int argc, char *argv[]) } iscsi_url = iscsi_parse_full_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/tests/prog_noop_reply.c b/tests/prog_noop_reply.c index 0e0566e..f6a2d2c 100644 --- a/tests/prog_noop_reply.c +++ b/tests/prog_noop_reply.c @@ -37,10 +37,6 @@ #include "iscsi-private.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-noop-reply"; struct client_state { @@ -136,7 +132,7 @@ int main(int argc, char *argv[]) struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; struct client_state state; - const char *url = NULL; + char *url = NULL; int c; static int show_help = 0, show_usage = 0, debug = 0; @@ -210,10 +206,8 @@ int main(int argc, char *argv[]) } iscsi_url = iscsi_parse_full_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/tests/prog_read_all_pdus.c b/tests/prog_read_all_pdus.c index e56c771..0f4d19a 100644 --- a/tests/prog_read_all_pdus.c +++ b/tests/prog_read_all_pdus.c @@ -34,10 +34,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-readwrite-iov"; void print_usage(void) @@ -84,7 +80,7 @@ int main(int argc, char *argv[]) { struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; - const char *url = NULL; + char *url = NULL; static int show_help = 0, show_usage = 0, debug = 0; int c, i, count; @@ -156,10 +152,8 @@ int main(int argc, char *argv[]) } iscsi_url = iscsi_parse_full_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/tests/prog_readwrite_iov.c b/tests/prog_readwrite_iov.c index 7d46e05..164d5f2 100644 --- a/tests/prog_readwrite_iov.c +++ b/tests/prog_readwrite_iov.c @@ -34,10 +34,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-readwrite-iov"; void print_usage(void) @@ -75,7 +71,7 @@ int main(int argc, char *argv[]) { struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; - const char *url = NULL; + char *url = NULL; static int show_help = 0, show_usage = 0, debug = 0; struct scsi_task *task; struct scsi_iovec iov[4]; @@ -152,10 +148,8 @@ int main(int argc, char *argv[]) } iscsi_url = iscsi_parse_full_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/tests/prog_reconnect.c b/tests/prog_reconnect.c index 5d3a426..9012cca 100644 --- a/tests/prog_reconnect.c +++ b/tests/prog_reconnect.c @@ -34,10 +34,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-reconnect"; struct client_state { @@ -194,7 +190,7 @@ int main(int argc, char *argv[]) struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; struct client_state state; - const char *url = NULL; + char *url = NULL; int i, c; static int show_help = 0, show_usage = 0, debug = 0; struct scsi_readcapacity10 *rc10; @@ -270,10 +266,8 @@ int main(int argc, char *argv[]) } iscsi_url = iscsi_parse_full_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/tests/prog_reconnect_timeout.c b/tests/prog_reconnect_timeout.c index 542dc67..3693af9 100644 --- a/tests/prog_reconnect_timeout.c +++ b/tests/prog_reconnect_timeout.c @@ -34,10 +34,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-reconnect-timeout"; struct client_state { @@ -217,7 +213,7 @@ int main(int argc, char *argv[]) struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; struct client_state state; - const char *url = NULL; + char *url = NULL; int i, c; static int show_help = 0, show_usage = 0, debug = 0; struct scsi_readcapacity10 *rc10; @@ -293,10 +289,8 @@ int main(int argc, char *argv[]) } iscsi_url = iscsi_parse_full_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/tests/prog_timeout.c b/tests/prog_timeout.c index bbe0c67..f6b8824 100644 --- a/tests/prog_timeout.c +++ b/tests/prog_timeout.c @@ -38,10 +38,6 @@ #include "iscsi-private.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:prog-timeout"; void print_usage(void) @@ -108,7 +104,7 @@ int main(int argc, char *argv[]) { struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; - const char *url = NULL; + char *url = NULL; int c; static int show_help = 0, show_usage = 0, debug = 0; uint32_t count; @@ -182,9 +178,7 @@ int main(int argc, char *argv[]) iscsi_url = iscsi_parse_full_url(iscsi, url); - if (url) { - free(discard_const(url)); - } + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/utils/iscsi-inq.c b/utils/iscsi-inq.c index cdc4535..24016fd 100644 --- a/utils/iscsi-inq.c +++ b/utils/iscsi-inq.c @@ -31,10 +31,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-inq"; void inquiry_block_limits(struct scsi_inquiry_block_limits *inq) @@ -236,7 +232,7 @@ void print_help(void) int main(int argc, char *argv[]) { struct iscsi_context *iscsi; - const char *url = NULL; + char *url = NULL; struct iscsi_url *iscsi_url = NULL; int evpd = 0, pagecode = 0; int show_help = 0, show_usage = 0, debug = 0; @@ -312,10 +308,8 @@ int main(int argc, char *argv[]) exit(10); } iscsi_url = iscsi_parse_full_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/utils/iscsi-ls.c b/utils/iscsi-ls.c index 698318b..886624f 100644 --- a/utils/iscsi-ls.c +++ b/utils/iscsi-ls.c @@ -40,10 +40,6 @@ WSADATA wsaData; #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - int showluns; int useurls; const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-ls"; @@ -349,7 +345,7 @@ int main(int argc, char *argv[]) struct iscsi_context *iscsi; struct iscsi_url *iscsi_url = NULL; struct client_state state; - const char *url = NULL; + char *url = NULL; int i; static int show_help = 0, show_usage = 0, debug = 0; @@ -418,10 +414,8 @@ int main(int argc, char *argv[]) } iscsi_url = iscsi_parse_portal_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/utils/iscsi-readcapacity16.c b/utils/iscsi-readcapacity16.c index 48c6d00..c417b9c 100644 --- a/utils/iscsi-readcapacity16.c +++ b/utils/iscsi-readcapacity16.c @@ -26,10 +26,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-readcapacity16"; void print_usage(void) @@ -59,7 +55,7 @@ void print_help(void) int main(int argc, char *argv[]) { struct iscsi_context *iscsi; - const char *url = NULL; + char *url = NULL; struct iscsi_url *iscsi_url = NULL; int show_help = 0, show_usage = 0, debug = 0, size_only=0; int c; @@ -134,10 +130,8 @@ int main(int argc, char *argv[]) exit(10); } iscsi_url = iscsi_parse_full_url(iscsi, url); - - if (url) { - free(discard_const(url)); - } + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n", diff --git a/utils/iscsi-swp.c b/utils/iscsi-swp.c index c67d4c3..af07c81 100644 --- a/utils/iscsi-swp.c +++ b/utils/iscsi-swp.c @@ -30,10 +30,6 @@ #include "iscsi.h" #include "scsi-lowlevel.h" -#ifndef discard_const -#define discard_const(ptr) ((void *)((intptr_t)(ptr))) -#endif - const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-swp"; @@ -65,7 +61,7 @@ void print_help(void) int main(int argc, char *argv[]) { struct iscsi_context *iscsi; - const char *url = NULL; + char *url = NULL; struct iscsi_url *iscsi_url = NULL; int show_help = 0, show_usage = 0, debug = 0; int c; @@ -148,8 +144,8 @@ int main(int argc, char *argv[]) goto finished; } iscsi_url = iscsi_parse_full_url(iscsi, url); - - free(discard_const(url)); + + free(url); if (iscsi_url == NULL) { fprintf(stderr, "Failed to parse URL: %s\n",