[pacman-dev] [PATCH 2/2] More consistent printing of off_t and time_t
%ld for type_t %"PRId64" for off_t Signed-off-by: Xavier Chantry <shiningxc@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
On Sat, Nov 14, 2009 at 1:30 PM, Xavier Chantry <shiningxc@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@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
On Mon, Nov 16, 2009 at 2:57 AM, Dan McGee <dpmcgee@gmail.com> wrote:
On Sat, Nov 14, 2009 at 1:30 PM, Xavier Chantry <shiningxc@gmail.com> wrote:
%ld for type_t What is type_t?
lol, I remember I had a bug when I typed (hmm) that. It was meant to be time_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.
I am not sure either. I looked again at various references : - man 3 printf - man types.h - man inttypes.h What about the following : time_t : %ld size_t : %zu ssize_t : %zd off_t : %jd or %"PRIdMAX" and cast to intmax_t For other long unsigned types (is there any?) : %ju or %"PRIuMAX" and cast to uintmax_t I checked netbsd, freebsd and osx man pages : they all document the z and j length modifier http://www.freebsd.org/cgi/man.cgi?query=printf&sektion=3&apropos=0&manpath=FreeBSD+7.2-RELEASE http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPag... http://netbsd.gw.com/cgi-bin/man-cgi?printf+3+NetBSD-current For cygwin, the man page I found inside this tarball does not document it : http://cygwin.elite-systems.org/release/cygwin-doc/cygwin-doc-1.4-4.tar.bz2 But we are already using j and z in the current code and it did not cause any problems. So my final proposal : time_t : %ld size_t : %zu ssize_t : %zd off_t : %jd and cast to intmax_t other long unsigned types : %ju and cast to uintmax_t
participants (3)
-
Dan McGee
-
Xavier
-
Xavier Chantry