[libnbd PATCH] maint: pick consistent spacing style for casts
We are inconsistent on whether a cast operator should be separated from its argument by a space. As a unary prefix operator, casts bind with relatively tight precedence, where only postfix operations (including function calls) come higher. We generally don't use a space after other prefix operators (*, &, ~, and unary - tend to not be followed by space; we are less consistent on !, but that would be a separate patch). Furthermore, we've already decided (in commit b5101fbc) that we prefer spaces before function invocations. At the time, discussion on the list[1] pointed out that thanks to the complexity of C with its context-sensitive parsing needing to know whether an identifier is a type name, you would be able to tell the difference between a 2-argument function call with two parameters through a function pointer (or intentional function-like macro suppression): (foo) (bar, baz) from the (admittedly rare) application of a cast operator to the results of a comma operator: (foo)(bar, baz) if we consistently avoid spaces after casts. Determining cast operators is not always trivial, but the regex used below seems to have a pretty low false positive rate (lines it selects usually are casts and not in a comment line), and can be modified by removing the space to see where we already had casts without a space. (Obviously, I can't tell how many false negatives there are of casts I missed out on). While this changes more lines than would be done by instead always using a space in a cast, it is still manageable to do a bulk change. $ git grep '\(_t\|int\|long\|signed\|char\|\*\)) [a-zA-Z0-9&"]' -- \ '**/*.[hc]' '**/*.ml' | grep -v '^ */\?\*' 'git show -w' shows that this change is whitespace only. [1] https://listman.redhat.com/archives/libguestfs/2023-February/030771.html Signed-off-by: Eric Blake <eblake@redhat.com> --- configure.ac | 6 ++-- common/utils/vector.h | 4 +-- generator/OCaml.ml | 4 +-- generator/Python.ml | 4 +-- generator/states-connect-socket-activation.c | 4 +-- generator/states-connect.c | 2 +- generator/states-issue-command.c | 2 +- generator/states-newstyle.c | 2 +- generator/states-oldstyle.c | 2 +- generator/states-reply-structured.c | 14 ++++---- generator/states-reply.c | 2 +- generator/states.c | 4 +-- lib/crypto.c | 6 ++-- lib/rw.c | 2 +- lib/uri.c | 10 +++--- lib/utils.c | 4 +-- common/utils/test-vector.c | 4 +-- python/handle.c | 4 +-- python/utils.c | 2 +- ocaml/nbd-c.h | 6 ++-- tests/aio-connect-port.c | 2 +- tests/aio-connect.c | 2 +- tests/errors-bad-cookie.c | 2 +- tests/errors-client-oversize.c | 2 +- tests/errors-client-unadvertised-cmd.c | 2 +- tests/errors-client-unaligned.c | 2 +- tests/errors-client-unknown-flags.c | 2 +- tests/errors-client-zerosize.c | 2 +- tests/errors-connect-null.c | 2 +- tests/errors-connect-twice.c | 4 +-- tests/errors-multiple-disconnects.c | 2 +- tests/errors-not-negotiating.c | 2 +- tests/errors-notify-not-blocked.c | 2 +- tests/errors-pread-structured.c | 2 +- tests/errors-server-invalid-offset.c | 2 +- tests/errors-server-oversize.c | 2 +- tests/errors-server-unadvertised-cmd.c | 2 +- tests/errors-server-unaligned.c | 2 +- tests/errors-server-unknown-flags.c | 2 +- tests/errors-server-zerosize.c | 2 +- tests/opt-set-meta.c | 2 +- tests/opt-starttls.c | 4 +-- tests/opt-structured-twice.c | 2 +- tests/pread-initialize.c | 2 +- tests/private-data.c | 4 +-- tests/server-death.c | 2 +- tests/shutdown-flags.c | 2 +- examples/glib-main-loop.c | 36 ++++++++++---------- examples/open-qcow2.c | 2 +- interop/list-exports.c | 2 +- copy/file-ops.c | 6 ++-- copy/main.c | 10 +++--- copy/nbd-ops.c | 36 ++++++++++---------- copy/pipe-ops.c | 8 ++--- dump/dump.c | 2 +- fuse/nbdfuse.c | 8 ++--- fuse/operations.c | 10 +++--- ublk/nbdublk.c | 4 +-- ublk/tgt.c | 4 +-- 59 files changed, 138 insertions(+), 138 deletions(-) diff --git a/configure.ac b/configure.ac index 30348ea9..0a9e4d79 100644 --- a/configure.ac +++ b/configure.ac @@ -456,7 +456,7 @@ AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \ AC_MSG_CHECKING([for caml_alloc_custom_mem]) cat >conftest.c <<'EOF' #include <caml/custom.h> -int main () { char *p = (void *) caml_alloc_custom_mem; return 0; } +int main () { char *p = (void *)caml_alloc_custom_mem; return 0; } EOF AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[ AC_MSG_RESULT([yes]) @@ -474,7 +474,7 @@ AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \ AC_MSG_CHECKING([for caml_alloc_initialized_string]) cat >conftest.c <<'EOF' #include <caml/alloc.h> -int main () { char *p = (void *) caml_alloc_initialized_string; return 0; } +int main () { char *p = (void *)caml_alloc_initialized_string; return 0; } EOF AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[ AC_MSG_RESULT([yes]) @@ -492,7 +492,7 @@ AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \ AC_MSG_CHECKING([for caml_unix_get_sockaddr]) cat >conftest.c <<'EOF' #include <caml/socketaddr.h> -int main () { char *p = (void *) caml_unix_get_sockaddr; return 0; } +int main () { char *p = (void *)caml_unix_get_sockaddr; return 0; } EOF AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[ AC_MSG_RESULT([yes]) diff --git a/common/utils/vector.h b/common/utils/vector.h index 7337d268..50cad1d0 100644 --- a/common/utils/vector.h +++ b/common/utils/vector.h @@ -173,7 +173,7 @@ name##_sort (name *v, \ int (*compare) (const type *p1, const type *p2)) \ { \ - qsort (v->ptr, v->len, sizeof (type), (void *) compare); \ + qsort (v->ptr, v->len, sizeof (type), (void *)compare); \ } \ \ /* Search for an exactly matching element in the vector using a \ @@ -184,7 +184,7 @@ int (*compare) (const void *key, const type *v)) \ { \ return bsearch (key, v->ptr, v->len, sizeof (type), \ - (void *) compare); \ + (void *)compare); \ } \ \ /* Make a new vector with the same elements. */ \ diff --git a/generator/OCaml.ml b/generator/OCaml.ml index 300c8a70..edb81f25 100644 --- a/generator/OCaml.ml +++ b/generator/OCaml.ml @@ -710,12 +710,12 @@ let pr " size_t %s = Int_val (%sv);\n" n n | SockAddrAndLen (n, len) -> pr " struct sockaddr_storage %s_storage;\n" n; - pr " struct sockaddr *%s = (struct sockaddr *) &%s_storage;\n" n n; + pr " struct sockaddr *%s = (struct sockaddr *)&%s_storage;\n" n n; pr " socklen_t %s;\n" len; pr " nbd_internal_unix_sockaddr_to_sa (%sv, &%s_storage, &%s);\n" n n len | StringList n -> - pr " char **%s = (char **) nbd_internal_ocaml_string_list (%sv);\n" n n + pr " char **%s = (char **)nbd_internal_ocaml_string_list (%sv);\n" n n | UInt n | UIntPtr n -> pr " unsigned %s = Int_val (%sv);\n" n n | UInt32 n -> diff --git a/generator/Python.ml b/generator/Python.ml index c146f04f..b73f9782 100644 --- a/generator/Python.ml +++ b/generator/Python.ml @@ -49,7 +49,7 @@ let { assert (obj); assert (obj != Py_None); - return (struct nbd_handle *) PyCapsule_GetPointer(obj, \"nbd_handle\"); + return (struct nbd_handle *)PyCapsule_GetPointer(obj, \"nbd_handle\"); } /* nbd.Error exception. */ @@ -370,7 +370,7 @@ let | SizeT n -> "n", sprintf "&%s" n, sprintf "(size_t)%s" n | SockAddrAndLen (n, _) -> "O", sprintf "&%s" n, - sprintf "(struct sockaddr *) &%s_sa, %s_len" n n + sprintf "(struct sockaddr *)&%s_sa, %s_len" n n | String n -> "s", sprintf "&%s" n, n | StringList n -> "O", sprintf "&py_%s" n, n | UInt n | UIntPtr n -> "I", sprintf "&%s" n, n diff --git a/generator/states-connect-socket-activation.c b/generator/states-connect-socket-activation.c index b57d5d00..98a39c0e 100644 --- a/generator/states-connect-socket-activation.c +++ b/generator/states-connect-socket-activation.c @@ -224,7 +224,7 @@ CONNECT_SA.START: addr.sun_family = AF_UNIX; memcpy (addr.sun_path, sockpath, strlen (sockpath) + 1); - if (bind (s, (struct sockaddr *) &addr, sizeof addr) == -1) { + if (bind (s, (struct sockaddr *)&addr, sizeof addr) == -1) { set_error (errno, "bind: %s", sockpath); goto close_socket; } @@ -294,7 +294,7 @@ CONNECT_SA.START: char buf[32]; const char *v = - nbd_internal_fork_safe_itoa ((long) getpid (), buf, sizeof buf); + nbd_internal_fork_safe_itoa ((long)getpid (), buf, sizeof buf); NBD_INTERNAL_FORK_SAFE_ASSERT (strlen (v) <= sact_var[pid_ofs].value_len); strcpy (env.ptr[pid_ofs] + sact_var[pid_ofs].prefix_len, v); diff --git a/generator/states-connect.c b/generator/states-connect.c index 65a68003..98d9f945 100644 --- a/generator/states-connect.c +++ b/generator/states-connect.c @@ -84,7 +84,7 @@ CONNECT.START: disable_nagle (fd); disable_sigpipe (fd); - r = connect (fd, (struct sockaddr *) &h->connaddr, h->connaddrlen); + r = connect (fd, (struct sockaddr *)&h->connaddr, h->connaddrlen); if (r == 0 || (r == -1 && errno == EINPROGRESS)) return 0; assert (r == -1); diff --git a/generator/states-issue-command.c b/generator/states-issue-command.c index a1458c6d..34ef4652 100644 --- a/generator/states-issue-command.c +++ b/generator/states-issue-command.c @@ -46,7 +46,7 @@ ISSUE_COMMAND.START: h->request.type = htobe16 (cmd->type); h->request.handle = htobe64 (cmd->cookie); h->request.offset = htobe64 (cmd->offset); - h->request.count = htobe32 ((uint32_t) cmd->count); + h->request.count = htobe32 ((uint32_t)cmd->count); h->chunks_sent++; h->wbuf = &h->request; h->wlen = sizeof (h->request); diff --git a/generator/states-newstyle.c b/generator/states-newstyle.c index 3bd17c33..ad5bbf72 100644 --- a/generator/states-newstyle.c +++ b/generator/states-newstyle.c @@ -102,7 +102,7 @@ handle_reply_error (struct nbd_handle *h) } if (len > 0) - debug (h, "handshake: server error message: %.*s", (int) len, + debug (h, "handshake: server error message: %.*s", (int)len, h->sbuf.or.payload.err_msg); return 0; diff --git a/generator/states-oldstyle.c b/generator/states-oldstyle.c index c9635636..f1be5df0 100644 --- a/generator/states-oldstyle.c +++ b/generator/states-oldstyle.c @@ -25,7 +25,7 @@ OLDSTYLE.START: */ h->rbuf = &h->sbuf.old_handshake; h->rlen = sizeof h->sbuf.old_handshake; - h->rbuf = (char *) h->rbuf + 16; + h->rbuf = (char *)h->rbuf + 16; h->rlen -= 16; SET_NEXT_STATE (%RECV_REMAINING); return 0; diff --git a/generator/states-reply-structured.c b/generator/states-reply-structured.c index 0788fb03..5aca7262 100644 --- a/generator/states-reply-structured.c +++ b/generator/states-reply-structured.c @@ -49,7 +49,7 @@ REPLY.STRUCTURED_REPLY.START: * so read the remaining part. */ h->rbuf = &h->sbuf; - h->rbuf = (char *) h->rbuf + sizeof h->sbuf.simple_reply; + h->rbuf = (char *)h->rbuf + sizeof h->sbuf.simple_reply; h->rlen = sizeof h->sbuf.sr.structured_reply; h->rlen -= sizeof h->sbuf.simple_reply; SET_NEXT_STATE (%RECV_REMAINING); @@ -223,7 +223,7 @@ REPLY.STRUCTURED_REPLY.RECV_ERROR_MESSAGE: length -= sizeof h->sbuf.sr.payload.error.error + msglen; if (msglen) - debug (h, "structured error server message: %.*s", (int) msglen, + debug (h, "structured error server message: %.*s", (int)msglen, h->sbuf.sr.payload.error.msg); /* Special case two specific errors; silently ignore tail for all others */ @@ -286,7 +286,7 @@ REPLY.STRUCTURED_REPLY.RECV_ERROR_TAIL: * without setting errno, then use the server's error below. */ if (CALL_CALLBACK (cmd->cb.fn.chunk, - (char *) cmd->data + (offset - cmd->offset), + (char *)cmd->data + (offset - cmd->offset), 0, offset, LIBNBD_READ_ERROR, &scratch) == -1) if (cmd->error == 0) @@ -337,7 +337,7 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_DATA: offset -= cmd->offset; /* Set up to receive the data directly to the user buffer. */ - h->rbuf = (char *) cmd->data + offset; + h->rbuf = (char *)cmd->data + offset; h->rlen = length; SET_NEXT_STATE (%RECV_OFFSET_DATA_DATA); } @@ -363,7 +363,7 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_DATA_DATA: int error = cmd->error; if (CALL_CALLBACK (cmd->cb.fn.chunk, - (char *) cmd->data + (offset - cmd->offset), + (char *)cmd->data + (offset - cmd->offset), length - sizeof offset, offset, LIBNBD_READ_DATA, &error) == -1) if (cmd->error == 0) @@ -408,12 +408,12 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_HOLE: * them as an extension, and this works even when length == 0. */ if (!cmd->initialized) - memset ((char *) cmd->data + offset, 0, length); + memset ((char *)cmd->data + offset, 0, length); if (CALLBACK_IS_NOT_NULL (cmd->cb.fn.chunk)) { int error = cmd->error; if (CALL_CALLBACK (cmd->cb.fn.chunk, - (char *) cmd->data + offset, length, + (char *)cmd->data + offset, length, cmd->offset + offset, LIBNBD_READ_HOLE, &error) == -1) if (cmd->error == 0) diff --git a/generator/states-reply.c b/generator/states-reply.c index 010d108b..f7888154 100644 --- a/generator/states-reply.c +++ b/generator/states-reply.c @@ -97,7 +97,7 @@ REPLY.START: #endif h->bytes_received += r; - h->rbuf = (char *) h->rbuf + r; + h->rbuf = (char *)h->rbuf + r; h->rlen -= r; SET_NEXT_STATE (%RECV_REPLY); return 0; diff --git a/generator/states.c b/generator/states.c index 836862ea..425fa62f 100644 --- a/generator/states.c +++ b/generator/states.c @@ -91,7 +91,7 @@ recv_into_rbuf (struct nbd_handle *h) #endif h->bytes_received += r; if (h->rbuf) - h->rbuf = (char *) h->rbuf + r; + h->rbuf = (char *)h->rbuf + r; h->rlen -= r; if (h->rlen == 0) return 0; /* move to next state */ @@ -114,7 +114,7 @@ send_from_wbuf (struct nbd_handle *h) return -1; } h->bytes_sent += r; - h->wbuf = (char *) h->wbuf + r; + h->wbuf = (char *)h->wbuf + r; h->wlen -= r; if (h->wlen == 0) goto next_state; diff --git a/lib/crypto.c b/lib/crypto.c index d43eeb4c..22a1cfa5 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -307,7 +307,7 @@ lookup_key (const char *pskfile, const char *username, if (r > ulen+1 && strncmp (line, username, ulen) == 0 && line[ulen] == ':') { - key->data = (unsigned char *) strdup (&line[ulen+1]); + key->data = (unsigned char *)strdup (&line[ulen+1]); if (key->data == NULL) { set_error (errno, "strdup"); goto error; @@ -712,7 +712,7 @@ nbd_internal_crypto_handshake (struct nbd_handle *h) in = gnutls_handshake_get_last_in (session); out = gnutls_handshake_get_last_out (session); set_error (0, "gnutls_handshake: %s (%d/%d)", - gnutls_strerror (err), (int) in, (int) out); + gnutls_strerror (err), (int)in, (int)out); return -1; } @@ -742,7 +742,7 @@ nbd_internal_crypto_debug_tls_enabled (struct nbd_handle *h) case GNUTLS_KTLS_SEND: ktls_status = "enabled send only"; break; case GNUTLS_KTLS_DUPLEX: ktls_status = "enabled"; break; default: - if ((int) ktls_enabled == 0) + if ((int)ktls_enabled == 0) ktls_status = "disabled"; else ktls_status = "unknown"; diff --git a/lib/rw.c b/lib/rw.c index a8d9e66c..3dc3499e 100644 --- a/lib/rw.c +++ b/lib/rw.c @@ -361,7 +361,7 @@ nbd_unlocked_aio_pwrite (struct nbd_handle *h, const void *buf, SET_CALLBACK_TO_NULL (*completion); return nbd_internal_command_common (h, flags, NBD_CMD_WRITE, offset, count, - ENOSPC, (void *) buf, &cb); + ENOSPC, (void *)buf, &cb); } int64_t diff --git a/lib/uri.c b/lib/uri.c index f9fde455..0c8e87cf 100644 --- a/lib/uri.c +++ b/lib/uri.c @@ -376,7 +376,7 @@ nbd_unlocked_aio_connect_uri (struct nbd_handle *h, const char *raw_uri) * uri->port > 0. This prevents us from using certain very large * port numbers, but that's not an issue that matters in practice. */ - svm_port = uri->port > 0 ? (uint32_t) uri->port : 10809; + svm_port = uri->port > 0 ? (uint32_t)uri->port : 10809; if (nbd_unlocked_aio_connect_vsock (h, cid, svm_port) == -1) goto cleanup; @@ -451,7 +451,7 @@ nbd_unlocked_get_uri (struct nbd_handle *h) char serv[NI_MAXSERV]; uri.scheme = using_tls ? "nbds" : "nbd"; - err = getnameinfo ((struct sockaddr *) &h->connaddr, h->connaddrlen, + err = getnameinfo ((struct sockaddr *)&h->connaddr, h->connaddrlen, host, sizeof host, serv, sizeof serv, NI_NUMERICHOST | NI_NUMERICSERV); if (err != 0) { @@ -471,7 +471,7 @@ nbd_unlocked_get_uri (struct nbd_handle *h) } case AF_UNIX: { - struct sockaddr_un *sun = (struct sockaddr_un *) &h->connaddr; + struct sockaddr_un *sun = (struct sockaddr_un *)&h->connaddr; if (sun->sun_path[0] == '\0') { /* Unix domain sockets in the abstract namespace are in theory @@ -495,7 +495,7 @@ nbd_unlocked_get_uri (struct nbd_handle *h) #if HAVE_STRUCT_SOCKADDR_VM case AF_VSOCK: { - struct sockaddr_vm *svm = (struct sockaddr_vm *) &h->connaddr; + struct sockaddr_vm *svm = (struct sockaddr_vm *)&h->connaddr; uri.scheme = using_tls ? "nbds+vsock" : "nbd+vsock"; if (asprintf (&server, "%u:%u", svm->svm_cid, svm->svm_port) == -1) { @@ -543,7 +543,7 @@ nbd_unlocked_get_uri (struct nbd_handle *h) uri.query_raw = query_params; /* Construct the final URI and return it. */ - ret = (char *) xmlSaveUri (&uri); + ret = (char *)xmlSaveUri (&uri); if (ret == NULL) set_error (errno, "xmlSaveUri failed"); out: diff --git a/lib/utils.c b/lib/utils.c index bce38df8..e3e13cdd 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -154,7 +154,7 @@ nbd_internal_set_querylist (struct nbd_handle *h, char **queries) const char * nbd_internal_fork_safe_itoa (long v, char *buf, size_t bufsize) { - unsigned long uv = (unsigned long) v; + unsigned long uv = (unsigned long)v; size_t i = bufsize - 1; bool neg = false; @@ -282,7 +282,7 @@ nbd_internal_fork_safe_perror (const char *s) #endif #endif if (!m) - m = nbd_internal_fork_safe_itoa ((long) errno, buf, sizeof buf); + m = nbd_internal_fork_safe_itoa ((long)errno, buf, sizeof buf); xwritel (STDERR_FILENO, s, ": ", m, "\n", (char *)NULL); /* Restore original errno in case it was disturbed by the system diff --git a/common/utils/test-vector.c b/common/utils/test-vector.c index 26ad5136..399f4f26 100644 --- a/common/utils/test-vector.c +++ b/common/utils/test-vector.c @@ -82,10 +82,10 @@ test_int64_vector (void) assert (v.ptr[1] == 2); tmp = 10; - p = int64_vector_search (&v, &tmp, (void*) compare); + p = int64_vector_search (&v, &tmp, (void *)compare); assert (p == NULL); tmp = 8; - p = int64_vector_search (&v, &tmp, (void*) compare); + p = int64_vector_search (&v, &tmp, (void *)compare); assert (p == &v.ptr[7]); free (v.ptr); diff --git a/python/handle.c b/python/handle.c index 2b04cdcd..8ff6ba81 100644 --- a/python/handle.c +++ b/python/handle.c @@ -46,7 +46,7 @@ static inline PyObject * put_handle (struct nbd_handle *h) { assert (h); - return PyCapsule_New ((void *) h, "nbd_handle", NULL); + return PyCapsule_New ((void *)h, "nbd_handle", NULL); } PyObject * @@ -188,7 +188,7 @@ nbd_internal_py_aio_buffer_is_zero (PyObject *self, PyObject *args) "except -1 to mean to the end of the buffer"); goto out; } - else if ((size_t) offset + size > buf.len) { + else if ((size_t)offset + size > buf.len) { PyErr_SetString (PyExc_IndexError, "size out of range"); goto out; } diff --git a/python/utils.c b/python/utils.c index 27242f25..bf62f411 100644 --- a/python/utils.c +++ b/python/utils.c @@ -53,7 +53,7 @@ nbd_internal_py_get_string_list (PyObject *obj) "get_string_list: PyList_Size failure"); return NULL; } - len = (size_t) slen; + len = (size_t)slen; r = malloc (sizeof (char *) * (len+1)); if (r == NULL) { PyErr_NoMemory (); diff --git a/ocaml/nbd-c.h b/ocaml/nbd-c.h index f853c84a..0cbe36d1 100644 --- a/ocaml/nbd-c.h +++ b/ocaml/nbd-c.h @@ -49,7 +49,7 @@ static inline value caml_alloc_initialized_string (mlsize_t len, const char *p) { value sv = caml_alloc_string (len); - memcpy ((char *) String_val (sv), p, len); + memcpy ((char *)String_val (sv), p, len); return sv; } #endif @@ -70,7 +70,7 @@ extern void nbd_internal_ocaml_exception_in_wrapper (const char *, value); #define NBD_val(v) (*((struct nbd_handle **)Data_custom_val (v))) static struct custom_operations libnbd_custom_operations = { - (char *) "libnbd_custom_operations", + (char *)"libnbd_custom_operations", nbd_internal_ocaml_handle_finalize, custom_compare_default, custom_hash_default, @@ -110,7 +110,7 @@ struct nbd_buffer { #define NBD_buffer_val(v) ((struct nbd_buffer *)Data_custom_val (v)) static struct custom_operations nbd_buffer_custom_operations = { - (char *) "nbd_buffer_custom_operations", + (char *)"nbd_buffer_custom_operations", nbd_internal_ocaml_buffer_finalize, custom_compare_default, custom_hash_default, diff --git a/tests/aio-connect-port.c b/tests/aio-connect-port.c index 05d33191..70138a80 100644 --- a/tests/aio-connect-port.c +++ b/tests/aio-connect-port.c @@ -87,7 +87,7 @@ main (int argc, char *argv[]) addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); addr.sin_port = htons (port); - if (nbd_aio_connect (nbd, (struct sockaddr *) &addr, sizeof addr) == -1) { + if (nbd_aio_connect (nbd, (struct sockaddr *)&addr, sizeof addr) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/aio-connect.c b/tests/aio-connect.c index 1601ed0b..aac82179 100644 --- a/tests/aio-connect.c +++ b/tests/aio-connect.c @@ -85,7 +85,7 @@ main (int argc, char *argv[]) addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); addr.sin_port = htons (port); - if (nbd_aio_connect (nbd, (struct sockaddr *) &addr, sizeof addr) == -1) { + if (nbd_aio_connect (nbd, (struct sockaddr *)&addr, sizeof addr) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-bad-cookie.c b/tests/errors-bad-cookie.c index c3de8c15..44479bdb 100644 --- a/tests/errors-bad-cookie.c +++ b/tests/errors-bad-cookie.c @@ -69,7 +69,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-oversize.c b/tests/errors-client-oversize.c index 8f0c039c..db701687 100644 --- a/tests/errors-client-oversize.c +++ b/tests/errors-client-oversize.c @@ -80,7 +80,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-unadvertised-cmd.c b/tests/errors-client-unadvertised-cmd.c index cd5a3e15..9dcd5766 100644 --- a/tests/errors-client-unadvertised-cmd.c +++ b/tests/errors-client-unadvertised-cmd.c @@ -80,7 +80,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-unaligned.c b/tests/errors-client-unaligned.c index ec996b71..e7c62fe8 100644 --- a/tests/errors-client-unaligned.c +++ b/tests/errors-client-unaligned.c @@ -80,7 +80,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-unknown-flags.c b/tests/errors-client-unknown-flags.c index 9d41de26..3399bbfd 100644 --- a/tests/errors-client-unknown-flags.c +++ b/tests/errors-client-unknown-flags.c @@ -73,7 +73,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-zerosize.c b/tests/errors-client-zerosize.c index 3ed170a7..69026324 100644 --- a/tests/errors-client-zerosize.c +++ b/tests/errors-client-zerosize.c @@ -73,7 +73,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-connect-null.c b/tests/errors-connect-null.c index e2542ff3..46114d0b 100644 --- a/tests/errors-connect-null.c +++ b/tests/errors-connect-null.c @@ -79,7 +79,7 @@ main (int argc, char *argv[]) } check (EFAULT, "nbd_connect_command: "); - if (nbd_connect_command (nbd, (char **) cmd) != -1) { + if (nbd_connect_command (nbd, (char **)cmd) != -1) { fprintf (stderr, "%s: test failed: " "nbd_connect_command did not reject empty argv\n", argv[0]); diff --git a/tests/errors-connect-twice.c b/tests/errors-connect-twice.c index 496fb521..f8053fc9 100644 --- a/tests/errors-connect-twice.c +++ b/tests/errors-connect-twice.c @@ -69,11 +69,11 @@ main (int argc, char *argv[]) } /* Connect to a working server, then try to connect again. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } - if (nbd_connect_command (nbd, (char **) cmd) != -1) { + if (nbd_connect_command (nbd, (char **)cmd) != -1) { fprintf (stderr, "%s: test failed: " "nbd_connect_command did not reject repeat attempt\n", argv[0]); diff --git a/tests/errors-multiple-disconnects.c b/tests/errors-multiple-disconnects.c index 13f30139..25309867 100644 --- a/tests/errors-multiple-disconnects.c +++ b/tests/errors-multiple-disconnects.c @@ -133,7 +133,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-not-negotiating.c b/tests/errors-not-negotiating.c index 2eed4181..7609de56 100644 --- a/tests/errors-not-negotiating.c +++ b/tests/errors-not-negotiating.c @@ -69,7 +69,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-notify-not-blocked.c b/tests/errors-notify-not-blocked.c index 93903946..306540b5 100644 --- a/tests/errors-notify-not-blocked.c +++ b/tests/errors-notify-not-blocked.c @@ -69,7 +69,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-pread-structured.c b/tests/errors-pread-structured.c index 946b14be..654d7b6d 100644 --- a/tests/errors-pread-structured.c +++ b/tests/errors-pread-structured.c @@ -95,7 +95,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-invalid-offset.c b/tests/errors-server-invalid-offset.c index 8ce7c814..dba1a7ff 100644 --- a/tests/errors-server-invalid-offset.c +++ b/tests/errors-server-invalid-offset.c @@ -101,7 +101,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-oversize.c b/tests/errors-server-oversize.c index 627d824b..c773ce29 100644 --- a/tests/errors-server-oversize.c +++ b/tests/errors-server-oversize.c @@ -117,7 +117,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-unadvertised-cmd.c b/tests/errors-server-unadvertised-cmd.c index d63043a1..44c266ac 100644 --- a/tests/errors-server-unadvertised-cmd.c +++ b/tests/errors-server-unadvertised-cmd.c @@ -108,7 +108,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-unaligned.c b/tests/errors-server-unaligned.c index a488570d..74cffaea 100644 --- a/tests/errors-server-unaligned.c +++ b/tests/errors-server-unaligned.c @@ -109,7 +109,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-unknown-flags.c b/tests/errors-server-unknown-flags.c index 38e1c080..d4946822 100644 --- a/tests/errors-server-unknown-flags.c +++ b/tests/errors-server-unknown-flags.c @@ -101,7 +101,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-zerosize.c b/tests/errors-server-zerosize.c index 295e0b58..6011bbef 100644 --- a/tests/errors-server-zerosize.c +++ b/tests/errors-server-zerosize.c @@ -101,7 +101,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/opt-set-meta.c b/tests/opt-set-meta.c index 7f4656b9..1bd60a9c 100644 --- a/tests/opt-set-meta.c +++ b/tests/opt-set-meta.c @@ -219,7 +219,7 @@ main (int argc, char *argv[]) * or newer with its --no-sr kill switch. */ requires ("nbdkit --no-sr --help"); - args[ARRAY_SIZE (args) - 2] = (char *) "--no-sr"; + args[ARRAY_SIZE (args) - 2] = (char *)"--no-sr"; nbd = nbd_create (); if (nbd == NULL || nbd_set_opt_mode (nbd, true) == -1 || diff --git a/tests/opt-starttls.c b/tests/opt-starttls.c index 35668f17..ce966d81 100644 --- a/tests/opt-starttls.c +++ b/tests/opt-starttls.c @@ -97,7 +97,7 @@ do_test (const char *server_tls, struct expected exp) "--filter=tls-fallback", "pattern", "size=1M", "tlsreadme=fallback", NULL }; - if (nbd_connect_command (nbd, (char **) args) == -1) { + if (nbd_connect_command (nbd, (char **)args) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } @@ -163,7 +163,7 @@ main (int argc, char *argv[]) exit (77); } if (nbd_set_opt_mode (nbd, true) == -1 || - nbd_connect_command (nbd, (char **) args) == -1 || + nbd_connect_command (nbd, (char **)args) == -1 || nbd_opt_info (nbd) != -1 || nbd_opt_info (nbd) != -1 || nbd_aio_is_dead (nbd) == 1) { diff --git a/tests/opt-structured-twice.c b/tests/opt-structured-twice.c index 17fab1f2..3892436a 100644 --- a/tests/opt-structured-twice.c +++ b/tests/opt-structured-twice.c @@ -60,7 +60,7 @@ main (int argc, char *argv[]) /* Connect to the server in opt mode, without structured replies. */ if (nbd_set_opt_mode (nbd, true) == -1 || nbd_set_request_structured_replies (nbd, false) == -1 || - nbd_connect_command (nbd, (char **) cmd) == -1) { + nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/pread-initialize.c b/tests/pread-initialize.c index 585bf608..36d1aae2 100644 --- a/tests/pread-initialize.c +++ b/tests/pread-initialize.c @@ -71,7 +71,7 @@ main (int argc, char *argv[]) } /* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/private-data.c b/tests/private-data.c index 734698c9..25d4cc5c 100644 --- a/tests/private-data.c +++ b/tests/private-data.c @@ -62,8 +62,8 @@ main (int argc, char *argv[]) assert (nbd_get_private_data (nbd1) == 43); /* Check that (in C) we can store and retrieve a pointer. */ - nbd_set_private_data (nbd1, (uintptr_t) &nbd_close); - assert (nbd_get_private_data (nbd1) == (uintptr_t) &nbd_close); + nbd_set_private_data (nbd1, (uintptr_t)&nbd_close); + assert (nbd_get_private_data (nbd1) == (uintptr_t)&nbd_close); nbd_close (nbd2); nbd_close (nbd1); diff --git a/tests/server-death.c b/tests/server-death.c index e65737a7..caf95572 100644 --- a/tests/server-death.c +++ b/tests/server-death.c @@ -66,7 +66,7 @@ main (int argc, char *argv[]) } /* Connect to a slow server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/shutdown-flags.c b/tests/shutdown-flags.c index bad638e9..4260425b 100644 --- a/tests/shutdown-flags.c +++ b/tests/shutdown-flags.c @@ -65,7 +65,7 @@ main (int argc, char *argv[]) } /* Connect to a server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/examples/glib-main-loop.c b/examples/glib-main-loop.c index 8403a970..38352683 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -79,7 +79,7 @@ events_from_nbd (struct nbd_handle *nbd) static gboolean prepare (GSource *sp, gint *timeout_) { - struct NBDSource *source = (struct NBDSource *) sp; + struct NBDSource *source = (struct NBDSource *)sp; int new_fd; int events; @@ -89,13 +89,13 @@ prepare (GSource *sp, gint *timeout_) new_fd = nbd_aio_get_fd (source->nbd); if (source->fd != new_fd) { if (source->tag != NULL) { - g_source_remove_unix_fd ((GSource *) source, source->tag); + g_source_remove_unix_fd ((GSource *)source, source->tag); source->fd = -1; source->tag = NULL; } if (new_fd >= 0) { source->fd = new_fd; - source->tag = g_source_add_unix_fd ((GSource *) source, new_fd, 0); + source->tag = g_source_add_unix_fd ((GSource *)source, new_fd, 0); } } @@ -103,7 +103,7 @@ prepare (GSource *sp, gint *timeout_) return FALSE; events = events_from_nbd (source->nbd); - g_source_modify_unix_fd ((GSource *) source, source->tag, events); + g_source_modify_unix_fd ((GSource *)source, source->tag, events); *timeout_ = -1; DEBUG (source, "prepare: events = 0x%x%s%s", @@ -125,14 +125,14 @@ prepare (GSource *sp, gint *timeout_) static gboolean check (GSource *sp) { - struct NBDSource *source = (struct NBDSource *) sp; + struct NBDSource *source = (struct NBDSource *)sp; unsigned dir; int revents; if (!source->tag) return FALSE; - revents = g_source_query_unix_fd ((GSource *) source, source->tag); + revents = g_source_query_unix_fd ((GSource *)source, source->tag); dir = nbd_aio_get_direction (source->nbd); DEBUG (source, "check: direction = 0x%x%s%s, revents = 0x%x%s%s", @@ -156,11 +156,11 @@ dispatch (GSource *sp, GSourceFunc callback, gpointer user_data) { - struct NBDSource *source = (struct NBDSource *) sp; + struct NBDSource *source = (struct NBDSource *)sp; int revents; int r; - revents = g_source_query_unix_fd ((GSource *) source, source->tag); + revents = g_source_query_unix_fd ((GSource *)source, source->tag); DEBUG (source, "dispatch: revents = 0x%x%s%s", revents, @@ -184,7 +184,7 @@ dispatch (GSource *sp, static void finalize (GSource *sp) { - struct NBDSource *source = (struct NBDSource *) sp; + struct NBDSource *source = (struct NBDSource *)sp; DEBUG (source, "finalize"); @@ -211,7 +211,7 @@ create_libnbd_gsource (struct nbd_handle *nbd) struct NBDSource *source; source = - (struct NBDSource *) g_source_new (&nbd_source_funcs, sizeof *source); + (struct NBDSource *)g_source_new (&nbd_source_funcs, sizeof *source); source->nbd = nbd; source->debug = nbd_get_debug (nbd); source->fd = -1; @@ -297,19 +297,19 @@ main (int argc, char *argv[]) gssrc = create_libnbd_gsource (src); gsdest = create_libnbd_gsource (dest); loopctx = g_main_loop_get_context (loop); - g_source_attach ((GSource *) gssrc, loopctx); - g_source_attach ((GSource *) gsdest, loopctx); + g_source_attach ((GSource *)gssrc, loopctx); + g_source_attach ((GSource *)gsdest, loopctx); /* Make sure we get called back when each handle connects. */ gssrc->connected_callback = connected; gsdest->connected_callback = connected; /* Asynchronously start each handle connecting. */ - if (nbd_aio_connect_command (src, (char **) src_args) == -1) { + if (nbd_aio_connect_command (src, (char **)src_args) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } - if (nbd_aio_connect_command (dest, (char **) dest_args) == -1) { + if (nbd_aio_connect_command (dest, (char **)dest_args) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } @@ -482,11 +482,11 @@ finished_write (void *vp, int *error) */ if (finished && nr_buffers == 0) { DEBUG (gsdest, "finished_write: all finished"); - g_source_remove (g_source_get_id ((GSource *) gssrc)); - g_source_unref ((GSource *) gssrc); + g_source_remove (g_source_get_id ((GSource *)gssrc)); + g_source_unref ((GSource *)gssrc); gssrc = NULL; - g_source_remove (g_source_get_id ((GSource *) gsdest)); - g_source_unref ((GSource *) gsdest); + g_source_remove (g_source_get_id ((GSource *)gsdest)); + g_source_unref ((GSource *)gsdest); gsdest = NULL; g_main_loop_quit (loop); } diff --git a/examples/open-qcow2.c b/examples/open-qcow2.c index 70ea9b37..dd5b7c74 100644 --- a/examples/open-qcow2.c +++ b/examples/open-qcow2.c @@ -34,7 +34,7 @@ main (int argc, const char *argv[]) */ char *args[] = { "qemu-nbd", "-f", "qcow2", - (char *) filename, + (char *)filename, NULL }; if (nbd_connect_systemd_socket_activation (nbd, diff --git a/interop/list-exports.c b/interop/list-exports.c index 8b15c815..26436cd6 100644 --- a/interop/list-exports.c +++ b/interop/list-exports.c @@ -75,7 +75,7 @@ append (void *opaque, const char *name, const char *description) static int compare_actuals (const void *vp1, const void *vp2) { - return strcmp (* (char * const *) vp1, * (char * const *) vp2); + return strcmp (*(char * const *)vp1, *(char * const *)vp2); } static void diff --git a/copy/file-ops.c b/copy/file-ops.c index 710fc68a..4f2ce738 100644 --- a/copy/file-ops.c +++ b/copy/file-ops.c @@ -334,7 +334,7 @@ file_close (struct rw *rw) static void file_truncate (struct rw *rw, int64_t size) { - struct rw_file *rwf = (struct rw_file *) rw; + struct rw_file *rwf = (struct rw_file *)rw; /* If the destination is an ordinary file then the original file * size doesn't matter. Truncate it to the source size. But @@ -420,7 +420,7 @@ file_synch_read (struct rw *rw, if (r == 0) return n; - data = (char *) data + r; + data = (char *)data + r; offset += r; len -= r; n += r; @@ -450,7 +450,7 @@ file_synch_write (struct rw *rw, perror (rw->name); exit (EXIT_FAILURE); } - data = (char *) data + r; + data = (char *)data + r; offset += r; len -= r; } diff --git a/copy/main.c b/copy/main.c index 9c53842f..391c0c4f 100644 --- a/copy/main.c +++ b/copy/main.c @@ -290,7 +290,7 @@ main (int argc, char *argv[]) found1: connections = 1; /* multi-conn not supported */ src = - nbd_rw_create_subprocess ((const char **) &argv[optind+1], i-optind-1, + nbd_rw_create_subprocess ((const char **)&argv[optind+1], i-optind-1, false); optind = i+1; } @@ -315,7 +315,7 @@ main (int argc, char *argv[]) found2: connections = 1; /* multi-conn not supported */ dst = - nbd_rw_create_subprocess ((const char **) &argv[optind+1], i-optind-1, + nbd_rw_create_subprocess ((const char **)&argv[optind+1], i-optind-1, true); optind = i+1; } @@ -371,7 +371,7 @@ main (int argc, char *argv[]) #else t = 1; #endif - threads = (unsigned) t; + threads = (unsigned)t; } if (synchronous) @@ -534,7 +534,7 @@ open_local (const char *filename, direction d) } if (S_ISREG (stat.st_mode)) /* Regular file. */ return file_create (filename, fd, - stat.st_size, (uint64_t) stat.st_blksize, false, d); + stat.st_size, (uint64_t)stat.st_blksize, false, d); else if (S_ISBLK (stat.st_mode)) { /* Block device. */ unsigned int blkioopt; @@ -549,7 +549,7 @@ open_local (const char *filename, direction d) #endif return file_create (filename, fd, - stat.st_size, (uint64_t) blkioopt, true, d); + stat.st_size, (uint64_t)blkioopt, true, d); } else { /* Probably stdin/stdout, a pipe or a socket. */ synchronous = true; /* Force synchronous mode for pipes. */ diff --git a/copy/nbd-ops.c b/copy/nbd-ops.c index 843b7c17..f3b3bed3 100644 --- a/copy/nbd-ops.c +++ b/copy/nbd-ops.c @@ -101,7 +101,7 @@ open_one_nbd_handle (struct rw_nbd *rwn) case CREATE_SUBPROCESS: if (nbd_connect_systemd_socket_activation (nbd, - (char **) rwn->argv.ptr) + (char **)rwn->argv.ptr) == -1) { fprintf (stderr, "%s: %s: %s\n", prog, rwn->argv.ptr[0], nbd_get_error ()); @@ -189,7 +189,7 @@ nbd_rw_create_subprocess (const char **argv, size_t argc, direction d) static void nbd_ops_close (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; size_t i; for (i = 0; i < rwn->handles.len; ++i) { @@ -208,7 +208,7 @@ nbd_ops_close (struct rw *rw) static void nbd_ops_flush (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; size_t i; for (i = 0; i < rwn->handles.len; ++i) { @@ -222,7 +222,7 @@ nbd_ops_flush (struct rw *rw) static bool nbd_ops_is_read_only (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (rwn->handles.len > 0) return nbd_is_read_only (rwn->handles.ptr[0]); @@ -233,7 +233,7 @@ nbd_ops_is_read_only (struct rw *rw) static bool nbd_ops_can_extents (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (rwn->handles.len > 0) return nbd_can_meta_context (rwn->handles.ptr[0], "base:allocation"); @@ -244,7 +244,7 @@ nbd_ops_can_extents (struct rw *rw) static bool nbd_ops_can_multi_conn (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (rwn->handles.len > 0) return nbd_can_multi_conn (rwn->handles.ptr[0]); @@ -255,7 +255,7 @@ nbd_ops_can_multi_conn (struct rw *rw) static void nbd_ops_start_multi_conn (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; size_t i; for (i = 1; i < connections; ++i) @@ -268,7 +268,7 @@ static size_t nbd_ops_synch_read (struct rw *rw, void *data, size_t len, uint64_t offset) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (len > rw->size - offset) len = rw->size - offset; @@ -287,7 +287,7 @@ static void nbd_ops_synch_write (struct rw *rw, const void *data, size_t len, uint64_t offset) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (nbd_pwrite (rwn->handles.ptr[0], data, len, offset, 0) == -1) { fprintf (stderr, "%s: %s\n", rw->name, nbd_get_error ()); @@ -299,7 +299,7 @@ static bool nbd_ops_synch_zero (struct rw *rw, uint64_t offset, uint64_t count, bool allocate) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (!rwn->can_zero) return false; @@ -317,7 +317,7 @@ nbd_ops_asynch_read (struct rw *rw, struct command *command, nbd_completion_callback cb) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (nbd_aio_pread (rwn->handles.ptr[command->worker->index], slice_ptr (command->slice), @@ -333,7 +333,7 @@ nbd_ops_asynch_write (struct rw *rw, struct command *command, nbd_completion_callback cb) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (nbd_aio_pwrite (rwn->handles.ptr[command->worker->index], slice_ptr (command->slice), @@ -348,7 +348,7 @@ static bool nbd_ops_asynch_zero (struct rw *rw, struct command *command, nbd_completion_callback cb, bool allocate) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (!rwn->can_zero) return false; @@ -367,7 +367,7 @@ nbd_ops_asynch_zero (struct rw *rw, struct command *command, static unsigned nbd_ops_in_flight (struct rw *rw, size_t index) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; /* Since the commands are auto-retired in the callbacks we don't * need to count "done" commands. @@ -379,7 +379,7 @@ static void nbd_ops_get_polling_fd (struct rw *rw, size_t index, int *fd, int *direction) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; struct nbd_handle *nbd; nbd = rwn->handles.ptr[index]; @@ -402,7 +402,7 @@ nbd_ops_get_polling_fd (struct rw *rw, size_t index, static void nbd_ops_asynch_notify_read (struct rw *rw, size_t index) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (nbd_aio_notify_read (rwn->handles.ptr[index]) == -1) { fprintf (stderr, "%s: %s\n", rw->name, nbd_get_error ()); exit (EXIT_FAILURE); @@ -412,7 +412,7 @@ nbd_ops_asynch_notify_read (struct rw *rw, size_t index) static void nbd_ops_asynch_notify_write (struct rw *rw, size_t index) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (nbd_aio_notify_write (rwn->handles.ptr[index]) == -1) { fprintf (stderr, "%s: %s\n", rw->name, nbd_get_error ()); exit (EXIT_FAILURE); @@ -436,7 +436,7 @@ nbd_ops_get_extents (struct rw *rw, size_t index, uint64_t offset, uint64_t count, extent_list *ret) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; extent_list exts = empty_vector; struct nbd_handle *nbd; diff --git a/copy/pipe-ops.c b/copy/pipe-ops.c index 596f3fed..bd8b7645 100644 --- a/copy/pipe-ops.c +++ b/copy/pipe-ops.c @@ -51,7 +51,7 @@ pipe_create (const char *name, int fd) static void pipe_close (struct rw *rw) { - struct rw_pipe *rwp = (struct rw_pipe *) rw; + struct rw_pipe *rwp = (struct rw_pipe *)rw; if (close (rwp->fd) == -1) { fprintf (stderr, "%s: close: %m\n", rw->name); @@ -96,7 +96,7 @@ static size_t pipe_synch_read (struct rw *rw, void *data, size_t len, uint64_t offset) { - struct rw_pipe *rwp = (struct rw_pipe *) rw; + struct rw_pipe *rwp = (struct rw_pipe *)rw; ssize_t r; r = read (rwp->fd, data, len); @@ -111,7 +111,7 @@ static void pipe_synch_write (struct rw *rw, const void *data, size_t len, uint64_t offset) { - struct rw_pipe *rwp = (struct rw_pipe *) rw; + struct rw_pipe *rwp = (struct rw_pipe *)rw; while (len > 0) { ssize_t r = write (rwp->fd, data, len); @@ -119,7 +119,7 @@ pipe_synch_write (struct rw *rw, perror (rw->name); exit (EXIT_FAILURE); } - data = (char *) data + r; + data = (char *)data + r; len -= r; } } diff --git a/dump/dump.c b/dump/dump.c index 3de24a12..b4aebe84 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -398,7 +398,7 @@ do_dump (void) /* Print the ASCII codes. */ printf ("%s", pipe); for (j = i; j < MIN (i+16, n); ++j) { - char c = (char) buffer[j]; + char c = (char)buffer[j]; if (isalnum (c)) { ansi_colour (ANSI_FG_BRIGHT_RED, stdout); printf ("%c", c); diff --git a/fuse/nbdfuse.c b/fuse/nbdfuse.c index d3eca256..491f6db8 100644 --- a/fuse/nbdfuse.c +++ b/fuse/nbdfuse.c @@ -109,7 +109,7 @@ fuse_help (const char *prog) { static struct fuse_operations null_operations; const char *tmp_argv[] = { prog, "--help", NULL }; - fuse_main (2, (char **) tmp_argv, &null_operations, NULL); + fuse_main (2, (char **)tmp_argv, &null_operations, NULL); exit (EXIT_SUCCESS); } @@ -415,7 +415,7 @@ main (int argc, char *argv[]) handles_append (&nbd, h); /* reserved above, so can't fail */ } } - connections = (unsigned) nbd.len; + connections = (unsigned)nbd.len; if (verbose) fprintf (stderr, "nbdfuse: connections=%u\n", connections); @@ -424,7 +424,7 @@ main (int argc, char *argv[]) fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } - size = (uint64_t) ssize; + size = (uint64_t)ssize; /* If the remote NBD server is readonly, then act as if the '-r' * flag was given on the nbdfuse command line. @@ -481,7 +481,7 @@ main (int argc, char *argv[]) if (pidfile) { fp = fopen (pidfile, "w"); if (fp) { - fprintf (fp, "%ld", (long) getpid ()); + fprintf (fp, "%ld", (long)getpid ()); fclose (fp); } } diff --git a/fuse/operations.c b/fuse/operations.c index 6f6bee3a..2d0634dc 100644 --- a/fuse/operations.c +++ b/fuse/operations.c @@ -380,7 +380,7 @@ nbdfuse_read (const char *path, char *buf, struct fuse_file_info *fi) { DEBUG_OPERATION ("read", "path=%s, buf=%p, count=%zu, offset=%" PRIi64, - path, buf, count, (int64_t) offset); + path, buf, count, (int64_t)offset); if (!file_mode && (path[0] != '/' || strcmp (path+1, filename) != 0)) return -ENOENT; @@ -396,7 +396,7 @@ nbdfuse_read (const char *path, char *buf, CHECK_NBD_ASYNC_ERROR (nbd_aio_pread (h, buf, count, offset, cb, 0)); - return (int) count; + return (int)count; } static int @@ -405,7 +405,7 @@ nbdfuse_write (const char *path, const char *buf, struct fuse_file_info *fi) { DEBUG_OPERATION ("write", "path=%s, buf=%p, count=%zu, offset=%" PRIi64, - path, buf, count, (int64_t) offset); + path, buf, count, (int64_t)offset); /* Probably shouldn't happen because of nbdfuse_open check. */ if (readonly) @@ -425,7 +425,7 @@ nbdfuse_write (const char *path, const char *buf, CHECK_NBD_ASYNC_ERROR (nbd_aio_pwrite (h, buf, count, offset, cb, 0)); - return (int) count; + return (int)count; } static int @@ -460,7 +460,7 @@ nbdfuse_fallocate (const char *path, int mode, off_t offset, off_t len, { DEBUG_OPERATION ("fallocate", "path=%s, mode=%d, " "offset=%" PRIi64 ", len=%" PRIi64, - path, mode, (int64_t) offset, (int64_t) len); + path, mode, (int64_t)offset, (int64_t)len); if (readonly) return -EACCES; diff --git a/ublk/nbdublk.c b/ublk/nbdublk.c index b079d577..b85ac609 100644 --- a/ublk/nbdublk.c +++ b/ublk/nbdublk.c @@ -347,7 +347,7 @@ main (int argc, char *argv[]) handles_append (&nbd, h); /* reserved above, so can't fail */ } } - connections = (unsigned) nbd.len; + connections = (unsigned)nbd.len; /* Get the size and preferred block sizes. */ rs = nbd_get_size (nbd.ptr[0]); @@ -355,7 +355,7 @@ main (int argc, char *argv[]) fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } - size = (uint64_t) rs; + size = (uint64_t)rs; rs = nbd_get_block_size (nbd.ptr[0], LIBNBD_SIZE_MAXIMUM); if (rs <= 0 || rs > 64 * 1024 * 1024) diff --git a/ublk/tgt.c b/ublk/tgt.c index 77d39661..20971bdb 100644 --- a/ublk/tgt.c +++ b/ublk/tgt.c @@ -120,7 +120,7 @@ aio_submitter (struct ublksrv_aio_ctx *ctx, struct ublksrv_aio *req) switch (op) { case UBLK_IO_OP_READ: - r = nbd_aio_pread (h, (void *) iod->addr, iod->nr_sectors << 9, + r = nbd_aio_pread (h, (void *)iod->addr, iod->nr_sectors << 9, iod->start_sector << 9, cb, 0); if (r == -1) { fprintf (stderr, "%s: %s\n", "nbdublk", nbd_get_error ()); @@ -132,7 +132,7 @@ aio_submitter (struct ublksrv_aio_ctx *ctx, struct ublksrv_aio *req) if (fua && can_fua) nbd_flags |= LIBNBD_CMD_FLAG_FUA; - r = nbd_aio_pwrite (h, (const void *) iod->addr, iod->nr_sectors << 9, + r = nbd_aio_pwrite (h, (const void *)iod->addr, iod->nr_sectors << 9, iod->start_sector << 9, cb, nbd_flags); if (r == -1) { fprintf (stderr, "%s: %s\n", "nbdublk", nbd_get_error ()); -- 2.40.1
On 5/24/23 04:12, Eric Blake wrote:
We are inconsistent on whether a cast operator should be separated from its argument by a space. As a unary prefix operator, casts bind with relatively tight precedence, where only postfix operations (including function calls) come higher. We generally don't use a space after other prefix operators (*, &, ~, and unary - tend to not be followed by space; we are less consistent on !, but that would be a separate patch).
Furthermore, we've already decided (in commit b5101fbc) that we prefer spaces before function invocations. At the time, discussion on the list[1] pointed out that thanks to the complexity of C with its context-sensitive parsing needing to know whether an identifier is a type name, you would be able to tell the difference between a 2-argument function call with two parameters through a function pointer (or intentional function-like macro suppression):
(foo) (bar, baz)
from the (admittedly rare) application of a cast operator to the results of a comma operator:
(foo)(bar, baz)
if we consistently avoid spaces after casts.
Determining cast operators is not always trivial, but the regex used below seems to have a pretty low false positive rate (lines it selects usually are casts and not in a comment line), and can be modified by removing the space to see where we already had casts without a space. (Obviously, I can't tell how many false negatives there are of casts I missed out on). While this changes more lines than would be done by instead always using a space in a cast, it is still manageable to do a bulk change.
$ git grep '\(_t\|int\|long\|signed\|char\|\*\)) [a-zA-Z0-9&"]' -- \ '**/*.[hc]' '**/*.ml' | grep -v '^ */\?\*'
'git show -w' shows that this change is whitespace only.
[1] https://listman.redhat.com/archives/libguestfs/2023-February/030771.html
Signed-off-by: Eric Blake <eblake@redhat.com> --- configure.ac | 6 ++-- common/utils/vector.h | 4 +-- generator/OCaml.ml | 4 +-- generator/Python.ml | 4 +-- generator/states-connect-socket-activation.c | 4 +-- generator/states-connect.c | 2 +- generator/states-issue-command.c | 2 +- generator/states-newstyle.c | 2 +- generator/states-oldstyle.c | 2 +- generator/states-reply-structured.c | 14 ++++---- generator/states-reply.c | 2 +- generator/states.c | 4 +-- lib/crypto.c | 6 ++-- lib/rw.c | 2 +- lib/uri.c | 10 +++--- lib/utils.c | 4 +-- common/utils/test-vector.c | 4 +-- python/handle.c | 4 +-- python/utils.c | 2 +- ocaml/nbd-c.h | 6 ++-- tests/aio-connect-port.c | 2 +- tests/aio-connect.c | 2 +- tests/errors-bad-cookie.c | 2 +- tests/errors-client-oversize.c | 2 +- tests/errors-client-unadvertised-cmd.c | 2 +- tests/errors-client-unaligned.c | 2 +- tests/errors-client-unknown-flags.c | 2 +- tests/errors-client-zerosize.c | 2 +- tests/errors-connect-null.c | 2 +- tests/errors-connect-twice.c | 4 +-- tests/errors-multiple-disconnects.c | 2 +- tests/errors-not-negotiating.c | 2 +- tests/errors-notify-not-blocked.c | 2 +- tests/errors-pread-structured.c | 2 +- tests/errors-server-invalid-offset.c | 2 +- tests/errors-server-oversize.c | 2 +- tests/errors-server-unadvertised-cmd.c | 2 +- tests/errors-server-unaligned.c | 2 +- tests/errors-server-unknown-flags.c | 2 +- tests/errors-server-zerosize.c | 2 +- tests/opt-set-meta.c | 2 +- tests/opt-starttls.c | 4 +-- tests/opt-structured-twice.c | 2 +- tests/pread-initialize.c | 2 +- tests/private-data.c | 4 +-- tests/server-death.c | 2 +- tests/shutdown-flags.c | 2 +- examples/glib-main-loop.c | 36 ++++++++++---------- examples/open-qcow2.c | 2 +- interop/list-exports.c | 2 +- copy/file-ops.c | 6 ++-- copy/main.c | 10 +++--- copy/nbd-ops.c | 36 ++++++++++---------- copy/pipe-ops.c | 8 ++--- dump/dump.c | 2 +- fuse/nbdfuse.c | 8 ++--- fuse/operations.c | 10 +++--- ublk/nbdublk.c | 4 +-- ublk/tgt.c | 4 +-- 59 files changed, 138 insertions(+), 138 deletions(-)
Going through the changes individually, it seems like we could eliminate a handful of the casts altogether; for examle (char *)"string literal" ones. (The C standard effectively says that a (non-wide) string literal has type "static char[n]", not "static const char[n]".) But that would be a different patch, plus I can imagine we have those casts in the first place because gcc complained or whatever. :) Reviewed-by: Laszlo Ersek <lersek@redhat.com>
On Wed, May 24, 2023 at 07:39:20AM +0200, Laszlo Ersek wrote:
Going through the changes individually, it seems like we could eliminate a handful of the casts altogether; for examle (char *)"string literal" ones.
It'd be interesting to remove then and compile with './configure --enable-gcc-warnings' to see if that creates new warnings.
(The C standard effectively says that a (non-wide) string literal has type "static char[n]", not "static const char[n]".) But that would be a different patch, plus I can imagine we have those casts in the first place because gcc complained or whatever. :)
It's a bit surprising. Surely any string literal is placed in the text section so definitely not writable? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
On Wed, May 24, 2023 at 02:09:30PM +0100, Richard W.M. Jones wrote:
On Wed, May 24, 2023 at 07:39:20AM +0200, Laszlo Ersek wrote:
Going through the changes individually, it seems like we could eliminate a handful of the casts altogether; for examle (char *)"string literal" ones.
It'd be interesting to remove then and compile with './configure --enable-gcc-warnings' to see if that creates new warnings.
(The C standard effectively says that a (non-wide) string literal has type "static char[n]", not "static const char[n]".) But that would be a different patch, plus I can imagine we have those casts in the first place because gcc complained or whatever. :)
It's a bit surprising. Surely any string literal is placed in the text section so definitely not writable?
C17 6.4.5 Paragraphs 6 and 7 "... The multibyte character sequence is then used to initialize an array of static storage duration and length just sufficient to contain the sequence. For character string literals, the array elements have type char, ..." "It is unspecified whether these arrays are distinct provided their elements have the appropriate values. If the program attempts to modify such an array, the behavior is undefined." Yeah, it's weird. In C, a string literal has the effective type 'char *' except that you cannot safely modify its contents; it's due to historical back-compat to pre-standard compilers that lacked 'const char *'. C++ on the other hand treats string literals as const char *; code that intends to be compiled in either language must explicitly cast away the const. I've checked that the compiler does not complain if we remove casts that only serve to explicitly document that we are removing const when passing a string literal to a place that wants a 'char *' but will otherwise not modify the contents. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On 5/24/23 15:09, Richard W.M. Jones wrote:
On Wed, May 24, 2023 at 07:39:20AM +0200, Laszlo Ersek wrote:
Going through the changes individually, it seems like we could eliminate a handful of the casts altogether; for examle (char *)"string literal" ones.
It'd be interesting to remove then and compile with './configure --enable-gcc-warnings' to see if that creates new warnings.
(The C standard effectively says that a (non-wide) string literal has type "static char[n]", not "static const char[n]".) But that would be a different patch, plus I can imagine we have those casts in the first place because gcc complained or whatever. :)
It's a bit surprising. Surely any string literal is placed in the text section so definitely not writable?
The standard does say that any attempt to modify a string literal leads to undefined behavior. But the type of a non-wide string literal is still "array of chars". Laszlo
On Wed, May 24, 2023 at 07:39:20AM +0200, Laszlo Ersek wrote:
On 5/24/23 04:12, Eric Blake wrote:
We are inconsistent on whether a cast operator should be separated from its argument by a space. As a unary prefix operator, casts bind with relatively tight precedence, where only postfix operations (including function calls) come higher. We generally don't use a space after other prefix operators (*, &, ~, and unary - tend to not be followed by space; we are less consistent on !, but that would be a separate patch).
Going through the changes individually, it seems like we could eliminate a handful of the casts altogether; for examle (char *)"string literal" ones. (The C standard effectively says that a (non-wide) string literal has type "static char[n]", not "static const char[n]".) But that would be a different patch, plus I can imagine we have those casts in the first place because gcc complained or whatever. :)
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Indeed, I did a manual review, and posted a followup patch of several casts that can be eliminated without causing any compiler warnings. I'm still planning on committing this patch as-is (whitespace only changes) but will wait until we review that patch to make sure I'm not eliminating a cast that would otherwise serve a useful documentation purpose despite being semantically unneeded. I could also rearrange the two patches (remove unneeded casts first, then fix whitespacing on the casts that remain) if desired. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
On Tue, May 23, 2023 at 09:12:44PM -0500, Eric Blake wrote:
We are inconsistent on whether a cast operator should be separated from its argument by a space. As a unary prefix operator, casts bind with relatively tight precedence, where only postfix operations (including function calls) come higher. We generally don't use a space after other prefix operators (*, &, ~, and unary - tend to not be followed by space; we are less consistent on !, but that would be a separate patch).
Furthermore, we've already decided (in commit b5101fbc) that we prefer spaces before function invocations. At the time, discussion on the list[1] pointed out that thanks to the complexity of C with its context-sensitive parsing needing to know whether an identifier is a type name, you would be able to tell the difference between a 2-argument function call with two parameters through a function pointer (or intentional function-like macro suppression):
(foo) (bar, baz)
from the (admittedly rare) application of a cast operator to the results of a comma operator:
(foo)(bar, baz)
if we consistently avoid spaces after casts.
Determining cast operators is not always trivial, but the regex used below seems to have a pretty low false positive rate (lines it selects usually are casts and not in a comment line), and can be modified by removing the space to see where we already had casts without a space. (Obviously, I can't tell how many false negatives there are of casts I missed out on). While this changes more lines than would be done by instead always using a space in a cast, it is still manageable to do a bulk change.
$ git grep '\(_t\|int\|long\|signed\|char\|\*\)) [a-zA-Z0-9&"]' -- \ '**/*.[hc]' '**/*.ml' | grep -v '^ */\?\*'
'git show -w' shows that this change is whitespace only.
[1] https://listman.redhat.com/archives/libguestfs/2023-February/030771.html
Signed-off-by: Eric Blake <eblake@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
--- configure.ac | 6 ++-- common/utils/vector.h | 4 +-- generator/OCaml.ml | 4 +-- generator/Python.ml | 4 +-- generator/states-connect-socket-activation.c | 4 +-- generator/states-connect.c | 2 +- generator/states-issue-command.c | 2 +- generator/states-newstyle.c | 2 +- generator/states-oldstyle.c | 2 +- generator/states-reply-structured.c | 14 ++++---- generator/states-reply.c | 2 +- generator/states.c | 4 +-- lib/crypto.c | 6 ++-- lib/rw.c | 2 +- lib/uri.c | 10 +++--- lib/utils.c | 4 +-- common/utils/test-vector.c | 4 +-- python/handle.c | 4 +-- python/utils.c | 2 +- ocaml/nbd-c.h | 6 ++-- tests/aio-connect-port.c | 2 +- tests/aio-connect.c | 2 +- tests/errors-bad-cookie.c | 2 +- tests/errors-client-oversize.c | 2 +- tests/errors-client-unadvertised-cmd.c | 2 +- tests/errors-client-unaligned.c | 2 +- tests/errors-client-unknown-flags.c | 2 +- tests/errors-client-zerosize.c | 2 +- tests/errors-connect-null.c | 2 +- tests/errors-connect-twice.c | 4 +-- tests/errors-multiple-disconnects.c | 2 +- tests/errors-not-negotiating.c | 2 +- tests/errors-notify-not-blocked.c | 2 +- tests/errors-pread-structured.c | 2 +- tests/errors-server-invalid-offset.c | 2 +- tests/errors-server-oversize.c | 2 +- tests/errors-server-unadvertised-cmd.c | 2 +- tests/errors-server-unaligned.c | 2 +- tests/errors-server-unknown-flags.c | 2 +- tests/errors-server-zerosize.c | 2 +- tests/opt-set-meta.c | 2 +- tests/opt-starttls.c | 4 +-- tests/opt-structured-twice.c | 2 +- tests/pread-initialize.c | 2 +- tests/private-data.c | 4 +-- tests/server-death.c | 2 +- tests/shutdown-flags.c | 2 +- examples/glib-main-loop.c | 36 ++++++++++---------- examples/open-qcow2.c | 2 +- interop/list-exports.c | 2 +- copy/file-ops.c | 6 ++-- copy/main.c | 10 +++--- copy/nbd-ops.c | 36 ++++++++++---------- copy/pipe-ops.c | 8 ++--- dump/dump.c | 2 +- fuse/nbdfuse.c | 8 ++--- fuse/operations.c | 10 +++--- ublk/nbdublk.c | 4 +-- ublk/tgt.c | 4 +-- 59 files changed, 138 insertions(+), 138 deletions(-)
diff --git a/configure.ac b/configure.ac index 30348ea9..0a9e4d79 100644 --- a/configure.ac +++ b/configure.ac @@ -456,7 +456,7 @@ AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \ AC_MSG_CHECKING([for caml_alloc_custom_mem]) cat >conftest.c <<'EOF' #include <caml/custom.h> -int main () { char *p = (void *) caml_alloc_custom_mem; return 0; } +int main () { char *p = (void *)caml_alloc_custom_mem; return 0; } EOF AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[ AC_MSG_RESULT([yes]) @@ -474,7 +474,7 @@ AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \ AC_MSG_CHECKING([for caml_alloc_initialized_string]) cat >conftest.c <<'EOF' #include <caml/alloc.h> -int main () { char *p = (void *) caml_alloc_initialized_string; return 0; } +int main () { char *p = (void *)caml_alloc_initialized_string; return 0; } EOF AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[ AC_MSG_RESULT([yes]) @@ -492,7 +492,7 @@ AS_IF([test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno" && \ AC_MSG_CHECKING([for caml_unix_get_sockaddr]) cat >conftest.c <<'EOF' #include <caml/socketaddr.h> -int main () { char *p = (void *) caml_unix_get_sockaddr; return 0; } +int main () { char *p = (void *)caml_unix_get_sockaddr; return 0; } EOF AS_IF([$OCAMLC conftest.c >&AS_MESSAGE_LOG_FD 2>&1],[ AC_MSG_RESULT([yes]) diff --git a/common/utils/vector.h b/common/utils/vector.h index 7337d268..50cad1d0 100644 --- a/common/utils/vector.h +++ b/common/utils/vector.h @@ -173,7 +173,7 @@ name##_sort (name *v, \ int (*compare) (const type *p1, const type *p2)) \ { \ - qsort (v->ptr, v->len, sizeof (type), (void *) compare); \ + qsort (v->ptr, v->len, sizeof (type), (void *)compare); \ } \ \ /* Search for an exactly matching element in the vector using a \ @@ -184,7 +184,7 @@ int (*compare) (const void *key, const type *v)) \ { \ return bsearch (key, v->ptr, v->len, sizeof (type), \ - (void *) compare); \ + (void *)compare); \ } \ \ /* Make a new vector with the same elements. */ \ diff --git a/generator/OCaml.ml b/generator/OCaml.ml index 300c8a70..edb81f25 100644 --- a/generator/OCaml.ml +++ b/generator/OCaml.ml @@ -710,12 +710,12 @@ let pr " size_t %s = Int_val (%sv);\n" n n | SockAddrAndLen (n, len) -> pr " struct sockaddr_storage %s_storage;\n" n; - pr " struct sockaddr *%s = (struct sockaddr *) &%s_storage;\n" n n; + pr " struct sockaddr *%s = (struct sockaddr *)&%s_storage;\n" n n; pr " socklen_t %s;\n" len; pr " nbd_internal_unix_sockaddr_to_sa (%sv, &%s_storage, &%s);\n" n n len | StringList n -> - pr " char **%s = (char **) nbd_internal_ocaml_string_list (%sv);\n" n n + pr " char **%s = (char **)nbd_internal_ocaml_string_list (%sv);\n" n n | UInt n | UIntPtr n -> pr " unsigned %s = Int_val (%sv);\n" n n | UInt32 n -> diff --git a/generator/Python.ml b/generator/Python.ml index c146f04f..b73f9782 100644 --- a/generator/Python.ml +++ b/generator/Python.ml @@ -49,7 +49,7 @@ let { assert (obj); assert (obj != Py_None); - return (struct nbd_handle *) PyCapsule_GetPointer(obj, \"nbd_handle\"); + return (struct nbd_handle *)PyCapsule_GetPointer(obj, \"nbd_handle\"); }
/* nbd.Error exception. */ @@ -370,7 +370,7 @@ let | SizeT n -> "n", sprintf "&%s" n, sprintf "(size_t)%s" n | SockAddrAndLen (n, _) -> "O", sprintf "&%s" n, - sprintf "(struct sockaddr *) &%s_sa, %s_len" n n + sprintf "(struct sockaddr *)&%s_sa, %s_len" n n | String n -> "s", sprintf "&%s" n, n | StringList n -> "O", sprintf "&py_%s" n, n | UInt n | UIntPtr n -> "I", sprintf "&%s" n, n diff --git a/generator/states-connect-socket-activation.c b/generator/states-connect-socket-activation.c index b57d5d00..98a39c0e 100644 --- a/generator/states-connect-socket-activation.c +++ b/generator/states-connect-socket-activation.c @@ -224,7 +224,7 @@ CONNECT_SA.START:
addr.sun_family = AF_UNIX; memcpy (addr.sun_path, sockpath, strlen (sockpath) + 1); - if (bind (s, (struct sockaddr *) &addr, sizeof addr) == -1) { + if (bind (s, (struct sockaddr *)&addr, sizeof addr) == -1) { set_error (errno, "bind: %s", sockpath); goto close_socket; } @@ -294,7 +294,7 @@ CONNECT_SA.START:
char buf[32]; const char *v = - nbd_internal_fork_safe_itoa ((long) getpid (), buf, sizeof buf); + nbd_internal_fork_safe_itoa ((long)getpid (), buf, sizeof buf); NBD_INTERNAL_FORK_SAFE_ASSERT (strlen (v) <= sact_var[pid_ofs].value_len); strcpy (env.ptr[pid_ofs] + sact_var[pid_ofs].prefix_len, v);
diff --git a/generator/states-connect.c b/generator/states-connect.c index 65a68003..98d9f945 100644 --- a/generator/states-connect.c +++ b/generator/states-connect.c @@ -84,7 +84,7 @@ CONNECT.START: disable_nagle (fd); disable_sigpipe (fd);
- r = connect (fd, (struct sockaddr *) &h->connaddr, h->connaddrlen); + r = connect (fd, (struct sockaddr *)&h->connaddr, h->connaddrlen); if (r == 0 || (r == -1 && errno == EINPROGRESS)) return 0; assert (r == -1); diff --git a/generator/states-issue-command.c b/generator/states-issue-command.c index a1458c6d..34ef4652 100644 --- a/generator/states-issue-command.c +++ b/generator/states-issue-command.c @@ -46,7 +46,7 @@ ISSUE_COMMAND.START: h->request.type = htobe16 (cmd->type); h->request.handle = htobe64 (cmd->cookie); h->request.offset = htobe64 (cmd->offset); - h->request.count = htobe32 ((uint32_t) cmd->count); + h->request.count = htobe32 ((uint32_t)cmd->count); h->chunks_sent++; h->wbuf = &h->request; h->wlen = sizeof (h->request); diff --git a/generator/states-newstyle.c b/generator/states-newstyle.c index 3bd17c33..ad5bbf72 100644 --- a/generator/states-newstyle.c +++ b/generator/states-newstyle.c @@ -102,7 +102,7 @@ handle_reply_error (struct nbd_handle *h) }
if (len > 0) - debug (h, "handshake: server error message: %.*s", (int) len, + debug (h, "handshake: server error message: %.*s", (int)len, h->sbuf.or.payload.err_msg);
return 0; diff --git a/generator/states-oldstyle.c b/generator/states-oldstyle.c index c9635636..f1be5df0 100644 --- a/generator/states-oldstyle.c +++ b/generator/states-oldstyle.c @@ -25,7 +25,7 @@ OLDSTYLE.START: */ h->rbuf = &h->sbuf.old_handshake; h->rlen = sizeof h->sbuf.old_handshake; - h->rbuf = (char *) h->rbuf + 16; + h->rbuf = (char *)h->rbuf + 16; h->rlen -= 16; SET_NEXT_STATE (%RECV_REMAINING); return 0; diff --git a/generator/states-reply-structured.c b/generator/states-reply-structured.c index 0788fb03..5aca7262 100644 --- a/generator/states-reply-structured.c +++ b/generator/states-reply-structured.c @@ -49,7 +49,7 @@ REPLY.STRUCTURED_REPLY.START: * so read the remaining part. */ h->rbuf = &h->sbuf; - h->rbuf = (char *) h->rbuf + sizeof h->sbuf.simple_reply; + h->rbuf = (char *)h->rbuf + sizeof h->sbuf.simple_reply; h->rlen = sizeof h->sbuf.sr.structured_reply; h->rlen -= sizeof h->sbuf.simple_reply; SET_NEXT_STATE (%RECV_REMAINING); @@ -223,7 +223,7 @@ REPLY.STRUCTURED_REPLY.RECV_ERROR_MESSAGE: length -= sizeof h->sbuf.sr.payload.error.error + msglen;
if (msglen) - debug (h, "structured error server message: %.*s", (int) msglen, + debug (h, "structured error server message: %.*s", (int)msglen, h->sbuf.sr.payload.error.msg);
/* Special case two specific errors; silently ignore tail for all others */ @@ -286,7 +286,7 @@ REPLY.STRUCTURED_REPLY.RECV_ERROR_TAIL: * without setting errno, then use the server's error below. */ if (CALL_CALLBACK (cmd->cb.fn.chunk, - (char *) cmd->data + (offset - cmd->offset), + (char *)cmd->data + (offset - cmd->offset), 0, offset, LIBNBD_READ_ERROR, &scratch) == -1) if (cmd->error == 0) @@ -337,7 +337,7 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_DATA: offset -= cmd->offset;
/* Set up to receive the data directly to the user buffer. */ - h->rbuf = (char *) cmd->data + offset; + h->rbuf = (char *)cmd->data + offset; h->rlen = length; SET_NEXT_STATE (%RECV_OFFSET_DATA_DATA); } @@ -363,7 +363,7 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_DATA_DATA: int error = cmd->error;
if (CALL_CALLBACK (cmd->cb.fn.chunk, - (char *) cmd->data + (offset - cmd->offset), + (char *)cmd->data + (offset - cmd->offset), length - sizeof offset, offset, LIBNBD_READ_DATA, &error) == -1) if (cmd->error == 0) @@ -408,12 +408,12 @@ REPLY.STRUCTURED_REPLY.RECV_OFFSET_HOLE: * them as an extension, and this works even when length == 0. */ if (!cmd->initialized) - memset ((char *) cmd->data + offset, 0, length); + memset ((char *)cmd->data + offset, 0, length); if (CALLBACK_IS_NOT_NULL (cmd->cb.fn.chunk)) { int error = cmd->error;
if (CALL_CALLBACK (cmd->cb.fn.chunk, - (char *) cmd->data + offset, length, + (char *)cmd->data + offset, length, cmd->offset + offset, LIBNBD_READ_HOLE, &error) == -1) if (cmd->error == 0) diff --git a/generator/states-reply.c b/generator/states-reply.c index 010d108b..f7888154 100644 --- a/generator/states-reply.c +++ b/generator/states-reply.c @@ -97,7 +97,7 @@ REPLY.START: #endif
h->bytes_received += r; - h->rbuf = (char *) h->rbuf + r; + h->rbuf = (char *)h->rbuf + r; h->rlen -= r; SET_NEXT_STATE (%RECV_REPLY); return 0; diff --git a/generator/states.c b/generator/states.c index 836862ea..425fa62f 100644 --- a/generator/states.c +++ b/generator/states.c @@ -91,7 +91,7 @@ recv_into_rbuf (struct nbd_handle *h) #endif h->bytes_received += r; if (h->rbuf) - h->rbuf = (char *) h->rbuf + r; + h->rbuf = (char *)h->rbuf + r; h->rlen -= r; if (h->rlen == 0) return 0; /* move to next state */ @@ -114,7 +114,7 @@ send_from_wbuf (struct nbd_handle *h) return -1; } h->bytes_sent += r; - h->wbuf = (char *) h->wbuf + r; + h->wbuf = (char *)h->wbuf + r; h->wlen -= r; if (h->wlen == 0) goto next_state; diff --git a/lib/crypto.c b/lib/crypto.c index d43eeb4c..22a1cfa5 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -307,7 +307,7 @@ lookup_key (const char *pskfile, const char *username, if (r > ulen+1 && strncmp (line, username, ulen) == 0 && line[ulen] == ':') { - key->data = (unsigned char *) strdup (&line[ulen+1]); + key->data = (unsigned char *)strdup (&line[ulen+1]); if (key->data == NULL) { set_error (errno, "strdup"); goto error; @@ -712,7 +712,7 @@ nbd_internal_crypto_handshake (struct nbd_handle *h) in = gnutls_handshake_get_last_in (session); out = gnutls_handshake_get_last_out (session); set_error (0, "gnutls_handshake: %s (%d/%d)", - gnutls_strerror (err), (int) in, (int) out); + gnutls_strerror (err), (int)in, (int)out); return -1; }
@@ -742,7 +742,7 @@ nbd_internal_crypto_debug_tls_enabled (struct nbd_handle *h) case GNUTLS_KTLS_SEND: ktls_status = "enabled send only"; break; case GNUTLS_KTLS_DUPLEX: ktls_status = "enabled"; break; default: - if ((int) ktls_enabled == 0) + if ((int)ktls_enabled == 0) ktls_status = "disabled"; else ktls_status = "unknown"; diff --git a/lib/rw.c b/lib/rw.c index a8d9e66c..3dc3499e 100644 --- a/lib/rw.c +++ b/lib/rw.c @@ -361,7 +361,7 @@ nbd_unlocked_aio_pwrite (struct nbd_handle *h, const void *buf,
SET_CALLBACK_TO_NULL (*completion); return nbd_internal_command_common (h, flags, NBD_CMD_WRITE, offset, count, - ENOSPC, (void *) buf, &cb); + ENOSPC, (void *)buf, &cb); }
int64_t diff --git a/lib/uri.c b/lib/uri.c index f9fde455..0c8e87cf 100644 --- a/lib/uri.c +++ b/lib/uri.c @@ -376,7 +376,7 @@ nbd_unlocked_aio_connect_uri (struct nbd_handle *h, const char *raw_uri) * uri->port > 0. This prevents us from using certain very large * port numbers, but that's not an issue that matters in practice. */ - svm_port = uri->port > 0 ? (uint32_t) uri->port : 10809; + svm_port = uri->port > 0 ? (uint32_t)uri->port : 10809; if (nbd_unlocked_aio_connect_vsock (h, cid, svm_port) == -1) goto cleanup;
@@ -451,7 +451,7 @@ nbd_unlocked_get_uri (struct nbd_handle *h) char serv[NI_MAXSERV];
uri.scheme = using_tls ? "nbds" : "nbd"; - err = getnameinfo ((struct sockaddr *) &h->connaddr, h->connaddrlen, + err = getnameinfo ((struct sockaddr *)&h->connaddr, h->connaddrlen, host, sizeof host, serv, sizeof serv, NI_NUMERICHOST | NI_NUMERICSERV); if (err != 0) { @@ -471,7 +471,7 @@ nbd_unlocked_get_uri (struct nbd_handle *h) }
case AF_UNIX: { - struct sockaddr_un *sun = (struct sockaddr_un *) &h->connaddr; + struct sockaddr_un *sun = (struct sockaddr_un *)&h->connaddr;
if (sun->sun_path[0] == '\0') { /* Unix domain sockets in the abstract namespace are in theory @@ -495,7 +495,7 @@ nbd_unlocked_get_uri (struct nbd_handle *h)
#if HAVE_STRUCT_SOCKADDR_VM case AF_VSOCK: { - struct sockaddr_vm *svm = (struct sockaddr_vm *) &h->connaddr; + struct sockaddr_vm *svm = (struct sockaddr_vm *)&h->connaddr;
uri.scheme = using_tls ? "nbds+vsock" : "nbd+vsock"; if (asprintf (&server, "%u:%u", svm->svm_cid, svm->svm_port) == -1) { @@ -543,7 +543,7 @@ nbd_unlocked_get_uri (struct nbd_handle *h) uri.query_raw = query_params;
/* Construct the final URI and return it. */ - ret = (char *) xmlSaveUri (&uri); + ret = (char *)xmlSaveUri (&uri); if (ret == NULL) set_error (errno, "xmlSaveUri failed"); out: diff --git a/lib/utils.c b/lib/utils.c index bce38df8..e3e13cdd 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -154,7 +154,7 @@ nbd_internal_set_querylist (struct nbd_handle *h, char **queries) const char * nbd_internal_fork_safe_itoa (long v, char *buf, size_t bufsize) { - unsigned long uv = (unsigned long) v; + unsigned long uv = (unsigned long)v; size_t i = bufsize - 1; bool neg = false;
@@ -282,7 +282,7 @@ nbd_internal_fork_safe_perror (const char *s) #endif #endif if (!m) - m = nbd_internal_fork_safe_itoa ((long) errno, buf, sizeof buf); + m = nbd_internal_fork_safe_itoa ((long)errno, buf, sizeof buf); xwritel (STDERR_FILENO, s, ": ", m, "\n", (char *)NULL);
/* Restore original errno in case it was disturbed by the system diff --git a/common/utils/test-vector.c b/common/utils/test-vector.c index 26ad5136..399f4f26 100644 --- a/common/utils/test-vector.c +++ b/common/utils/test-vector.c @@ -82,10 +82,10 @@ test_int64_vector (void) assert (v.ptr[1] == 2);
tmp = 10; - p = int64_vector_search (&v, &tmp, (void*) compare); + p = int64_vector_search (&v, &tmp, (void *)compare); assert (p == NULL); tmp = 8; - p = int64_vector_search (&v, &tmp, (void*) compare); + p = int64_vector_search (&v, &tmp, (void *)compare); assert (p == &v.ptr[7]);
free (v.ptr); diff --git a/python/handle.c b/python/handle.c index 2b04cdcd..8ff6ba81 100644 --- a/python/handle.c +++ b/python/handle.c @@ -46,7 +46,7 @@ static inline PyObject * put_handle (struct nbd_handle *h) { assert (h); - return PyCapsule_New ((void *) h, "nbd_handle", NULL); + return PyCapsule_New ((void *)h, "nbd_handle", NULL); }
PyObject * @@ -188,7 +188,7 @@ nbd_internal_py_aio_buffer_is_zero (PyObject *self, PyObject *args) "except -1 to mean to the end of the buffer"); goto out; } - else if ((size_t) offset + size > buf.len) { + else if ((size_t)offset + size > buf.len) { PyErr_SetString (PyExc_IndexError, "size out of range"); goto out; } diff --git a/python/utils.c b/python/utils.c index 27242f25..bf62f411 100644 --- a/python/utils.c +++ b/python/utils.c @@ -53,7 +53,7 @@ nbd_internal_py_get_string_list (PyObject *obj) "get_string_list: PyList_Size failure"); return NULL; } - len = (size_t) slen; + len = (size_t)slen; r = malloc (sizeof (char *) * (len+1)); if (r == NULL) { PyErr_NoMemory (); diff --git a/ocaml/nbd-c.h b/ocaml/nbd-c.h index f853c84a..0cbe36d1 100644 --- a/ocaml/nbd-c.h +++ b/ocaml/nbd-c.h @@ -49,7 +49,7 @@ static inline value caml_alloc_initialized_string (mlsize_t len, const char *p) { value sv = caml_alloc_string (len); - memcpy ((char *) String_val (sv), p, len); + memcpy ((char *)String_val (sv), p, len); return sv; } #endif @@ -70,7 +70,7 @@ extern void nbd_internal_ocaml_exception_in_wrapper (const char *, value); #define NBD_val(v) (*((struct nbd_handle **)Data_custom_val (v)))
static struct custom_operations libnbd_custom_operations = { - (char *) "libnbd_custom_operations", + (char *)"libnbd_custom_operations", nbd_internal_ocaml_handle_finalize, custom_compare_default, custom_hash_default, @@ -110,7 +110,7 @@ struct nbd_buffer { #define NBD_buffer_val(v) ((struct nbd_buffer *)Data_custom_val (v))
static struct custom_operations nbd_buffer_custom_operations = { - (char *) "nbd_buffer_custom_operations", + (char *)"nbd_buffer_custom_operations", nbd_internal_ocaml_buffer_finalize, custom_compare_default, custom_hash_default, diff --git a/tests/aio-connect-port.c b/tests/aio-connect-port.c index 05d33191..70138a80 100644 --- a/tests/aio-connect-port.c +++ b/tests/aio-connect-port.c @@ -87,7 +87,7 @@ main (int argc, char *argv[]) addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); addr.sin_port = htons (port);
- if (nbd_aio_connect (nbd, (struct sockaddr *) &addr, sizeof addr) == -1) { + if (nbd_aio_connect (nbd, (struct sockaddr *)&addr, sizeof addr) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/aio-connect.c b/tests/aio-connect.c index 1601ed0b..aac82179 100644 --- a/tests/aio-connect.c +++ b/tests/aio-connect.c @@ -85,7 +85,7 @@ main (int argc, char *argv[]) addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); addr.sin_port = htons (port);
- if (nbd_aio_connect (nbd, (struct sockaddr *) &addr, sizeof addr) == -1) { + if (nbd_aio_connect (nbd, (struct sockaddr *)&addr, sizeof addr) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-bad-cookie.c b/tests/errors-bad-cookie.c index c3de8c15..44479bdb 100644 --- a/tests/errors-bad-cookie.c +++ b/tests/errors-bad-cookie.c @@ -69,7 +69,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-oversize.c b/tests/errors-client-oversize.c index 8f0c039c..db701687 100644 --- a/tests/errors-client-oversize.c +++ b/tests/errors-client-oversize.c @@ -80,7 +80,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-unadvertised-cmd.c b/tests/errors-client-unadvertised-cmd.c index cd5a3e15..9dcd5766 100644 --- a/tests/errors-client-unadvertised-cmd.c +++ b/tests/errors-client-unadvertised-cmd.c @@ -80,7 +80,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-unaligned.c b/tests/errors-client-unaligned.c index ec996b71..e7c62fe8 100644 --- a/tests/errors-client-unaligned.c +++ b/tests/errors-client-unaligned.c @@ -80,7 +80,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-unknown-flags.c b/tests/errors-client-unknown-flags.c index 9d41de26..3399bbfd 100644 --- a/tests/errors-client-unknown-flags.c +++ b/tests/errors-client-unknown-flags.c @@ -73,7 +73,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-client-zerosize.c b/tests/errors-client-zerosize.c index 3ed170a7..69026324 100644 --- a/tests/errors-client-zerosize.c +++ b/tests/errors-client-zerosize.c @@ -73,7 +73,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-connect-null.c b/tests/errors-connect-null.c index e2542ff3..46114d0b 100644 --- a/tests/errors-connect-null.c +++ b/tests/errors-connect-null.c @@ -79,7 +79,7 @@ main (int argc, char *argv[]) } check (EFAULT, "nbd_connect_command: ");
- if (nbd_connect_command (nbd, (char **) cmd) != -1) { + if (nbd_connect_command (nbd, (char **)cmd) != -1) { fprintf (stderr, "%s: test failed: " "nbd_connect_command did not reject empty argv\n", argv[0]); diff --git a/tests/errors-connect-twice.c b/tests/errors-connect-twice.c index 496fb521..f8053fc9 100644 --- a/tests/errors-connect-twice.c +++ b/tests/errors-connect-twice.c @@ -69,11 +69,11 @@ main (int argc, char *argv[]) }
/* Connect to a working server, then try to connect again. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } - if (nbd_connect_command (nbd, (char **) cmd) != -1) { + if (nbd_connect_command (nbd, (char **)cmd) != -1) { fprintf (stderr, "%s: test failed: " "nbd_connect_command did not reject repeat attempt\n", argv[0]); diff --git a/tests/errors-multiple-disconnects.c b/tests/errors-multiple-disconnects.c index 13f30139..25309867 100644 --- a/tests/errors-multiple-disconnects.c +++ b/tests/errors-multiple-disconnects.c @@ -133,7 +133,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-not-negotiating.c b/tests/errors-not-negotiating.c index 2eed4181..7609de56 100644 --- a/tests/errors-not-negotiating.c +++ b/tests/errors-not-negotiating.c @@ -69,7 +69,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-notify-not-blocked.c b/tests/errors-notify-not-blocked.c index 93903946..306540b5 100644 --- a/tests/errors-notify-not-blocked.c +++ b/tests/errors-notify-not-blocked.c @@ -69,7 +69,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-pread-structured.c b/tests/errors-pread-structured.c index 946b14be..654d7b6d 100644 --- a/tests/errors-pread-structured.c +++ b/tests/errors-pread-structured.c @@ -95,7 +95,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-invalid-offset.c b/tests/errors-server-invalid-offset.c index 8ce7c814..dba1a7ff 100644 --- a/tests/errors-server-invalid-offset.c +++ b/tests/errors-server-invalid-offset.c @@ -101,7 +101,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-oversize.c b/tests/errors-server-oversize.c index 627d824b..c773ce29 100644 --- a/tests/errors-server-oversize.c +++ b/tests/errors-server-oversize.c @@ -117,7 +117,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-unadvertised-cmd.c b/tests/errors-server-unadvertised-cmd.c index d63043a1..44c266ac 100644 --- a/tests/errors-server-unadvertised-cmd.c +++ b/tests/errors-server-unadvertised-cmd.c @@ -108,7 +108,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-unaligned.c b/tests/errors-server-unaligned.c index a488570d..74cffaea 100644 --- a/tests/errors-server-unaligned.c +++ b/tests/errors-server-unaligned.c @@ -109,7 +109,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-unknown-flags.c b/tests/errors-server-unknown-flags.c index 38e1c080..d4946822 100644 --- a/tests/errors-server-unknown-flags.c +++ b/tests/errors-server-unknown-flags.c @@ -101,7 +101,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/errors-server-zerosize.c b/tests/errors-server-zerosize.c index 295e0b58..6011bbef 100644 --- a/tests/errors-server-zerosize.c +++ b/tests/errors-server-zerosize.c @@ -101,7 +101,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/opt-set-meta.c b/tests/opt-set-meta.c index 7f4656b9..1bd60a9c 100644 --- a/tests/opt-set-meta.c +++ b/tests/opt-set-meta.c @@ -219,7 +219,7 @@ main (int argc, char *argv[]) * or newer with its --no-sr kill switch. */ requires ("nbdkit --no-sr --help"); - args[ARRAY_SIZE (args) - 2] = (char *) "--no-sr"; + args[ARRAY_SIZE (args) - 2] = (char *)"--no-sr"; nbd = nbd_create (); if (nbd == NULL || nbd_set_opt_mode (nbd, true) == -1 || diff --git a/tests/opt-starttls.c b/tests/opt-starttls.c index 35668f17..ce966d81 100644 --- a/tests/opt-starttls.c +++ b/tests/opt-starttls.c @@ -97,7 +97,7 @@ do_test (const char *server_tls, struct expected exp) "--filter=tls-fallback", "pattern", "size=1M", "tlsreadme=fallback", NULL };
- if (nbd_connect_command (nbd, (char **) args) == -1) { + if (nbd_connect_command (nbd, (char **)args) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } @@ -163,7 +163,7 @@ main (int argc, char *argv[]) exit (77); } if (nbd_set_opt_mode (nbd, true) == -1 || - nbd_connect_command (nbd, (char **) args) == -1 || + nbd_connect_command (nbd, (char **)args) == -1 || nbd_opt_info (nbd) != -1 || nbd_opt_info (nbd) != -1 || nbd_aio_is_dead (nbd) == 1) { diff --git a/tests/opt-structured-twice.c b/tests/opt-structured-twice.c index 17fab1f2..3892436a 100644 --- a/tests/opt-structured-twice.c +++ b/tests/opt-structured-twice.c @@ -60,7 +60,7 @@ main (int argc, char *argv[]) /* Connect to the server in opt mode, without structured replies. */ if (nbd_set_opt_mode (nbd, true) == -1 || nbd_set_request_structured_replies (nbd, false) == -1 || - nbd_connect_command (nbd, (char **) cmd) == -1) { + nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/pread-initialize.c b/tests/pread-initialize.c index 585bf608..36d1aae2 100644 --- a/tests/pread-initialize.c +++ b/tests/pread-initialize.c @@ -71,7 +71,7 @@ main (int argc, char *argv[]) }
/* Connect to the server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/private-data.c b/tests/private-data.c index 734698c9..25d4cc5c 100644 --- a/tests/private-data.c +++ b/tests/private-data.c @@ -62,8 +62,8 @@ main (int argc, char *argv[]) assert (nbd_get_private_data (nbd1) == 43);
/* Check that (in C) we can store and retrieve a pointer. */ - nbd_set_private_data (nbd1, (uintptr_t) &nbd_close); - assert (nbd_get_private_data (nbd1) == (uintptr_t) &nbd_close); + nbd_set_private_data (nbd1, (uintptr_t)&nbd_close); + assert (nbd_get_private_data (nbd1) == (uintptr_t)&nbd_close);
nbd_close (nbd2); nbd_close (nbd1); diff --git a/tests/server-death.c b/tests/server-death.c index e65737a7..caf95572 100644 --- a/tests/server-death.c +++ b/tests/server-death.c @@ -66,7 +66,7 @@ main (int argc, char *argv[]) }
/* Connect to a slow server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/tests/shutdown-flags.c b/tests/shutdown-flags.c index bad638e9..4260425b 100644 --- a/tests/shutdown-flags.c +++ b/tests/shutdown-flags.c @@ -65,7 +65,7 @@ main (int argc, char *argv[]) }
/* Connect to a server. */ - if (nbd_connect_command (nbd, (char **) cmd) == -1) { + if (nbd_connect_command (nbd, (char **)cmd) == -1) { fprintf (stderr, "%s: %s\n", argv[0], nbd_get_error ()); exit (EXIT_FAILURE); } diff --git a/examples/glib-main-loop.c b/examples/glib-main-loop.c index 8403a970..38352683 100644 --- a/examples/glib-main-loop.c +++ b/examples/glib-main-loop.c @@ -79,7 +79,7 @@ events_from_nbd (struct nbd_handle *nbd) static gboolean prepare (GSource *sp, gint *timeout_) { - struct NBDSource *source = (struct NBDSource *) sp; + struct NBDSource *source = (struct NBDSource *)sp; int new_fd; int events;
@@ -89,13 +89,13 @@ prepare (GSource *sp, gint *timeout_) new_fd = nbd_aio_get_fd (source->nbd); if (source->fd != new_fd) { if (source->tag != NULL) { - g_source_remove_unix_fd ((GSource *) source, source->tag); + g_source_remove_unix_fd ((GSource *)source, source->tag); source->fd = -1; source->tag = NULL; } if (new_fd >= 0) { source->fd = new_fd; - source->tag = g_source_add_unix_fd ((GSource *) source, new_fd, 0); + source->tag = g_source_add_unix_fd ((GSource *)source, new_fd, 0); } }
@@ -103,7 +103,7 @@ prepare (GSource *sp, gint *timeout_) return FALSE;
events = events_from_nbd (source->nbd); - g_source_modify_unix_fd ((GSource *) source, source->tag, events); + g_source_modify_unix_fd ((GSource *)source, source->tag, events); *timeout_ = -1;
DEBUG (source, "prepare: events = 0x%x%s%s", @@ -125,14 +125,14 @@ prepare (GSource *sp, gint *timeout_) static gboolean check (GSource *sp) { - struct NBDSource *source = (struct NBDSource *) sp; + struct NBDSource *source = (struct NBDSource *)sp; unsigned dir; int revents;
if (!source->tag) return FALSE;
- revents = g_source_query_unix_fd ((GSource *) source, source->tag); + revents = g_source_query_unix_fd ((GSource *)source, source->tag); dir = nbd_aio_get_direction (source->nbd);
DEBUG (source, "check: direction = 0x%x%s%s, revents = 0x%x%s%s", @@ -156,11 +156,11 @@ dispatch (GSource *sp, GSourceFunc callback, gpointer user_data) { - struct NBDSource *source = (struct NBDSource *) sp; + struct NBDSource *source = (struct NBDSource *)sp; int revents; int r;
- revents = g_source_query_unix_fd ((GSource *) source, source->tag); + revents = g_source_query_unix_fd ((GSource *)source, source->tag);
DEBUG (source, "dispatch: revents = 0x%x%s%s", revents, @@ -184,7 +184,7 @@ dispatch (GSource *sp, static void finalize (GSource *sp) { - struct NBDSource *source = (struct NBDSource *) sp; + struct NBDSource *source = (struct NBDSource *)sp;
DEBUG (source, "finalize");
@@ -211,7 +211,7 @@ create_libnbd_gsource (struct nbd_handle *nbd) struct NBDSource *source;
source = - (struct NBDSource *) g_source_new (&nbd_source_funcs, sizeof *source); + (struct NBDSource *)g_source_new (&nbd_source_funcs, sizeof *source); source->nbd = nbd; source->debug = nbd_get_debug (nbd); source->fd = -1; @@ -297,19 +297,19 @@ main (int argc, char *argv[]) gssrc = create_libnbd_gsource (src); gsdest = create_libnbd_gsource (dest); loopctx = g_main_loop_get_context (loop); - g_source_attach ((GSource *) gssrc, loopctx); - g_source_attach ((GSource *) gsdest, loopctx); + g_source_attach ((GSource *)gssrc, loopctx); + g_source_attach ((GSource *)gsdest, loopctx);
/* Make sure we get called back when each handle connects. */ gssrc->connected_callback = connected; gsdest->connected_callback = connected;
/* Asynchronously start each handle connecting. */ - if (nbd_aio_connect_command (src, (char **) src_args) == -1) { + if (nbd_aio_connect_command (src, (char **)src_args) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } - if (nbd_aio_connect_command (dest, (char **) dest_args) == -1) { + if (nbd_aio_connect_command (dest, (char **)dest_args) == -1) { fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } @@ -482,11 +482,11 @@ finished_write (void *vp, int *error) */ if (finished && nr_buffers == 0) { DEBUG (gsdest, "finished_write: all finished"); - g_source_remove (g_source_get_id ((GSource *) gssrc)); - g_source_unref ((GSource *) gssrc); + g_source_remove (g_source_get_id ((GSource *)gssrc)); + g_source_unref ((GSource *)gssrc); gssrc = NULL; - g_source_remove (g_source_get_id ((GSource *) gsdest)); - g_source_unref ((GSource *) gsdest); + g_source_remove (g_source_get_id ((GSource *)gsdest)); + g_source_unref ((GSource *)gsdest); gsdest = NULL; g_main_loop_quit (loop); } diff --git a/examples/open-qcow2.c b/examples/open-qcow2.c index 70ea9b37..dd5b7c74 100644 --- a/examples/open-qcow2.c +++ b/examples/open-qcow2.c @@ -34,7 +34,7 @@ main (int argc, const char *argv[]) */ char *args[] = { "qemu-nbd", "-f", "qcow2", - (char *) filename, + (char *)filename, NULL }; if (nbd_connect_systemd_socket_activation (nbd, diff --git a/interop/list-exports.c b/interop/list-exports.c index 8b15c815..26436cd6 100644 --- a/interop/list-exports.c +++ b/interop/list-exports.c @@ -75,7 +75,7 @@ append (void *opaque, const char *name, const char *description) static int compare_actuals (const void *vp1, const void *vp2) { - return strcmp (* (char * const *) vp1, * (char * const *) vp2); + return strcmp (*(char * const *)vp1, *(char * const *)vp2); }
static void diff --git a/copy/file-ops.c b/copy/file-ops.c index 710fc68a..4f2ce738 100644 --- a/copy/file-ops.c +++ b/copy/file-ops.c @@ -334,7 +334,7 @@ file_close (struct rw *rw) static void file_truncate (struct rw *rw, int64_t size) { - struct rw_file *rwf = (struct rw_file *) rw; + struct rw_file *rwf = (struct rw_file *)rw;
/* If the destination is an ordinary file then the original file * size doesn't matter. Truncate it to the source size. But @@ -420,7 +420,7 @@ file_synch_read (struct rw *rw, if (r == 0) return n;
- data = (char *) data + r; + data = (char *)data + r; offset += r; len -= r; n += r; @@ -450,7 +450,7 @@ file_synch_write (struct rw *rw, perror (rw->name); exit (EXIT_FAILURE); } - data = (char *) data + r; + data = (char *)data + r; offset += r; len -= r; } diff --git a/copy/main.c b/copy/main.c index 9c53842f..391c0c4f 100644 --- a/copy/main.c +++ b/copy/main.c @@ -290,7 +290,7 @@ main (int argc, char *argv[]) found1: connections = 1; /* multi-conn not supported */ src = - nbd_rw_create_subprocess ((const char **) &argv[optind+1], i-optind-1, + nbd_rw_create_subprocess ((const char **)&argv[optind+1], i-optind-1, false); optind = i+1; } @@ -315,7 +315,7 @@ main (int argc, char *argv[]) found2: connections = 1; /* multi-conn not supported */ dst = - nbd_rw_create_subprocess ((const char **) &argv[optind+1], i-optind-1, + nbd_rw_create_subprocess ((const char **)&argv[optind+1], i-optind-1, true); optind = i+1; } @@ -371,7 +371,7 @@ main (int argc, char *argv[]) #else t = 1; #endif - threads = (unsigned) t; + threads = (unsigned)t; }
if (synchronous) @@ -534,7 +534,7 @@ open_local (const char *filename, direction d) } if (S_ISREG (stat.st_mode)) /* Regular file. */ return file_create (filename, fd, - stat.st_size, (uint64_t) stat.st_blksize, false, d); + stat.st_size, (uint64_t)stat.st_blksize, false, d); else if (S_ISBLK (stat.st_mode)) { /* Block device. */ unsigned int blkioopt;
@@ -549,7 +549,7 @@ open_local (const char *filename, direction d) #endif
return file_create (filename, fd, - stat.st_size, (uint64_t) blkioopt, true, d); + stat.st_size, (uint64_t)blkioopt, true, d); } else { /* Probably stdin/stdout, a pipe or a socket. */ synchronous = true; /* Force synchronous mode for pipes. */ diff --git a/copy/nbd-ops.c b/copy/nbd-ops.c index 843b7c17..f3b3bed3 100644 --- a/copy/nbd-ops.c +++ b/copy/nbd-ops.c @@ -101,7 +101,7 @@ open_one_nbd_handle (struct rw_nbd *rwn)
case CREATE_SUBPROCESS: if (nbd_connect_systemd_socket_activation (nbd, - (char **) rwn->argv.ptr) + (char **)rwn->argv.ptr) == -1) { fprintf (stderr, "%s: %s: %s\n", prog, rwn->argv.ptr[0], nbd_get_error ()); @@ -189,7 +189,7 @@ nbd_rw_create_subprocess (const char **argv, size_t argc, direction d) static void nbd_ops_close (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; size_t i;
for (i = 0; i < rwn->handles.len; ++i) { @@ -208,7 +208,7 @@ nbd_ops_close (struct rw *rw) static void nbd_ops_flush (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; size_t i;
for (i = 0; i < rwn->handles.len; ++i) { @@ -222,7 +222,7 @@ nbd_ops_flush (struct rw *rw) static bool nbd_ops_is_read_only (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (rwn->handles.len > 0) return nbd_is_read_only (rwn->handles.ptr[0]); @@ -233,7 +233,7 @@ nbd_ops_is_read_only (struct rw *rw) static bool nbd_ops_can_extents (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (rwn->handles.len > 0) return nbd_can_meta_context (rwn->handles.ptr[0], "base:allocation"); @@ -244,7 +244,7 @@ nbd_ops_can_extents (struct rw *rw) static bool nbd_ops_can_multi_conn (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (rwn->handles.len > 0) return nbd_can_multi_conn (rwn->handles.ptr[0]); @@ -255,7 +255,7 @@ nbd_ops_can_multi_conn (struct rw *rw) static void nbd_ops_start_multi_conn (struct rw *rw) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; size_t i;
for (i = 1; i < connections; ++i) @@ -268,7 +268,7 @@ static size_t nbd_ops_synch_read (struct rw *rw, void *data, size_t len, uint64_t offset) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (len > rw->size - offset) len = rw->size - offset; @@ -287,7 +287,7 @@ static void nbd_ops_synch_write (struct rw *rw, const void *data, size_t len, uint64_t offset) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (nbd_pwrite (rwn->handles.ptr[0], data, len, offset, 0) == -1) { fprintf (stderr, "%s: %s\n", rw->name, nbd_get_error ()); @@ -299,7 +299,7 @@ static bool nbd_ops_synch_zero (struct rw *rw, uint64_t offset, uint64_t count, bool allocate) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (!rwn->can_zero) return false; @@ -317,7 +317,7 @@ nbd_ops_asynch_read (struct rw *rw, struct command *command, nbd_completion_callback cb) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (nbd_aio_pread (rwn->handles.ptr[command->worker->index], slice_ptr (command->slice), @@ -333,7 +333,7 @@ nbd_ops_asynch_write (struct rw *rw, struct command *command, nbd_completion_callback cb) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (nbd_aio_pwrite (rwn->handles.ptr[command->worker->index], slice_ptr (command->slice), @@ -348,7 +348,7 @@ static bool nbd_ops_asynch_zero (struct rw *rw, struct command *command, nbd_completion_callback cb, bool allocate) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
if (!rwn->can_zero) return false; @@ -367,7 +367,7 @@ nbd_ops_asynch_zero (struct rw *rw, struct command *command, static unsigned nbd_ops_in_flight (struct rw *rw, size_t index) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw;
/* Since the commands are auto-retired in the callbacks we don't * need to count "done" commands. @@ -379,7 +379,7 @@ static void nbd_ops_get_polling_fd (struct rw *rw, size_t index, int *fd, int *direction) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; struct nbd_handle *nbd;
nbd = rwn->handles.ptr[index]; @@ -402,7 +402,7 @@ nbd_ops_get_polling_fd (struct rw *rw, size_t index, static void nbd_ops_asynch_notify_read (struct rw *rw, size_t index) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (nbd_aio_notify_read (rwn->handles.ptr[index]) == -1) { fprintf (stderr, "%s: %s\n", rw->name, nbd_get_error ()); exit (EXIT_FAILURE); @@ -412,7 +412,7 @@ nbd_ops_asynch_notify_read (struct rw *rw, size_t index) static void nbd_ops_asynch_notify_write (struct rw *rw, size_t index) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; if (nbd_aio_notify_write (rwn->handles.ptr[index]) == -1) { fprintf (stderr, "%s: %s\n", rw->name, nbd_get_error ()); exit (EXIT_FAILURE); @@ -436,7 +436,7 @@ nbd_ops_get_extents (struct rw *rw, size_t index, uint64_t offset, uint64_t count, extent_list *ret) { - struct rw_nbd *rwn = (struct rw_nbd *) rw; + struct rw_nbd *rwn = (struct rw_nbd *)rw; extent_list exts = empty_vector; struct nbd_handle *nbd;
diff --git a/copy/pipe-ops.c b/copy/pipe-ops.c index 596f3fed..bd8b7645 100644 --- a/copy/pipe-ops.c +++ b/copy/pipe-ops.c @@ -51,7 +51,7 @@ pipe_create (const char *name, int fd) static void pipe_close (struct rw *rw) { - struct rw_pipe *rwp = (struct rw_pipe *) rw; + struct rw_pipe *rwp = (struct rw_pipe *)rw;
if (close (rwp->fd) == -1) { fprintf (stderr, "%s: close: %m\n", rw->name); @@ -96,7 +96,7 @@ static size_t pipe_synch_read (struct rw *rw, void *data, size_t len, uint64_t offset) { - struct rw_pipe *rwp = (struct rw_pipe *) rw; + struct rw_pipe *rwp = (struct rw_pipe *)rw; ssize_t r;
r = read (rwp->fd, data, len); @@ -111,7 +111,7 @@ static void pipe_synch_write (struct rw *rw, const void *data, size_t len, uint64_t offset) { - struct rw_pipe *rwp = (struct rw_pipe *) rw; + struct rw_pipe *rwp = (struct rw_pipe *)rw;
while (len > 0) { ssize_t r = write (rwp->fd, data, len); @@ -119,7 +119,7 @@ pipe_synch_write (struct rw *rw, perror (rw->name); exit (EXIT_FAILURE); } - data = (char *) data + r; + data = (char *)data + r; len -= r; } } diff --git a/dump/dump.c b/dump/dump.c index 3de24a12..b4aebe84 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -398,7 +398,7 @@ do_dump (void) /* Print the ASCII codes. */ printf ("%s", pipe); for (j = i; j < MIN (i+16, n); ++j) { - char c = (char) buffer[j]; + char c = (char)buffer[j]; if (isalnum (c)) { ansi_colour (ANSI_FG_BRIGHT_RED, stdout); printf ("%c", c); diff --git a/fuse/nbdfuse.c b/fuse/nbdfuse.c index d3eca256..491f6db8 100644 --- a/fuse/nbdfuse.c +++ b/fuse/nbdfuse.c @@ -109,7 +109,7 @@ fuse_help (const char *prog) { static struct fuse_operations null_operations; const char *tmp_argv[] = { prog, "--help", NULL }; - fuse_main (2, (char **) tmp_argv, &null_operations, NULL); + fuse_main (2, (char **)tmp_argv, &null_operations, NULL); exit (EXIT_SUCCESS); }
@@ -415,7 +415,7 @@ main (int argc, char *argv[]) handles_append (&nbd, h); /* reserved above, so can't fail */ } } - connections = (unsigned) nbd.len; + connections = (unsigned)nbd.len; if (verbose) fprintf (stderr, "nbdfuse: connections=%u\n", connections);
@@ -424,7 +424,7 @@ main (int argc, char *argv[]) fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } - size = (uint64_t) ssize; + size = (uint64_t)ssize;
/* If the remote NBD server is readonly, then act as if the '-r' * flag was given on the nbdfuse command line. @@ -481,7 +481,7 @@ main (int argc, char *argv[]) if (pidfile) { fp = fopen (pidfile, "w"); if (fp) { - fprintf (fp, "%ld", (long) getpid ()); + fprintf (fp, "%ld", (long)getpid ()); fclose (fp); } } diff --git a/fuse/operations.c b/fuse/operations.c index 6f6bee3a..2d0634dc 100644 --- a/fuse/operations.c +++ b/fuse/operations.c @@ -380,7 +380,7 @@ nbdfuse_read (const char *path, char *buf, struct fuse_file_info *fi) { DEBUG_OPERATION ("read", "path=%s, buf=%p, count=%zu, offset=%" PRIi64, - path, buf, count, (int64_t) offset); + path, buf, count, (int64_t)offset);
if (!file_mode && (path[0] != '/' || strcmp (path+1, filename) != 0)) return -ENOENT; @@ -396,7 +396,7 @@ nbdfuse_read (const char *path, char *buf,
CHECK_NBD_ASYNC_ERROR (nbd_aio_pread (h, buf, count, offset, cb, 0));
- return (int) count; + return (int)count; }
static int @@ -405,7 +405,7 @@ nbdfuse_write (const char *path, const char *buf, struct fuse_file_info *fi) { DEBUG_OPERATION ("write", "path=%s, buf=%p, count=%zu, offset=%" PRIi64, - path, buf, count, (int64_t) offset); + path, buf, count, (int64_t)offset);
/* Probably shouldn't happen because of nbdfuse_open check. */ if (readonly) @@ -425,7 +425,7 @@ nbdfuse_write (const char *path, const char *buf,
CHECK_NBD_ASYNC_ERROR (nbd_aio_pwrite (h, buf, count, offset, cb, 0));
- return (int) count; + return (int)count; }
static int @@ -460,7 +460,7 @@ nbdfuse_fallocate (const char *path, int mode, off_t offset, off_t len, { DEBUG_OPERATION ("fallocate", "path=%s, mode=%d, " "offset=%" PRIi64 ", len=%" PRIi64, - path, mode, (int64_t) offset, (int64_t) len); + path, mode, (int64_t)offset, (int64_t)len);
if (readonly) return -EACCES; diff --git a/ublk/nbdublk.c b/ublk/nbdublk.c index b079d577..b85ac609 100644 --- a/ublk/nbdublk.c +++ b/ublk/nbdublk.c @@ -347,7 +347,7 @@ main (int argc, char *argv[]) handles_append (&nbd, h); /* reserved above, so can't fail */ } } - connections = (unsigned) nbd.len; + connections = (unsigned)nbd.len;
/* Get the size and preferred block sizes. */ rs = nbd_get_size (nbd.ptr[0]); @@ -355,7 +355,7 @@ main (int argc, char *argv[]) fprintf (stderr, "%s\n", nbd_get_error ()); exit (EXIT_FAILURE); } - size = (uint64_t) rs; + size = (uint64_t)rs;
rs = nbd_get_block_size (nbd.ptr[0], LIBNBD_SIZE_MAXIMUM); if (rs <= 0 || rs > 64 * 1024 * 1024) diff --git a/ublk/tgt.c b/ublk/tgt.c index 77d39661..20971bdb 100644 --- a/ublk/tgt.c +++ b/ublk/tgt.c @@ -120,7 +120,7 @@ aio_submitter (struct ublksrv_aio_ctx *ctx, struct ublksrv_aio *req)
switch (op) { case UBLK_IO_OP_READ: - r = nbd_aio_pread (h, (void *) iod->addr, iod->nr_sectors << 9, + r = nbd_aio_pread (h, (void *)iod->addr, iod->nr_sectors << 9, iod->start_sector << 9, cb, 0); if (r == -1) { fprintf (stderr, "%s: %s\n", "nbdublk", nbd_get_error ()); @@ -132,7 +132,7 @@ aio_submitter (struct ublksrv_aio_ctx *ctx, struct ublksrv_aio *req) if (fua && can_fua) nbd_flags |= LIBNBD_CMD_FLAG_FUA;
- r = nbd_aio_pwrite (h, (const void *) iod->addr, iod->nr_sectors << 9, + r = nbd_aio_pwrite (h, (const void *)iod->addr, iod->nr_sectors << 9, iod->start_sector << 9, cb, nbd_flags); if (r == -1) { fprintf (stderr, "%s: %s\n", "nbdublk", nbd_get_error ()); -- 2.40.1
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
participants (3)
-
Eric Blake -
Laszlo Ersek -
Richard W.M. Jones