[pacman-dev] [PATCH 2/2] More consistent printing of off_t and time_t

Dan McGee dpmcgee at gmail.com
Sun Nov 15 20:57:48 EST 2009


On Sat, Nov 14, 2009 at 1:30 PM, Xavier Chantry <shiningxc at gmail.com> wrote:
> %ld for type_t
What is type_t?

> %"PRId64" for off_t
Can you explain why this works for off_t?

It looks like we have three "rogue" types here to be concerned with-
time_t, size_t, and off_t. I'm not sure that removing all of the casts
was the right decision, but hopefully I can be learned if you point me
in the right direction.

>
> Signed-off-by: Xavier Chantry <shiningxc at gmail.com>
> ---
>  lib/libalpm/add.c      |    7 +++----
>  lib/libalpm/be_files.c |   12 ++++++------
>  lib/libalpm/delta.c    |    6 +++---
>  lib/libalpm/dload.c    |    4 ++--
>  lib/libalpm/sync.c     |    6 +++---
>  5 files changed, 17 insertions(+), 18 deletions(-)
>
> diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
> index ebcd6a5..05bb8d4 100644
> --- a/lib/libalpm/add.c
> +++ b/lib/libalpm/add.c
> @@ -28,8 +28,7 @@
>  #include <sys/types.h>
>  #include <sys/stat.h>
>  #include <unistd.h>
> -#include <inttypes.h> /* int64_t */
> -#include <stdint.h> /* intmax_t */
> +#include <inttypes.h> /* int64_t,PRId64 */
>
>  /* libarchive */
>  #include <archive.h>
> @@ -602,8 +601,8 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count,
>                                int64_t pos = archive_position_compressed(archive);
>                                percent = (double)pos / (double)newpkg->size;
>                                _alpm_log(PM_LOG_DEBUG, "decompression progress: "
> -                                               "%f%% (%"PRId64" / %jd)\n",
> -                                               percent*100.0, pos, (intmax_t)newpkg->size);
> +                                               "%f%% (%"PRId64" / %"PRId64")\n",
> +                                               percent*100.0, pos, newpkg->size);
>                                if(percent >= 1.0) {
>                                        percent = 1.0;
>                                }
> diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
> index 90e97a5..dc95bdb 100644
> --- a/lib/libalpm/be_files.c
> +++ b/lib/libalpm/be_files.c
> @@ -25,7 +25,7 @@
>  #include <stdlib.h>
>  #include <errno.h>
>  #include <string.h>
> -#include <stdint.h> /* uintmax_t, intmax_t */
> +#include <inttypes.h> /* PRId64 */
>  #include <sys/stat.h>
>  #include <dirent.h>
>  #include <ctype.h>
> @@ -697,11 +697,11 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
>                        }
>                        if(info->builddate) {
>                                fprintf(fp, "%%BUILDDATE%%\n"
> -                                                               "%ju\n\n", (uintmax_t)info->builddate);
> +                                                               "%ld\n\n", info->builddate);
>                        }
>                        if(info->installdate) {
>                                fprintf(fp, "%%INSTALLDATE%%\n"
> -                                                               "%ju\n\n", (uintmax_t)info->installdate);
> +                                                               "%ld\n\n", info->installdate);
>                        }
>                        if(info->packager) {
>                                fprintf(fp, "%%PACKAGER%%\n"
> @@ -710,7 +710,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
>                        if(info->isize) {
>                                /* only write installed size, csize is irrelevant once installed */
>                                fprintf(fp, "%%SIZE%%\n"
> -                                                               "%jd\n\n", (intmax_t)info->isize);
> +                                                               "%"PRId64"\n\n", info->isize);
>                        }
>                        if(info->reason) {
>                                fprintf(fp, "%%REASON%%\n"
> @@ -719,11 +719,11 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
>                } else {
>                        if(info->size) {
>                                fprintf(fp, "%%CSIZE%%\n"
> -                                                               "%jd\n\n", (intmax_t)info->size);
> +                                                               "%"PRId64"\n\n", info->size);
>                        }
>                        if(info->isize) {
>                                fprintf(fp, "%%ISIZE%%\n"
> -                                                               "%jd\n\n", (intmax_t)info->isize);
> +                                                               "%"PRId64"\n\n", info->isize);
>                        }
>                        if(info->md5sum) {
>                                fprintf(fp, "%%MD5SUM%%\n"
> diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
> index 523968e..fc4afd1 100644
> --- a/lib/libalpm/delta.c
> +++ b/lib/libalpm/delta.c
> @@ -22,7 +22,7 @@
>
>  #include <stdlib.h>
>  #include <string.h>
> -#include <stdint.h> /* intmax_t */
> +#include <inttypes.h> /* PRId64 */
>  #include <limits.h>
>  #include <sys/types.h>
>  #include <regex.h>
> @@ -238,7 +238,7 @@ off_t _alpm_shortest_delta_path(alpm_list_t *deltas,
>        dijkstra(vertices);
>        bestsize = shortest_path(vertices, to, &bestpath);
>
> -       _alpm_log(PM_LOG_DEBUG, "delta shortest-path search complete : '%jd'\n", (intmax_t)bestsize);
> +       _alpm_log(PM_LOG_DEBUG, "delta shortest-path search complete : '%"PRId64"'\n", bestsize);
>
>        alpm_list_free_inner(vertices, _alpm_graph_free);
>        alpm_list_free(vertices);
> @@ -297,7 +297,7 @@ pmdelta_t *_alpm_delta_parse(char *line)
>        tmp2 = tmp;
>        STRDUP(delta->to, tmp2, RET_ERR(PM_ERR_MEMORY, NULL));
>
> -       _alpm_log(PM_LOG_DEBUG, "delta : %s %s '%lld'\n", delta->from, delta->to, (long long)delta->delta_size);
> +       _alpm_log(PM_LOG_DEBUG, "delta : %s %s '%"PRId64"'\n", delta->from, delta->to, delta->delta_size);
>
>        return(delta);
>  }
> diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
> index 05555f2..717954f 100644
> --- a/lib/libalpm/dload.c
> +++ b/lib/libalpm/dload.c
> @@ -271,8 +271,8 @@ static int download_internal(const char *url, const char *localpath,
>
>        if (ust.size != -1 && dl_thisfile < ust.size) {
>                pm_errno = PM_ERR_RETRIEVE;
> -               _alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"),
> -                               filename, (intmax_t)dl_thisfile, (intmax_t)ust.size);
> +               _alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %"PRId64"/%"PRId64" bytes\n"),
> +                               filename, dl_thisfile, ust.size);
>                ret = -1;
>                goto cleanup;
>        }
> diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
> index 2cdcd47..e3155fc 100644
> --- a/lib/libalpm/sync.c
> +++ b/lib/libalpm/sync.c
> @@ -28,7 +28,7 @@
>  #include <stdio.h>
>  #include <fcntl.h>
>  #include <string.h>
> -#include <stdint.h> /* intmax_t */
> +#include <inttypes.h> /* PRId64 */
>  #include <unistd.h>
>  #include <time.h>
>  #include <dirent.h>
> @@ -389,8 +389,8 @@ static int compute_download_size(pmpkg_t *newpkg)
>                size = alpm_pkg_get_size(newpkg);
>        }
>
> -       _alpm_log(PM_LOG_DEBUG, "setting download size %jd for pkg %s\n",
> -                       (intmax_t)size, alpm_pkg_get_name(newpkg));
> +       _alpm_log(PM_LOG_DEBUG, "setting download size %"PRId64" for pkg %s\n",
> +                       size, alpm_pkg_get_name(newpkg));
>
>        newpkg->download_size = size;
>        return(0);
> --
> 1.6.5.2
>
>
>


More information about the pacman-dev mailing list