diff --git a/builder/index-parse.y b/builder/index-parse.y index ffc3f50f8..6dba255c0 100644 --- a/builder/index-parse.y +++ b/builder/index-parse.y @@ -157,7 +157,8 @@ emptylines: void yyerror (YYLTYPE * yylloc, yyscan_t scanner, struct parse_context *context, const char *msg) { - int has_suffix = context->error_suffix != NULL && context->error_suffix[0] != 0; + const int has_suffix = + context->error_suffix != NULL && context->error_suffix[0] != 0; fprintf (stderr, "%s%s%s%ssyntax error at line %d: %s%s%s\n", context->progname ? context->progname : "", diff --git a/builder/index-scan.l b/builder/index-scan.l index 71259136d..d4db826c5 100644 --- a/builder/index-scan.l +++ b/builder/index-scan.l @@ -82,7 +82,7 @@ extern void scanner_destroy (yyscan_t scanner); yylval->field->next = NULL; yylval->field->key = strndup (yytext, i); if (yytext[i] == '[') { - size_t j = strcspn (yytext+i+1, "]"); + const size_t j = strcspn (yytext+i+1, "]"); yylval->field->subkey = strndup (yytext+i+1, j); i += 1+j+1; } else { diff --git a/builder/pxzcat-c.c b/builder/pxzcat-c.c index fa9f6bf27..33923b532 100644 --- a/builder/pxzcat-c.c +++ b/builder/pxzcat-c.c @@ -110,7 +110,7 @@ virt_builder_pxzcat (value inputfilev, value outputfilev) pid = fork (); if (pid == -1) { - int err = errno; + const int err = errno; close (fd); unix_error (err, (char *) "fork", Nothing); } @@ -188,7 +188,7 @@ pxzcat (value filenamev, value outputfilev, unsigned nr_threads) */ ofd = open (String_val (outputfilev), O_WRONLY|O_CREAT|O_NOCTTY, 0644); if (ofd == -1) { - int err = errno; + const int err = errno; close (fd); unix_error (err, (char *) "open", outputfilev); } @@ -196,25 +196,25 @@ pxzcat (value filenamev, value outputfilev, unsigned nr_threads) guestfs_int_fadvise_random (ofd); if (ftruncate (ofd, 1) == -1) { - int err = errno; + const int err = errno; close (fd); unix_error (err, (char *) "ftruncate", outputfilev); } if (lseek (ofd, 0, SEEK_SET) == -1) { - int err = errno; + const int err = errno; close (fd); unix_error (err, (char *) "lseek", outputfilev); } if (write (ofd, "\0", 1) == -1) { - int err = errno; + const int err = errno; close (fd); unix_error (err, (char *) "write", outputfilev); } if (ftruncate (ofd, size) == -1) { - int err = errno; + const int err = errno; close (fd); unix_error (err, (char *) "ftruncate", outputfilev); } diff --git a/builder/yajl-c.c b/builder/yajl-c.c index 6b7594372..3c2402e42 100644 --- a/builder/yajl-c.c +++ b/builder/yajl-c.c @@ -49,7 +49,7 @@ convert_yajl_value (yajl_val val, int level) caml_invalid_argument ("too many levels of object/array nesting"); if (YAJL_IS_OBJECT (val)) { - size_t len = YAJL_GET_OBJECT(val)->len; + const size_t len = YAJL_GET_OBJECT(val)->len; size_t i; rv = caml_alloc (1, 3); lv = caml_alloc_tuple (len); @@ -63,7 +63,7 @@ convert_yajl_value (yajl_val val, int level) } Store_field (rv, 0, lv); } else if (YAJL_IS_ARRAY (val)) { - size_t len = YAJL_GET_ARRAY(val)->len; + const size_t len = YAJL_GET_ARRAY(val)->len; size_t i; rv = caml_alloc (1, 4); lv = caml_alloc_tuple (len); diff --git a/cat/ls.c b/cat/ls.c index 59cb914cf..282996f05 100644 --- a/cat/ls.c +++ b/cat/ls.c @@ -550,7 +550,7 @@ static int field; static void next_field (void) { - int c = csv ? ',' : ' '; + const int c = csv ? ',' : ' '; field++; if (field == 1) return; @@ -643,7 +643,8 @@ static void output_int64_size (int64_t size) { char buf[LONGEST_HUMAN_READABLE]; - int hopts = human_round_to_nearest|human_autoscale|human_base_1024|human_SI; + const int hopts = + human_round_to_nearest|human_autoscale|human_base_1024|human_SI; int r; next_field (); diff --git a/daemon/augeas.c b/daemon/augeas.c index ea1163f77..14cc0cf7c 100644 --- a/daemon/augeas.c +++ b/daemon/augeas.c @@ -31,7 +31,7 @@ #define FPRINTF_AUGEAS_ERROR(aug,fs,...) \ do { \ - int code = aug_error (aug); \ + const int code = aug_error (aug); \ if (code == AUG_ENOMEM) \ reply_with_error (fs ": augeas out of memory", ##__VA_ARGS__); \ else { \ diff --git a/daemon/available.c b/daemon/available.c index 1d0f5a069..977c4dead 100644 --- a/daemon/available.c +++ b/daemon/available.c @@ -40,7 +40,7 @@ do_internal_feature_available (const char *group) for (i = 0; optgroups[i].group != NULL; ++i) { if (STREQ (group, optgroups[i].group)) { - int av = optgroups[i].available (); + const int av = optgroups[i].available (); return av ? 0 : 1; } } @@ -122,7 +122,8 @@ filesystem_available (const char *filesystem) int do_filesystem_available (const char *filesystem) { - size_t i, len = strlen (filesystem); + size_t i; + const size_t len = strlen (filesystem); int r; for (i = 0; i < len; ++i) { diff --git a/daemon/base64.c b/daemon/base64.c index 3f7a63054..3468c3342 100644 --- a/daemon/base64.c +++ b/daemon/base64.c @@ -35,7 +35,7 @@ GUESTFSD_EXT_CMD(str_base64, base64); static int write_cb (void *fd_ptr, const void *buf, size_t len) { - int fd = *(int *)fd_ptr; + const int fd = *(int *)fd_ptr; return xwrite (fd, buf, len); } diff --git a/daemon/btrfs.c b/daemon/btrfs.c index 811194d37..711f7ebfb 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -152,8 +152,8 @@ do_mkfs_btrfs (char *const *devices, int leafsize, const char *label, const char *metadata, int nodesize, int sectorsize) { - size_t nr_devices = count_strings (devices); - size_t MAX_ARGS = nr_devices + 64; + const size_t nr_devices = count_strings (devices); + const size_t MAX_ARGS = nr_devices + 64; const char *argv[MAX_ARGS]; size_t i = 0, j; int r; @@ -500,7 +500,7 @@ do_btrfs_subvolume_list (const mountable_t *fs) guestfs_int_btrfssubvolume_list *ret = NULL; - size_t nr_subvolumes = count_strings (lines); + const size_t nr_subvolumes = count_strings (lines); ret = malloc (sizeof *ret); if (!ret) { @@ -733,8 +733,8 @@ int do_btrfs_device_add (char *const *devices, const char *fs) { static int btrfs_device_add_needs_force = -1; - size_t nr_devices = count_strings (devices); - size_t MAX_ARGS = nr_devices + 8; + const size_t nr_devices = count_strings (devices); + const size_t MAX_ARGS = nr_devices + 8; const char *argv[MAX_ARGS]; size_t i = 0, j; CLEANUP_FREE char *fs_buf = NULL; @@ -781,12 +781,12 @@ do_btrfs_device_add (char *const *devices, const char *fs) int do_btrfs_device_delete (char *const *devices, const char *fs) { - size_t nr_devices = count_strings (devices); + const size_t nr_devices = count_strings (devices); if (nr_devices == 0) return 0; - size_t MAX_ARGS = nr_devices + 8; + const size_t MAX_ARGS = nr_devices + 8; const char *argv[MAX_ARGS]; size_t i = 0, j; CLEANUP_FREE char *fs_buf = NULL; @@ -882,7 +882,7 @@ btrfs_set_uuid (const char *device, const char *uuid) { CLEANUP_FREE char *err = NULL; int r; - int has_uuid_opts = test_btrfstune_uuid_opt (); + const int has_uuid_opts = test_btrfstune_uuid_opt (); if (has_uuid_opts <= 0) NOT_SUPPORTED (-1, "btrfs filesystems' UUID cannot be changed"); @@ -902,7 +902,7 @@ btrfs_set_uuid_random (const char *device) { CLEANUP_FREE char *err = NULL; int r; - int has_uuid_opts = test_btrfstune_uuid_opt (); + const int has_uuid_opts = test_btrfstune_uuid_opt (); if (has_uuid_opts <= 0) NOT_SUPPORTED (-1, "btrfs filesystems' UUID cannot be changed"); @@ -1353,7 +1353,7 @@ do_btrfs_qgroup_show (const char *path) const size_t MAX_ARGS = 64; const char *argv[MAX_ARGS]; size_t i = 0; - int has_raw_opt = test_btrfs_qgroup_show_raw_opt (); + const int has_raw_opt = test_btrfs_qgroup_show_raw_opt (); CLEANUP_FREE char *path_buf = NULL; CLEANUP_FREE char *err = NULL; CLEANUP_FREE char *out = NULL; @@ -1391,7 +1391,7 @@ do_btrfs_qgroup_show (const char *path) * 0/5 9249849344 9249849344 * */ - size_t nr_qgroups = count_strings (lines) - 2; + const size_t nr_qgroups = count_strings (lines) - 2; guestfs_int_btrfsqgroup_list *ret = NULL; ret = malloc (sizeof *ret); if (!ret) { @@ -2124,7 +2124,7 @@ int do_btrfs_image (char *const *sources, const char *image, int compresslevel) { - size_t nr_sources = count_strings (sources); + const size_t nr_sources = count_strings (sources); const size_t MAX_ARGS = 64 + nr_sources; const char *argv[MAX_ARGS]; size_t i = 0, j; @@ -2324,7 +2324,7 @@ btrfs_minimum_size (const char *path) CLEANUP_FREE char *buf = NULL, *err = NULL, *out = NULL; int64_t ret = 0; int r; - int min_size_supported = test_btrfs_min_dev_size (); + const int min_size_supported = test_btrfs_min_dev_size (); if (min_size_supported == -1) return -1; diff --git a/daemon/cleanups.c b/daemon/cleanups.c index 5293ff23d..092e493d7 100644 --- a/daemon/cleanups.c +++ b/daemon/cleanups.c @@ -55,7 +55,7 @@ cleanup_unlink_free (void *ptr) void cleanup_close (void *ptr) { - int fd = * (int *) ptr; + const int fd = * (int *) ptr; if (fd >= 0) close (fd); diff --git a/daemon/command.c b/daemon/command.c index 01df28ac7..5bd79dfc8 100644 --- a/daemon/command.c +++ b/daemon/command.c @@ -217,9 +217,10 @@ commandrvf (char **stdoutput, char **stderror, unsigned flags, { size_t so_size = 0, se_size = 0; int so_fd[2], se_fd[2]; - unsigned flag_copy_stdin = flags & COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN; - int flag_copy_fd = (int) (flags & COMMAND_FLAG_FD_MASK); - unsigned flag_out_on_err = flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR; + const unsigned flag_copy_stdin = + flags & COMMAND_FLAG_CHROOT_COPY_FILE_TO_STDIN; + const int flag_copy_fd = (int) (flags & COMMAND_FLAG_FD_MASK); + const unsigned flag_out_on_err = flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR; pid_t pid; int r, quit, i; fd_set rset, rset2; diff --git a/daemon/copy.c b/daemon/copy.c index 2a6720bef..4fbf599dc 100644 --- a/daemon/copy.c +++ b/daemon/copy.c @@ -48,7 +48,7 @@ copy (const char *src, const char *src_display, int flags, int64_t srcoffset, int64_t destoffset, int64_t size, int sparse) { - int64_t saved_size = size; + const int64_t saved_size = size; int src_fd, dest_fd; CLEANUP_FREE char *buf = NULL; size_t n; diff --git a/daemon/daemon.h b/daemon/daemon.h index 994b47a3a..771698156 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -377,7 +377,7 @@ is_zero (const char *buffer, size_t size) #define CHROOT_IN \ do { \ if (sysroot_len > 0) { \ - int __old_errno = errno; \ + const int __old_errno = errno; \ if (chroot (sysroot) == -1) \ perror ("CHROOT_IN: sysroot"); \ errno = __old_errno; \ @@ -386,7 +386,7 @@ is_zero (const char *buffer, size_t size) #define CHROOT_OUT \ do { \ if (sysroot_len > 0) { \ - int __old_errno = errno; \ + const int __old_errno = errno; \ if (chroot (".") == -1) \ perror ("CHROOT_OUT: ."); \ errno = __old_errno; \ @@ -414,7 +414,7 @@ is_zero (const char *buffer, size_t size) /* Calls reply_with_error, but includes the Augeas error details. */ #define AUGEAS_ERROR(fs,...) \ do { \ - int code = aug_error (aug); \ + const int code = aug_error (aug); \ if (code == AUG_ENOMEM) \ reply_with_error (fs ": augeas out of memory", ##__VA_ARGS__); \ else { \ diff --git a/daemon/debug.c b/daemon/debug.c index da4cfc8be..c646be754 100644 --- a/daemon/debug.c +++ b/daemon/debug.c @@ -436,7 +436,7 @@ debug_ldd (const char *subcmd, size_t argc, char *const *const argv) static char * debug_ls (const char *subcmd, size_t argc, char *const *const argv) { - size_t len = count_strings (argv); + const size_t len = count_strings (argv); CLEANUP_FREE const char **cargv = NULL; size_t i; int r; @@ -469,7 +469,7 @@ debug_ls (const char *subcmd, size_t argc, char *const *const argv) static char * debug_ll (const char *subcmd, size_t argc, char *const *const argv) { - size_t len = count_strings (argv); + const size_t len = count_strings (argv); CLEANUP_FREE const char **cargv = NULL; size_t i; int r; @@ -675,7 +675,7 @@ debug_spew (const char *subcmd, size_t argc, char *const *const argv) static int write_cb (void *fd_ptr, const void *buf, size_t len) { - int fd = *(int *)fd_ptr; + const int fd = *(int *)fd_ptr; return xwrite (fd, buf, len); } @@ -900,7 +900,7 @@ do_debug_upload (const char *filename, int mode) int fd = open (filename, O_WRONLY|O_CREAT|O_TRUNC|O_NOCTTY|O_CLOEXEC, mode); if (fd == -1) { - int err = errno; + const int err = errno; cancel_receive (); errno = err; reply_with_perror ("%s", filename); @@ -909,7 +909,7 @@ do_debug_upload (const char *filename, int mode) int r = receive_file (write_cb, &fd); if (r == -1) { /* write error */ - int err = errno; + const int err = errno; cancel_receive (); errno = err; reply_with_error ("write error: %s", filename); @@ -972,7 +972,7 @@ do_internal_rhbz914931 (int count) r = receive_file (crash_cb, &count); if (r == -1) { /* write error */ - int err = errno; + const int err = errno; cancel_receive (); errno = err; reply_with_error ("write error"); diff --git a/daemon/fallocate.c b/daemon/fallocate.c index f98babfb2..3b573a3ea 100644 --- a/daemon/fallocate.c +++ b/daemon/fallocate.c @@ -53,7 +53,7 @@ do_fallocate64 (const char *path, int64_t len) } #ifdef HAVE_POSIX_FALLOCATE - int err = posix_fallocate (fd, 0, len); + const int err = posix_fallocate (fd, 0, len); if (err != 0) { errno = err; reply_with_perror ("%s", path); diff --git a/daemon/file.c b/daemon/file.c index 35f41d3d0..1ef78e402 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -201,7 +201,7 @@ do_write_file (const char *path, const char *content, int size) /* Note content_len must be small because of the limits on protocol * message size. */ - int content_len = (int) strlen (content); + const int content_len = (int) strlen (content); if (size == 0) size = content_len; @@ -455,8 +455,8 @@ do_file (const char *path) { CLEANUP_FREE char *buf = NULL; const char *display_path = path; - - int is_dev = STRPREFIX (path, "/dev/"); + const int is_dev = STRPREFIX (path, "/dev/"); + struct stat statbuf; if (!is_dev) { buf = sysroot_path (path); @@ -469,7 +469,6 @@ do_file (const char *path) /* For non-dev, check this is a regular file, else just return the * file type as a string (RHBZ#582484). */ - struct stat statbuf; if (lstat (path, &statbuf) == -1) { reply_with_perror ("lstat: %s", display_path); return NULL; diff --git a/daemon/fill.c b/daemon/fill.c index 2d19df5db..d4f0ab2b6 100644 --- a/daemon/fill.c +++ b/daemon/fill.c @@ -86,7 +86,7 @@ do_fill (int c, int len, const char *path) int do_fill_pattern (const char *pattern, int len, const char *path) { - size_t patlen = strlen (pattern); + const size_t patlen = strlen (pattern); if (patlen < 1) { reply_with_error ("pattern string must be non-empty"); @@ -97,7 +97,7 @@ do_fill_pattern (const char *pattern, int len, const char *path) reply_with_error ("%d: length is < 0", len); return -1; } - size_t len_sz = (size_t) len; + const size_t len_sz = (size_t) len; int fd; CHROOT_IN; @@ -112,7 +112,7 @@ do_fill_pattern (const char *pattern, int len, const char *path) /* XXX This implementation won't be very efficient for large files. */ size_t n = 0; while (n < len_sz) { - size_t wrlen = len_sz - n < patlen ? len_sz - n : patlen; + const size_t wrlen = len_sz - n < patlen ? len_sz - n : patlen; if (xwrite (fd, pattern, wrlen) == -1) { reply_with_perror ("write: %s", path); close (fd); diff --git a/daemon/find.c b/daemon/find.c index b47caa887..604d3bfb9 100644 --- a/daemon/find.c +++ b/daemon/find.c @@ -113,7 +113,7 @@ do_find0 (const char *dir) * we'll need to modify the code to handle it. XXX */ while ((r = input_to_nul (fp, str, GUESTFS_MAX_CHUNK_SIZE)) > 0) { - size_t len = strlen (str); + const size_t len = strlen (str); if (len <= sysrootdirlen) continue; diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 03d8f0abb..bd3f7de7c 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -424,7 +424,7 @@ char * sysroot_path (const char *path) { char *r; - size_t len = strlen (path) + sysroot_len + 1; + const size_t len = strlen (path) + sysroot_len + 1; r = malloc (len); if (r == NULL) diff --git a/daemon/inotify.c b/daemon/inotify.c index 277c94c1a..74c895b1d 100644 --- a/daemon/inotify.c +++ b/daemon/inotify.c @@ -364,7 +364,7 @@ do_inotify_files (void) } while (fgets (buf, sizeof buf, fp) != NULL) { - size_t len = strlen (buf); + const size_t len = strlen (buf); if (len > 0 && buf[len-1] == '\n') buf[len-1] = '\0'; diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c index 619523901..44045b3ef 100644 --- a/daemon/lvm-filter.c +++ b/daemon/lvm-filter.c @@ -251,7 +251,7 @@ make_filter_strings (char *const *devices) * for whole block devices: * "a|^/dev/sda$|", "a|^/dev/sda[0-9]|", */ - size_t slen = strlen (devices[i]); + const size_t slen = strlen (devices[i]); if (add_sprintf (&ret, "a|^%s$|", devices[i]) == -1) return NULL; diff --git a/daemon/lvm.c b/daemon/lvm.c index d3892fe77..d4909adfb 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -255,7 +255,7 @@ do_lvs (void) char *out; CLEANUP_FREE char *err = NULL; int r; - int has_S = test_lvs_has_S_opt (); + const int has_S = test_lvs_has_S_opt (); if (has_S < 0) return NULL; diff --git a/daemon/md.c b/daemon/md.c index 66e695ab9..3f31529e2 100644 --- a/daemon/md.c +++ b/daemon/md.c @@ -132,7 +132,7 @@ do_md_create (const char *name, char *const *devices, return -1; } - size_t MAX_ARGS = nrdevices + 16; + const size_t MAX_ARGS = nrdevices + 16; const char *argv[MAX_ARGS]; size_t i = 0; @@ -231,7 +231,7 @@ do_list_md_devices (void) /* Look for directories under /sys/block matching md[0-9]* * As an additional check, we also make sure they have a md subdirectory. */ - int err = glob (PREFIX "[0-9]*" SUFFIX, GLOB_ERR, glob_errfunc, &mds); + const int err = glob (PREFIX "[0-9]*" SUFFIX, GLOB_ERR, glob_errfunc, &mds); if (err == GLOB_NOSPACE) { reply_with_error ("glob: returned GLOB_NOSPACE: " "rerun with LIBGUESTFS_DEBUG=1"); diff --git a/daemon/mkfs.c b/daemon/mkfs.c index a0617a074..f7509bfcb 100644 --- a/daemon/mkfs.c +++ b/daemon/mkfs.c @@ -117,11 +117,11 @@ do_mkfs (const char *fstype, const char *device, int blocksize, * have to determine the block device sector size in order to do * this. */ - int ss = do_blockdev_getss (device); + const int ss = do_blockdev_getss (device); if (ss == -1) return -1; - int sectors_per_cluster = blocksize / ss; + const int sectors_per_cluster = blocksize / ss; if (sectors_per_cluster < 1 || sectors_per_cluster > 128) { reply_with_error ("unsupported cluster size for %s filesystem (requested cluster size = %d, sector size = %d, trying sectors per cluster = %d)", fstype, blocksize, ss, sectors_per_cluster); diff --git a/daemon/mount.c b/daemon/mount.c index 4c83403f5..f2aedfd11 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -351,8 +351,8 @@ compare_longest_first (const void *vp1, const void *vp2) { char * const *p1 = (char * const *) vp1; char * const *p2 = (char * const *) vp2; - int n1 = strlen (*p1); - int n2 = strlen (*p2); + const int n1 = strlen (*p1); + const int n2 = strlen (*p2); return n2 - n1; } diff --git a/daemon/ntfsclone.c b/daemon/ntfsclone.c index f04017c77..ac061e6ce 100644 --- a/daemon/ntfsclone.c +++ b/daemon/ntfsclone.c @@ -59,7 +59,7 @@ read_error_file (char *error_file) static int write_cb (void *fd_ptr, const void *buf, size_t len) { - int fd = *(int *)fd_ptr; + const int fd = *(int *)fd_ptr; return xwrite (fd, buf, len); } diff --git a/daemon/parted.c b/daemon/parted.c index 00ae424ad..68ca1b609 100644 --- a/daemon/parted.c +++ b/daemon/parted.c @@ -303,7 +303,7 @@ get_table_field (const char *line, int n) return NULL; } - size_t len = strcspn (p, ":;"); + const size_t len = strcspn (p, ":;"); char *q = strndup (p, len); if (q == NULL) { reply_with_perror ("strndup"); @@ -681,7 +681,7 @@ sgdisk_info_extract_field (const char *device, int partnum, const char *field, return NULL; } - int fieldlen = strlen (field); + const int fieldlen = strlen (field); /* Parse the output of sgdisk -i: * Partition GUID code: 21686148-6449-6E6F-744E-656564454649 (BIOS boot partition) @@ -739,7 +739,7 @@ static char * extract_uuid (const char *value) { /* The value contains only valid GUID characters */ - size_t value_len = strspn (value, "-0123456789ABCDEF"); + const size_t value_len = strspn (value, "-0123456789ABCDEF"); char *ret = malloc (value_len + 1); if (ret == NULL) { diff --git a/daemon/proto.c b/daemon/proto.c index 654dd3a0d..696aa2f09 100644 --- a/daemon/proto.c +++ b/daemon/proto.c @@ -593,8 +593,8 @@ send_chunk (const guestfs_chunk *chunk) xdr_u_int (&xdr, &len); xdr_destroy (&xdr); - int err = (xwrite (sock, lenbuf, 4) == 0 - && xwrite (sock, buf, len) == 0 ? 0 : -1); + const int err = (xwrite (sock, lenbuf, 4) == 0 + && xwrite (sock, buf, len) == 0 ? 0 : -1); if (err) error (EXIT_FAILURE, 0, "send_chunk: write failed"); @@ -722,7 +722,7 @@ pulse_mode_end (void) void pulse_mode_cancel (void) { - int err = errno; /* Function must preserve errno. */ + const int err = errno; /* Function must preserve errno. */ struct itimerval it; struct sigaction act; @@ -752,7 +752,7 @@ static void async_safe_send_pulse (int sig) { /* XDR is a RFC ... */ - unsigned char msg[] = { + const unsigned char msg[] = { (GUESTFS_PROGRESS_FLAG & 0xff000000) >> 24, (GUESTFS_PROGRESS_FLAG & 0x00ff0000) >> 16, (GUESTFS_PROGRESS_FLAG & 0x0000ff00) >> 8, diff --git a/daemon/tar.c b/daemon/tar.c index 6d0403a40..c5d9524de 100644 --- a/daemon/tar.c +++ b/daemon/tar.c @@ -127,7 +127,7 @@ read_error_file (char *error_file) static int write_cb (void *fd_ptr, const void *buf, size_t len) { - int fd = *(int *)fd_ptr; + const int fd = *(int *)fd_ptr; return xwrite (fd, buf, len); } diff --git a/daemon/tsk.c b/daemon/tsk.c index 2d0ea832d..dd368d71a 100644 --- a/daemon/tsk.c +++ b/daemon/tsk.c @@ -56,7 +56,8 @@ do_internal_filesystem_walk (const mountable_t *mountable) int ret = -1; TSK_FS_INFO *fs = NULL; TSK_IMG_INFO *img = NULL; /* Used internally by tsk_fs_dir_walk */ - int flags = TSK_FS_DIR_WALK_FLAG_ALLOC | TSK_FS_DIR_WALK_FLAG_UNALLOC | + const int flags = + TSK_FS_DIR_WALK_FLAG_ALLOC | TSK_FS_DIR_WALK_FLAG_UNALLOC | TSK_FS_DIR_WALK_FLAG_RECURSE | TSK_FS_DIR_WALK_FLAG_NOORPHAN; ret = open_filesystem (mountable->device, &img, &fs); diff --git a/daemon/upload.c b/daemon/upload.c index aeb730666..f034627d4 100644 --- a/daemon/upload.c +++ b/daemon/upload.c @@ -186,7 +186,7 @@ do_download (const char *filename) } total = statbuf.st_size; } else { - int64_t size = do_blockdev_getsize64 (filename); + const int64_t size = do_blockdev_getsize64 (filename); if (size == -1) { /* do_blockdev_getsize64 has already sent a reply. */ close (fd); diff --git a/daemon/zero.c b/daemon/zero.c index c54575350..1b2ddf75a 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -137,7 +137,7 @@ do_wipefs (const char *device) int do_zero_device (const char *device) { - int64_t ssize = do_blockdev_getsize64 (device); + const int64_t ssize = do_blockdev_getsize64 (device); if (ssize == -1) return -1; uint64_t size = (uint64_t) ssize; diff --git a/df/output.c b/df/output.c index b9bbcb6bd..eed7f384d 100644 --- a/df/output.c +++ b/df/output.c @@ -97,7 +97,8 @@ print_stat (FILE *fp, const char *cols[4]; int64_t factor, v; float percent; - int hopts = human_round_to_nearest|human_autoscale|human_base_1024|human_SI; + const int hopts = + human_round_to_nearest|human_autoscale|human_base_1024|human_SI; size_t i, len; char *dev; diff --git a/diff/diff.c b/diff/diff.c index 72f197f6f..2ac71eb5e 100644 --- a/diff/diff.c +++ b/diff/diff.c @@ -510,7 +510,7 @@ visit_entry (const char *dir, const char *name, i = t->nr_files++; if (i >= t->allocated) { struct file *old_files = t->files; - size_t old_allocated = t->allocated; + const size_t old_allocated = t->allocated; /* Number of entries in an F15 guest was 111524, and in a * Windows guest was 10709. @@ -561,7 +561,7 @@ diff_guests (struct tree *t1, struct tree *t2) while (i1 < end1 || i2 < end2) { if (i1 < end1 && i2 < end2) { - int comp = strcmp (i1->path, i2->path); + const int comp = strcmp (i1->path, i2->path); /* i1->path < i2->path. i1 catches up with i2 (files deleted) */ if (comp < 0) { @@ -575,11 +575,11 @@ diff_guests (struct tree *t1, struct tree *t2) } /* Otherwise i1->path == i2->path, compare in detail. */ else { - int st = compare_stats (i1, i2); + const int st = compare_stats (i1, i2); if (st != 0) changed (t1->g, i1, t2->g, i2, st, 0); else if (i1->csum && i2->csum) { - int cst = strcmp (i1->csum, i2->csum); + const int cst = strcmp (i1->csum, i2->csum); changed (t1->g, i1, t2->g, i2, 0, cst); } i1++; @@ -824,7 +824,7 @@ static int field; static void next_field (void) { - int c = csv ? ',' : ' '; + const int c = csv ? ',' : ' '; field++; if (field == 1) return; @@ -980,7 +980,8 @@ static void output_int64_size (int64_t size) { char buf[LONGEST_HUMAN_READABLE]; - int hopts = human_round_to_nearest|human_autoscale|human_base_1024|human_SI; + const int hopts = + human_round_to_nearest|human_autoscale|human_base_1024|human_SI; int r; next_field (); diff --git a/erlang/erl-guestfs-proto.c b/erlang/erl-guestfs-proto.c index 24295ef68..f82823697 100644 --- a/erlang/erl-guestfs-proto.c +++ b/erlang/erl-guestfs-proto.c @@ -163,8 +163,8 @@ write_reply (ETERM *term) int atom_equals (ETERM *atom, const char *name) { - size_t namelen = strlen (name); - size_t atomlen = ERL_ATOM_SIZE (atom); + const size_t namelen = strlen (name); + const size_t atomlen = ERL_ATOM_SIZE (atom); if (namelen != atomlen) return 0; return strncmp (ERL_ATOM_PTR (atom), name, atomlen) == 0; } diff --git a/examples/mount-local.c b/examples/mount-local.c index ce12ffe9b..f9b421283 100644 --- a/examples/mount-local.c +++ b/examples/mount-local.c @@ -141,7 +141,7 @@ main (int argc, char *argv[]) /* Set a magic prompt. We only know how to do this for bash. */ p = strrchr (shell, '/'); if (p && strcmp (p+1, "bash") == 0) { - size_t len = 64 + strlen (shell); + const size_t len = 64 + strlen (shell); char *buf; buf = malloc (len); diff --git a/fish/copy.c b/fish/copy.c index f522950a5..7472e6f2c 100644 --- a/fish/copy.c +++ b/fish/copy.c @@ -50,7 +50,7 @@ run_copy_in (const char *cmd, size_t argc, char *argv[]) if (remote == NULL) return -1; - int nr_locals = argc-1; + const int nr_locals = argc-1; /* Upload each local one at a time using copy-in. */ int i; @@ -74,7 +74,7 @@ run_copy_out (const char *cmd, size_t argc, char *argv[]) /* Local directory is always the last arg. */ const char *local = argv[argc-1]; - int nr_remotes = argc-1; + const int nr_remotes = argc-1; /* Download each remote one at a time using copy-out. */ int i, r; diff --git a/fish/destpaths.c b/fish/destpaths.c index 868f5a42b..622c8d7d9 100644 --- a/fish/destpaths.c +++ b/fish/destpaths.c @@ -198,8 +198,10 @@ complete_dest_paths_generator (const char *text, int state) if (dirents->val[i].ftyp == 'u' || dirents->val[i].ftyp == 'l' || dirents->val[i].ftyp == '?') { - int is_dir = guestfs_is_dir_opts (g, words[nr_words].name, - GUESTFS_IS_DIR_OPTS_FOLLOWSYMLINKS, 1, -1); + const int is_dir = + guestfs_is_dir_opts (g, words[nr_words].name, + GUESTFS_IS_DIR_OPTS_FOLLOWSYMLINKS, + 1, -1); words[nr_words].is_dir = is_dir; } else words[nr_words].is_dir = dirents->val[i].ftyp == 'd'; @@ -245,7 +247,7 @@ complete_dest_paths_generator (const char *text, int state) if (cic_var && STREQ (cic_var, "off")) cic = 0; - int matches = + const int matches = cic ? STRCASEEQLEN (word->name, text, len) : STREQLEN (word->name, text, len); diff --git a/fish/fish.c b/fish/fish.c index 2ce2039ce..302b52f44 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -666,7 +666,7 @@ static void script (int prompt) { char *buf; - int global_exit_on_error = !prompt; + const int global_exit_on_error = !prompt; int exit_on_error; struct parsed_command pcmd; @@ -799,7 +799,7 @@ parse_command_line (char *buf, int *exit_on_error_rtn) * popen(3), read the result and execute it as guestfish commands. */ if (buf[0] == '<' && buf[1] == '!') { - int r = execute_and_inline (&buf[2], *exit_on_error_rtn); + const int r = execute_and_inline (&buf[2], *exit_on_error_rtn); if (r == -1) pcmd.status = -1; else @@ -1369,7 +1369,7 @@ parse_string_list (const char *str) } /* Grow the token to accommodate the fragment */ - size_t tok_end = tok_len; + const size_t tok_end = tok_len; tok_len += end - p; char *tok_new = realloc (tok, tok_len + 1); if (NULL == tok_new) { @@ -1542,7 +1542,7 @@ static char * decode_ps1 (const char *str) { char *ret; - size_t len = strlen (str); + const size_t len = strlen (str); size_t i, j; /* Result string is always smaller than the input string. This will @@ -1867,7 +1867,7 @@ file_in_heredoc (const char *endmarker) while (fgets (buffer, BUFSIZ, stdin) != NULL) { /* Look for "END" or "END\n" in input. */ - size_t blen = strlen (buffer); + const size_t blen = strlen (buffer); if (STREQLEN (buffer, endmarker, markerlen) && (blen == markerlen || (blen == markerlen+1 && buffer[markerlen] == '\n'))) diff --git a/fish/prep-boot.c b/fish/prep-boot.c index 45a5a8f11..7a6150ed0 100644 --- a/fish/prep-boot.c +++ b/fish/prep-boot.c @@ -44,7 +44,7 @@ prep_postlaunch_bootroot (const char *filename, prep_data *data, const char *dev if (parse_size (data->params[3], &bootsize) == -1) prep_error (data, filename, _("could not parse boot size")); - int sector = guestfs_blockdev_getss (g, device); + const int sector = guestfs_blockdev_getss (g, device); if (sector == -1) prep_error (data, filename, _("failed to get sector size of disk: %s"), guestfs_last_error (g)); @@ -94,7 +94,7 @@ prep_postlaunch_bootrootlv (const char *filename, prep_data *data, const char *d if (parse_size (data->params[4], &bootsize) == -1) prep_error (data, filename, _("could not parse boot size")); - int sector = guestfs_blockdev_getss (g, device); + const int sector = guestfs_blockdev_getss (g, device); if (sector == -1) prep_error (data, filename, _("failed to get sector size of disk: %s"), guestfs_last_error (g)); diff --git a/fish/progress.c b/fish/progress.c index f684a66d4..20c15eab4 100644 --- a/fish/progress.c +++ b/fish/progress.c @@ -332,7 +332,7 @@ progress_bar_set (struct progress_bar *bar, fprintf (fp, "%s --- ", spinner (bar, bar->count)); } else if (ratio < 1) { - int percent = 100.0 * ratio; + const int percent = 100.0 * ratio; fprintf (fp, "%s%3d%% ", spinner (bar, bar->count), percent); } else { @@ -351,7 +351,7 @@ progress_bar_set (struct progress_bar *bar, fputs (s_open, fp); if (!pulse_mode) { - size_t dots = ratio * (double) (cols - COLS_OVERHEAD); + const size_t dots = ratio * (double) (cols - COLS_OVERHEAD); for (i = 0; i < dots; ++i) fputs (s_dot, fp); @@ -360,7 +360,7 @@ progress_bar_set (struct progress_bar *bar, } else { /* "Pulse mode": the progress bar just pulses. */ for (i = 0; i < cols - COLS_OVERHEAD; ++i) { - int cc = (bar->count * 3 - i) % (cols - COLS_OVERHEAD); + const int cc = (bar->count * 3 - i) % (cols - COLS_OVERHEAD); if (cc >= 0 && cc <= 3) fputs (s_dot, fp); else @@ -376,21 +376,21 @@ progress_bar_set (struct progress_bar *bar, if (estimate >= 100.0 * 60.0 * 60.0 /* >= 100 hours */) { /* Display hours */ estimate /= 60. * 60.; - int hh = floor (estimate); + const int hh = floor (estimate); fprintf (fp, ">%dh", hh); } else if (estimate >= 100.0 * 60.0 /* >= 100 minutes */) { /* Display hoursminutes */ estimate /= 60. * 60.; - int hh = floor (estimate); + const int hh = floor (estimate); double ignore; - int mm = floor (modf (estimate, &ignore) * 60.); + const int mm = floor (modf (estimate, &ignore) * 60.); fprintf (fp, "%02dh%02d", hh, mm); } else if (estimate >= 0.0) { /* Display minutes:seconds */ estimate /= 60.; - int mm = floor (estimate); + const int mm = floor (estimate); double ignore; - int ss = floor (modf (estimate, &ignore) * 60.); + const int ss = floor (modf (estimate, &ignore) * 60.); fprintf (fp, "%02d:%02d", mm, ss); } else /* < 0 means estimate was not meaningful */ diff --git a/fish/supported.c b/fish/supported.c index 4beb63f99..26b9a786e 100644 --- a/fish/supported.c +++ b/fish/supported.c @@ -47,14 +47,14 @@ run_supported (const char *cmd, size_t argc, char *argv[]) size_t i; size_t len = 0; for (i = 0; groups[i] != NULL; ++i) { - size_t l = strlen (groups[i]); + const size_t l = strlen (groups[i]); if (l > len) len = l; } for (i = 0; groups[i] != NULL; ++i) { char *gg[] = { groups[i], NULL }; - int r = guestfs_available (g, gg); + const int r = guestfs_available (g, gg); const char *str = r == 0 ? _("yes") : _("no"); printf ("%*s %s\n", (int) len, groups[i], str); diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 330805889..dccc7ba6d 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -53,7 +53,7 @@ static int write_pid_file (const char *pid_file, pid_t pid); static void fuse_opt_add_opt_escaped (char **opts, const char *opt) { - unsigned oldlen = *opts ? strlen(*opts) : 0; + const unsigned oldlen = *opts ? strlen(*opts) : 0; char *d = realloc (*opts, oldlen + 1 + strlen(opt) * 2 + 1); if (!d) diff --git a/generator/daemon.ml b/generator/daemon.ml index 31ca76435..d8dc9cfb2 100644 --- a/generator/daemon.ml +++ b/generator/daemon.ml @@ -118,7 +118,7 @@ and generate_daemon_actions () = } \\ (path_out) = device_name_translation ((path)); \\ if ((path_out) == NULL) { \\ - int err = errno; \\ + const int err = errno; \\ cancel_stmt; \\ errno = err; \\ reply_with_perror (\"%%s: %%s\", __func__, path); \\ diff --git a/generator/lua.ml b/generator/lua.ml index 53c207272..89a8afd48 100644 --- a/generator/lua.ml +++ b/generator/lua.ml @@ -643,7 +643,7 @@ get_handle (lua_State *L, int index) static char ** get_string_list (lua_State *L, int index) { - size_t len = lua_objlen (L, index); + const size_t len = lua_objlen (L, index); size_t i; char **strs; @@ -786,8 +786,7 @@ get_event_bitmask (lua_State *L, int index) static uint64_t get_event (lua_State *L, int index) { - int r = luaL_checkoption (L, index, NULL, event_all); - + const int r = luaL_checkoption (L, index, NULL, event_all); return UINT64_C(1) << r; } diff --git a/generator/ruby.ml b/generator/ruby.ml index 0f71cccb2..fb0003bfe 100644 --- a/generator/ruby.ml +++ b/generator/ruby.ml @@ -295,7 +295,7 @@ delete_event_callback (VALUE gv, VALUE event_handlev) { guestfs_h *g; char key[64]; - int eh = NUM2INT (event_handlev); + const int eh = NUM2INT (event_handlev); VALUE *root; Data_Get_Struct (gv, guestfs_h, g); diff --git a/mllib/getopt-c.c b/mllib/getopt-c.c index 2d1a47e85..29845f6a9 100644 --- a/mllib/getopt-c.c +++ b/mllib/getopt-c.c @@ -249,7 +249,7 @@ guestfs_int_mllib_getopt_parse (value argsv, value specsv, value anon_funv, valu for (j = 0; j < len; ++j) { const char *key = String_val (Field (keysv, j)); - size_t key_len = strlen (key); + const size_t key_len = strlen (key); int has_arg = 0; /* We assume that the key is valid, with the checks done in the diff --git a/mllib/progress-c.c b/mllib/progress-c.c index 8e5efd368..9162e4fd2 100644 --- a/mllib/progress-c.c +++ b/mllib/progress-c.c @@ -61,7 +61,7 @@ guestfs_int_mllib_progress_bar_init (value machine_readablev) CAMLparam1 (machine_readablev); CAMLlocal1 (barv); struct progress_bar *bar; - int machine_readable = Bool_val (machine_readablev); + const int machine_readable = Bool_val (machine_readablev); unsigned flags = 0; /* XXX Have to do this to get nl_langinfo to work properly. However diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c index edb4646c4..16d57321c 100644 --- a/ocaml/guestfs-c.c +++ b/ocaml/guestfs-c.c @@ -256,7 +256,7 @@ guestfs_int_ocaml_delete_event_callback (value gv, value ehv) { CAMLparam2 (gv, ehv); char key[64]; - int eh = Int_val (ehv); + const int eh = Int_val (ehv); guestfs_h *g = Guestfs_val (gv); diff --git a/p2v/conversion.c b/p2v/conversion.c index 155c4d24a..e8f57412b 100644 --- a/p2v/conversion.c +++ b/p2v/conversion.c @@ -197,7 +197,7 @@ start_conversion (struct config *config, int ret = -1; int status; size_t i, len; - size_t nr_disks = guestfs_int_count_strings (config->disks); + const size_t nr_disks = guestfs_int_count_strings (config->disks); time_t now; struct tm tm; CLEANUP_FREE struct data_conn *data_conns = NULL; @@ -877,7 +877,7 @@ generate_libvirt_xml (struct config *config, struct data_conn *data_conns, config->interfaces[i]) == -1) error (EXIT_FAILURE, errno, "asprintf"); if (g_file_get_contents (mac_filename, &mac, NULL, NULL)) { - size_t len = strlen (mac); + const size_t len = strlen (mac); if (len > 0 && mac[len-1] == '\n') mac[len-1] = '\0'; diff --git a/p2v/miniexpect.c b/p2v/miniexpect.c index caf498dc1..d5a7c6e5d 100644 --- a/p2v/miniexpect.c +++ b/p2v/miniexpect.c @@ -345,7 +345,7 @@ mexp_expect (mexp_h *h, const mexp_regexp *regexps, int *ovector, int ovecsize) assert (h->buffer != NULL); for (i = 0; regexps[i].r > 0; ++i) { - int options = regexps[i].options | PCRE_PARTIAL_SOFT; + const int options = regexps[i].options | PCRE_PARTIAL_SOFT; r = pcre_exec (regexps[i].re, regexps[i].extra, h->buffer, (int)h->len, 0, diff --git a/src/appliance.c b/src/appliance.c index 5748af523..942ecae55 100644 --- a/src/appliance.c +++ b/src/appliance.c @@ -152,7 +152,7 @@ build_appliance (guestfs_h *g, return -1; if (r == 1) { - size_t len = strlen (path); + const size_t len = strlen (path); *kernel = safe_malloc (g, len + 6 /* "kernel" */ + 2); *initrd = safe_malloc (g, len + 6 /* "initrd" */ + 2); *appliance = safe_malloc (g, len + 4 /* "root" */ + 2); @@ -168,7 +168,7 @@ build_appliance (guestfs_h *g, return -1; if (r == 1) { - size_t len = strlen (path); + const size_t len = strlen (path); *kernel = safe_malloc (g, len + strlen (kernel_name) + 2); *initrd = safe_malloc (g, len + strlen (initrd_name) + 2); sprintf (*kernel, "%s/%s", path, kernel_name); @@ -272,11 +272,11 @@ run_supermin_build (guestfs_h *g, CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g); int r; #if 0 /* not supported in supermin 5 yet XXX */ - uid_t uid = getuid (); - uid_t euid = geteuid (); - gid_t gid = getgid (); - gid_t egid = getegid (); - int pass_u_g_args = uid != euid || gid != egid; + const uid_t uid = getuid (); + const uid_t euid = geteuid (); + const gid_t gid = getgid (); + const gid_t egid = getegid (); + const int pass_u_g_args = uid != euid || gid != egid; #endif guestfs_int_cmd_add_arg (cmd, SUPERMIN); diff --git a/src/conn-socket.c b/src/conn-socket.c index 624342b3b..4e1f78141 100644 --- a/src/conn-socket.c +++ b/src/conn-socket.c @@ -142,7 +142,7 @@ read_data (guestfs_h *g, struct connection *connv, void *bufv, size_t len) { char *buf = bufv; struct connection_socket *conn = (struct connection_socket *) connv; - size_t original_len = len; + const size_t original_len = len; if (conn->daemon_sock == -1) { error (g, _("read_data: socket not connected")); @@ -246,7 +246,7 @@ write_data (guestfs_h *g, struct connection *connv, { const char *buf = bufv; struct connection_socket *conn = (struct connection_socket *) connv; - size_t original_len = len; + const size_t original_len = len; if (conn->daemon_sock == -1) { error (g, _("write_data: socket not connected")); diff --git a/src/copy-in-out.c b/src/copy-in-out.c index 50831bec3..a4e39f8b3 100644 --- a/src/copy-in-out.c +++ b/src/copy-in-out.c @@ -42,7 +42,7 @@ guestfs_impl_copy_in (guestfs_h *g, int fd; int r; char fdbuf[64]; - size_t buf_len = strlen (localpath) + 1; + const size_t buf_len = strlen (localpath) + 1; CLEANUP_FREE char *buf = safe_malloc (g, buf_len); const char *dirname, *basename; struct stat statbuf; @@ -52,7 +52,7 @@ guestfs_impl_copy_in (guestfs_h *g, return -1; } - int remote_is_dir = guestfs_is_dir (g, remotedir); + const int remote_is_dir = guestfs_is_dir (g, remotedir); if (remote_is_dir == -1) return -1; @@ -152,7 +152,7 @@ guestfs_impl_copy_out (guestfs_h *g, if (r == 1) { /* is file */ CLEANUP_FREE char *filename = NULL; - size_t buf_len = strlen (remotepath) + 1; + const size_t buf_len = strlen (remotepath) + 1; CLEANUP_FREE char *buf = safe_malloc (g, buf_len); const char *basename; @@ -180,7 +180,7 @@ guestfs_impl_copy_out (guestfs_h *g, return -1; } - size_t buf_len = strlen (remotepath) + 1; + const size_t buf_len = strlen (remotepath) + 1; CLEANUP_FREE char *buf = safe_malloc (g, buf_len); const char *basename; if (split_path (g, buf, buf_len, remotepath, NULL, &basename) == -1) diff --git a/src/drives.c b/src/drives.c index 5e7eb1241..1e3b0af72 100644 --- a/src/drives.c +++ b/src/drives.c @@ -727,7 +727,7 @@ parse_servers (guestfs_h *g, char *const *strs, struct drive_server **servers_rtn) { size_t i; - size_t n = guestfs_int_count_strings (strs); + const size_t n = guestfs_int_count_strings (strs); struct drive_server *servers; if (n == 0) { diff --git a/src/errors.c b/src/errors.c index ee21dafd2..b1ef491e5 100644 --- a/src/errors.c +++ b/src/errors.c @@ -191,7 +191,7 @@ guestfs_int_perrorf (guestfs_h *g, const char *fs, ...) { va_list args; CLEANUP_FREE char *msg = NULL; - int errnum = errno; + const int errnum = errno; int err; char buf[256]; @@ -294,7 +294,7 @@ void guestfs_int_print_BufferIn (FILE *out, const char *buf, size_t buf_size) { size_t i; - size_t orig_size = buf_size; + const size_t orig_size = buf_size; if (buf_size > 256) buf_size = 256; @@ -392,7 +392,7 @@ void guestfs_int_external_command_failed (guestfs_h *g, int status, const char *cmd_name, const char *extra) { - size_t len = 80 + strlen (cmd_name); + const size_t len = 80 + strlen (cmd_name); CLEANUP_FREE char *status_string = safe_malloc (g, len); guestfs_int_exit_status_to_string (status, cmd_name, status_string, len); diff --git a/src/fuse.c b/src/fuse.c index cb8274fea..01de3a9e9 100644 --- a/src/fuse.c +++ b/src/fuse.c @@ -628,7 +628,7 @@ mount_local_utimens (const char *path, const struct timespec ts[2]) static int mount_local_open (const char *path, struct fuse_file_info *fi) { - int flags = fi->flags & O_ACCMODE; + const int flags = fi->flags & O_ACCMODE; DECL_G (); DEBUG_CALL ("%s, 0%o", path, (unsigned) fi->flags); diff --git a/src/handle.c b/src/handle.c index ee3c4d3b9..81a3cb1f2 100644 --- a/src/handle.c +++ b/src/handle.c @@ -302,7 +302,7 @@ static char * getenv_from_strings (const void *stringsv, const char *name) { char **strings = (char **) stringsv; - size_t len = strlen (name); + const size_t len = strlen (name); size_t i; for (i = 0; strings[i] != NULL; ++i) @@ -796,7 +796,7 @@ char * guestfs_impl_get_backend_setting (guestfs_h *g, const char *name) { char **settings = g->backend_settings; - size_t namelen = strlen (name); + const size_t namelen = strlen (name); size_t i; if (settings == NULL) @@ -820,7 +820,7 @@ int guestfs_impl_clear_backend_setting (guestfs_h *g, const char *name) { char **settings = g->backend_settings; - size_t namelen = strlen (name); + const size_t namelen = strlen (name); size_t i, j; int count = 0; diff --git a/src/inspect-apps.c b/src/inspect-apps.c index b8767c3c8..b377f57c7 100644 --- a/src/inspect-apps.c +++ b/src/inspect-apps.c @@ -844,7 +844,7 @@ list_applications_windows_from_path (guestfs_h *g, * http://nsis.sourceforge.net/Add_uninstall_information_to_Add/Remove_Programs#Optional_values */ for (i = 0; i < children->len; ++i) { - int64_t child = children->val[i].hivex_node_h; + const int64_t child = children->val[i].hivex_node_h; int64_t value; CLEANUP_FREE char *name = NULL, *display_name = NULL, *version = NULL, *install_path = NULL, *publisher = NULL, *url = NULL, *comments = NULL; diff --git a/src/inspect-fs-cd.c b/src/inspect-fs-cd.c index d8373f651..bb28c0fc7 100644 --- a/src/inspect-fs-cd.c +++ b/src/inspect-fs-cd.c @@ -349,7 +349,7 @@ check_isolinux_installer_root (guestfs_h *g, struct inspect_fs *fs) static void trim_cr (char *str) { - size_t n = strlen (str); + const size_t n = strlen (str); if (n > 0 && str[n-1] == '\r') str[n-1] = '\0'; } @@ -357,7 +357,7 @@ trim_cr (char *str) static void trim_quot (char *str) { - size_t n = strlen (str); + const size_t n = strlen (str); if (n > 0 && str[n-1] == '"') str[n-1] = '\0'; } diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c index 0e798bda4..cc0e6b1a0 100644 --- a/src/inspect-fs-unix.c +++ b/src/inspect-fs-unix.c @@ -351,13 +351,13 @@ parse_lsb_release (guestfs_h *g, struct inspect_fs *fs, const char *filename) else if (fs->product_name == NULL && (STRPREFIX (lines[i], "DISTRIB_DESCRIPTION=\"") || STRPREFIX (lines[i], "DISTRIB_DESCRIPTION='"))) { - size_t len = strlen (lines[i]) - 21 - 1; + const size_t len = strlen (lines[i]) - 21 - 1; fs->product_name = safe_strndup (g, &lines[i][21], len); r = 1; } else if (fs->product_name == NULL && STRPREFIX (lines[i], "DISTRIB_DESCRIPTION=")) { - size_t len = strlen (lines[i]) - 20; + const size_t len = strlen (lines[i]) - 20; fs->product_name = safe_strndup (g, &lines[i][20], len); r = 1; } @@ -1227,11 +1227,11 @@ check_hostname_freebsd (guestfs_h *g, struct inspect_fs *fs) for (i = 0; lines[i] != NULL; ++i) { if (STRPREFIX (lines[i], "hostname=\"") || STRPREFIX (lines[i], "hostname='")) { - size_t len = strlen (lines[i]) - 10 - 1; + const size_t len = strlen (lines[i]) - 10 - 1; fs->hostname = safe_strndup (g, &lines[i][10], len); break; } else if (STRPREFIX (lines[i], "hostname=")) { - size_t len = strlen (lines[i]) - 9; + const size_t len = strlen (lines[i]) - 9; fs->hostname = safe_strndup (g, &lines[i][9], len); break; } @@ -1394,7 +1394,7 @@ add_fstab_entry (guestfs_h *g, struct inspect_fs *fs, * Note these are further filtered by guestfs_inspect_get_mountpoints * and guestfs_inspect_get_filesystems. */ - size_t n = fs->nr_fstab + 1; + const size_t n = fs->nr_fstab + 1; struct inspect_fstab_entry *p; p = safe_realloc (g, fs->fstab, n * sizeof (struct inspect_fstab_entry)); @@ -1861,8 +1861,8 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map, * prefixed with vtbd. IDE hard drives used to be prefixed with ad and now * are with ada. */ - int disk_i = guestfs_int_parse_unsigned_int (g, disk); - int part_i = guestfs_int_parse_unsigned_int (g, part); + const int disk_i = guestfs_int_parse_unsigned_int (g, disk); + const int part_i = guestfs_int_parse_unsigned_int (g, part); free (type); free (disk); free (part); @@ -1877,8 +1877,8 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map, * numbered from 5 in Linux. I have no idea what happens when you * have multiple "slices" (the FreeBSD term for MBR partitions). */ - int disk_i = guestfs_int_parse_unsigned_int (g, disk); - int slice_i = guestfs_int_parse_unsigned_int (g, slice); + const int disk_i = guestfs_int_parse_unsigned_int (g, disk); + const int slice_i = guestfs_int_parse_unsigned_int (g, slice); int part_i = part[0] - 'a' /* counting from 0 */; free (type); free (disk); @@ -1897,7 +1897,7 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map, } else if ((os_type == OS_TYPE_NETBSD) && match3 (g, spec, re_netbsd_dev, &type, &disk, &part)) { - int disk_i = guestfs_int_parse_unsigned_int (g, disk); + const int disk_i = guestfs_int_parse_unsigned_int (g, disk); int part_i = part[0] - 'a'; /* counting from 0 */ free (type); free (disk); @@ -1914,7 +1914,7 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map, } else if ((os_type == OS_TYPE_OPENBSD) && match3 (g, spec, re_openbsd_dev, &type, &disk, &part)) { - int disk_i = guestfs_int_parse_unsigned_int (g, disk); + const int disk_i = guestfs_int_parse_unsigned_int (g, disk); int part_i = part[0] - 'a'; /* counting from 0 */ free (type); free (disk); @@ -1940,7 +1940,7 @@ resolve_fstab_device (guestfs_h *g, const char *spec, Hash_table *md_map, * Turn the disk number into a letter-based identifier, so * we can resolve it easily. */ - int disk_i = guestfs_int_parse_unsigned_int (g, disk); + const int disk_i = guestfs_int_parse_unsigned_int (g, disk); const char disk_as_letter[2] = { disk_i + 'a', 0 }; r = resolve_fstab_device_xdev (g, type, disk_as_letter, part, &device); free (type); diff --git a/src/inspect-fs-windows.c b/src/inspect-fs-windows.c index 8399a904b..c139051d0 100644 --- a/src/inspect-fs-windows.c +++ b/src/inspect-fs-windows.c @@ -301,7 +301,7 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs) values = guestfs_hivex_node_values (g, node); for (i = 0; i < values->len; ++i) { - int64_t value = values->val[i].hivex_value_h; + const int64_t value = values->val[i].hivex_value_h; CLEANUP_FREE char *key = guestfs_hivex_value_key (g, value); if (key == NULL) goto out; @@ -313,7 +313,7 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs) } else if (STRCASEEQ (key, "CurrentMajorVersionNumber")) { size_t vsize; - int64_t vtype = guestfs_hivex_value_type (g, value); + const int64_t vtype = guestfs_hivex_value_type (g, value); CLEANUP_FREE char *vbuf = guestfs_hivex_value_value (g, value, &vsize); if (vbuf == NULL) @@ -331,7 +331,7 @@ check_windows_software_registry (guestfs_h *g, struct inspect_fs *fs) } else if (STRCASEEQ (key, "CurrentMinorVersionNumber")) { size_t vsize; - int64_t vtype = guestfs_hivex_value_type (g, value); + const int64_t vtype = guestfs_hivex_value_type (g, value); CLEANUP_FREE char *vbuf = guestfs_hivex_value_value (g, value, &vsize); if (vbuf == NULL) @@ -471,7 +471,7 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) fs->drive_mappings = safe_calloc (g, 2*count + 1, sizeof (char *)); for (i = count = 0; i < values->len; ++i) { - int64_t v = values->val[i].hivex_value_h; + const int64_t v = values->val[i].hivex_value_h; CLEANUP_FREE char *key = guestfs_hivex_value_key (g, v); if (key == NULL) goto out; @@ -525,7 +525,7 @@ check_windows_system_registry (guestfs_h *g, struct inspect_fs *fs) goto out; for (i = 0; i < values2->len; ++i) { - int64_t v = values2->val[i].hivex_value_h; + const int64_t v = values2->val[i].hivex_value_h; CLEANUP_FREE char *key = guestfs_hivex_value_key (g, v); if (key == NULL) goto out; @@ -752,11 +752,12 @@ utf16_to_utf8 (/* const */ char *input, size_t len) char *inp = input; char *outp = out; - size_t r = iconv (ic, (ICONV_CONST char **) &inp, &inlen, &outp, &outlen); + const size_t r = + iconv (ic, (ICONV_CONST char **) &inp, &inlen, &outp, &outlen); if (r == (size_t) -1) { if (errno == E2BIG) { - int err = errno; - size_t prev = outalloc; + const int err = errno; + const size_t prev = outalloc; /* Try again with a larger output buffer. */ free (out); outalloc *= 2; @@ -769,7 +770,7 @@ utf16_to_utf8 (/* const */ char *input, size_t len) } else { /* Else some conversion failure, eg. EILSEQ, EINVAL. */ - int err = errno; + const int err = errno; iconv_close (ic); free (out); errno = err; diff --git a/src/inspect-fs.c b/src/inspect-fs.c index adda4abb1..5e5b00499 100644 --- a/src/inspect-fs.c +++ b/src/inspect-fs.c @@ -150,9 +150,9 @@ check_filesystem (guestfs_h *g, const char *mountable, fs->mountable = safe_strdup (g, mountable); /* Optimize some of the tests by avoiding multiple tests of the same thing. */ - int is_dir_etc = guestfs_is_dir (g, "/etc") > 0; - int is_dir_bin = guestfs_is_dir (g, "/bin") > 0; - int is_dir_share = guestfs_is_dir (g, "/share") > 0; + const int is_dir_etc = guestfs_is_dir (g, "/etc") > 0; + const int is_dir_bin = guestfs_is_dir (g, "/bin") > 0; + const int is_dir_share = guestfs_is_dir (g, "/share") > 0; /* Grub /boot? */ if (guestfs_is_file (g, "/grub/menu.lst") > 0 || @@ -324,7 +324,7 @@ check_filesystem (guestfs_h *g, const char *mountable, static void extend_fses (guestfs_h *g) { - size_t n = g->nr_fses + 1; + const size_t n = g->nr_fses + 1; struct inspect_fs *p; p = safe_realloc (g, g->fses, n * sizeof (struct inspect_fs)); @@ -412,7 +412,7 @@ int guestfs_int_parse_unsigned_int (guestfs_h *g, const char *str) { long ret; - int r = xstrtol (str, NULL, 10, &ret, ""); + const int r = xstrtol (str, NULL, 10, &ret, ""); if (r != LONGINT_OK) { error (g, _("could not parse integer in version number: %s"), str); return -1; @@ -425,7 +425,7 @@ int guestfs_int_parse_unsigned_int_ignore_trailing (guestfs_h *g, const char *str) { long ret; - int r = xstrtol (str, NULL, 10, &ret, NULL); + const int r = xstrtol (str, NULL, 10, &ret, NULL); if (r != LONGINT_OK) { error (g, _("could not parse integer in version number: %s"), str); return -1; diff --git a/src/launch.c b/src/launch.c index 5e6d1aa84..78bf46d71 100644 --- a/src/launch.c +++ b/src/launch.c @@ -337,7 +337,7 @@ guestfs_int_appliance_command_line (guestfs_h *g, const char *appliance_dev, snprintf (root, sizeof root, " root=%s", appliance_dev); if (tcg) { - int lpj = guestfs_int_get_lpj (g); + const int lpj = guestfs_int_get_lpj (g); if (lpj > 0) snprintf (lpj_s, sizeof lpj_s, " lpj=%d", lpj); } diff --git a/src/listfs.c b/src/listfs.c index de3b6f57f..88446cc9f 100644 --- a/src/listfs.c +++ b/src/listfs.c @@ -44,9 +44,9 @@ guestfs_impl_list_filesystems (guestfs_h *g) DECLARE_STRINGSBUF (ret); const char *lvm2[] = { "lvm2", NULL }; - int has_lvm2 = guestfs_feature_available (g, (char **) lvm2); + const int has_lvm2 = guestfs_feature_available (g, (char **) lvm2); const char *ldm[] = { "ldm", NULL }; - int has_ldm = guestfs_feature_available (g, (char **) ldm); + const int has_ldm = guestfs_feature_available (g, (char **) ldm); CLEANUP_FREE_STRING_LIST char **devices = NULL; CLEANUP_FREE_STRING_LIST char **partitions = NULL; @@ -169,7 +169,8 @@ check_with_vfs_type (guestfs_h *g, const char *device, struct stringsbuf *sb) if (vols == NULL) return -1; - int64_t default_volume = guestfs_btrfs_subvolume_get_default (g, device); + const int64_t default_volume = + guestfs_btrfs_subvolume_get_default (g, device); for (size_t i = 0; i < vols->len; i++) { struct guestfs_btrfssubvolume *this = &vols->val[i]; @@ -193,7 +194,7 @@ check_with_vfs_type (guestfs_h *g, const char *device, struct stringsbuf *sb) * for things which are members of some RAID or LVM set, most * importantly "LVM2_member" which is a PV. */ - size_t n = strlen (vfs_type); + const size_t n = strlen (vfs_type); if (n >= 7 && STREQ (&vfs_type[n-7], "_member")) return 0; diff --git a/src/match.c b/src/match.c index 41cc5f94a..149495987 100644 --- a/src/match.c +++ b/src/match.c @@ -33,7 +33,7 @@ int guestfs_int_match (guestfs_h *g, const char *str, const pcre *re) { - size_t len = strlen (str); + const size_t len = strlen (str); int vec[30], r; r = pcre_exec (re, NULL, str, len, 0, 0, vec, sizeof vec / sizeof vec[0]); @@ -50,7 +50,7 @@ guestfs_int_match (guestfs_h *g, const char *str, const pcre *re) char * guestfs_int_match1 (guestfs_h *g, const char *str, const pcre *re) { - size_t len = strlen (str); + const size_t len = strlen (str); int vec[30], r; r = pcre_exec (re, NULL, str, len, 0, 0, vec, sizeof vec / sizeof vec[0]); @@ -65,7 +65,7 @@ int guestfs_int_match2 (guestfs_h *g, const char *str, const pcre *re, char **ret1, char **ret2) { - size_t len = strlen (str); + const size_t len = strlen (str); int vec[30], r; r = pcre_exec (re, NULL, str, len, 0, 0, vec, 30); @@ -86,7 +86,7 @@ int guestfs_int_match3 (guestfs_h *g, const char *str, const pcre *re, char **ret1, char **ret2, char **ret3) { - size_t len = strlen (str); + const size_t len = strlen (str); int vec[30], r; r = pcre_exec (re, NULL, str, len, 0, 0, vec, 30); @@ -109,7 +109,7 @@ int guestfs_int_match4 (guestfs_h *g, const char *str, const pcre *re, char **ret1, char **ret2, char **ret3, char **ret4) { - size_t len = strlen (str); + const size_t len = strlen (str); int vec[30], r; r = pcre_exec (re, NULL, str, len, 0, 0, vec, 30); @@ -135,7 +135,7 @@ guestfs_int_match6 (guestfs_h *g, const char *str, const pcre *re, char **ret1, char **ret2, char **ret3, char **ret4, char **ret5, char **ret6) { - size_t len = strlen (str); + const size_t len = strlen (str); int vec[30], r; r = pcre_exec (re, NULL, str, len, 0, 0, vec, 30); diff --git a/src/osinfo.c b/src/osinfo.c index f4e2c7193..5887b2a1f 100644 --- a/src/osinfo.c +++ b/src/osinfo.c @@ -438,7 +438,7 @@ parse_version (guestfs_h *g, xmlNodePtr node, struct osinfo *osinfo) content = (char *) xmlNodeGetContent (node); if (content) { struct version version; - int res = guestfs_int_version_from_x_y (g, &version, content); + const int res = guestfs_int_version_from_x_y (g, &version, content); if (res < 0) return -1; else if (res > 0) { diff --git a/src/proto.c b/src/proto.c index cbf868047..32992d295 100644 --- a/src/proto.c +++ b/src/proto.c @@ -251,7 +251,7 @@ guestfs_int_send (guestfs_h *g, int proc_nr, struct guestfs_message_header hdr; XDR xdr; uint32_t len; - int serial = g->msg_next_serial++; + const int serial = g->msg_next_serial++; ssize_t r; CLEANUP_FREE char *msg_out = NULL; size_t msg_out_size; diff --git a/src/qemu.c b/src/qemu.c index 844c3f04c..c51133859 100644 --- a/src/qemu.c +++ b/src/qemu.c @@ -355,7 +355,8 @@ guestfs_int_qemu_supports_virtio_scsi (guestfs_h *g, struct qemu_data *data, char * guestfs_int_qemu_escape_param (guestfs_h *g, const char *param) { - size_t i, len = strlen (param); + size_t i; + const size_t len = strlen (param); char *p, *ret; ret = p = safe_malloc (g, len*2 + 1); /* max length of escaped name*/ diff --git a/src/unit-tests.c b/src/unit-tests.c index c754ddb60..06d4d2736 100644 --- a/src/unit-tests.c +++ b/src/unit-tests.c @@ -237,7 +237,7 @@ static void test_getumask (void) { guestfs_h *g; - int orig_umask = umask (0777); + const int orig_umask = umask (0777); g = guestfs_create (); assert (g); diff --git a/src/utils.c b/src/utils.c index a9d9ea90b..0b8962c0e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -73,7 +73,7 @@ guestfs_int_count_strings (char *const *argv) char ** guestfs_int_copy_string_list (char *const *argv) { - size_t n = guestfs_int_count_strings (argv); + const size_t n = guestfs_int_count_strings (argv); size_t i, j; char **ret; @@ -166,7 +166,8 @@ guestfs_int_join_strings (const char *sep, char *const *argv) char ** guestfs_int_split_string (char sep, const char *str) { - size_t i, n, c, len = strlen (str); + size_t i, n, c; + const size_t len = strlen (str); char reject[2] = { sep, '\0' }; char **ret; diff --git a/src/version.c b/src/version.c index 6796c2651..60ffe1e89 100644 --- a/src/version.c +++ b/src/version.c @@ -132,7 +132,7 @@ version_from_x_y_or_x (guestfs_h *g, struct version *v, const char *str, return 1; } else if (allow_only_x) { - int major_version = guestfs_int_parse_unsigned_int (g, str); + const int major_version = guestfs_int_parse_unsigned_int (g, str); if (major_version == -1) return -1; diff --git a/tests/c-api/tests-main.c b/tests/c-api/tests-main.c index e3af651dd..5db407e03 100644 --- a/tests/c-api/tests-main.c +++ b/tests/c-api/tests-main.c @@ -341,7 +341,7 @@ match_re (const char *str, const char *pattern) const char *err; int offset; pcre *re; - size_t len = strlen (str); + const size_t len = strlen (str); int vec[30], r; re = pcre_compile (pattern, 0, &err, &offset, NULL); diff --git a/tests/mount-local/test-parallel-mount-local.c b/tests/mount-local/test-parallel-mount-local.c index 873d20a99..37b2b3db1 100644 --- a/tests/mount-local/test-parallel-mount-local.c +++ b/tests/mount-local/test-parallel-mount-local.c @@ -277,7 +277,7 @@ start_thread (void *statevp) static void test_mountpoint (const char *mp) { - int nr_passes = 5 + (random () & 31); + const int nr_passes = 5 + (random () & 31); int pass; int ret = EXIT_FAILURE; FILE *fp; diff --git a/utils/qemu-speed-test/qemu-speed-test.c b/utils/qemu-speed-test/qemu-speed-test.c index f26d71c36..091959436 100644 --- a/utils/qemu-speed-test/qemu-speed-test.c +++ b/utils/qemu-speed-test/qemu-speed-test.c @@ -378,7 +378,8 @@ test_block_device (void) CLEANUP_FREE char **devices = NULL; char *r; const char *argv[4]; - int t = max_time_override > 0 ? max_time_override : TEST_BLOCK_DEVICE_TIME; + const int t = + max_time_override > 0 ? max_time_override : TEST_BLOCK_DEVICE_TIME; char tbuf[64]; int64_t bytes_written, bytes_read; diff --git a/v2v/domainxml-c.c b/v2v/domainxml-c.c index 06a93eb42..3b00cada4 100644 --- a/v2v/domainxml-c.c +++ b/v2v/domainxml-c.c @@ -240,7 +240,7 @@ v2v_dumpxml (value passwordv, value connv, value domnamev) * this is only appropriate for virt-v2v. (RHBZ#1138586) */ if (!is_test_uri) { - int state = get_dom_state (dom); + const int state = get_dom_state (dom); if (state == VIR_DOMAIN_RUNNING || state == VIR_DOMAIN_BLOCKED || diff --git a/v2v/xml-c.c b/v2v/xml-c.c index 0be5b0b63..0af3d8f11 100644 --- a/v2v/xml-c.c +++ b/v2v/xml-c.c @@ -239,7 +239,7 @@ v2v_xml_xpathobjptr_get_nodeptr (value xpathobjv, value iv) { CAMLparam2 (xpathobjv, iv); xmlXPathObjectPtr xpathobj = xpathobjptr_val (xpathobjv); - int i = Int_val (iv); + const int i = Int_val (iv); if (i < 0 || i >= xpathobj->nodesetval->nodeNr) caml_invalid_argument ("get_nodeptr: node number out of range");