On Thu, Nov 12, 2009 at 9:09 AM, Dan McGee <dan@archlinux.org> wrote:
+ _alpm_log(PM_LOG_DEBUG, "ust.size: %ld local_size: %ld compare: %ld\n", + ust.size, local_size, local_size - ust.size);
+ } else if(fileurl->offset) { + _alpm_log(PM_LOG_DEBUG, "resuming download at position %ld\n", fileurl->offset); }
This does not compile here : dload.c:190: error: format '%ld' expects type 'long int', but argument 3 has type 'off_t' dload.c:190: error: format '%ld' expects type 'long int', but argument 4 has type 'off_t' dload.c:190: error: format '%ld' expects type 'long int', but argument 5 has type 'off_t' dload.c:223: error: format '%ld' expects type 'long int', but argument 3 has type 'off_t' I am always confused about this stuff, so I looked at one older patch : http://code.toofishes.net/cgit/dan/pacman.git/commit/?id=0669c9bfac7aead01f1400444e691d542f7645c2&ss=1 But this was confusing too. It looks like the same patch used three different ways to print off_t : 1 - %jd and cast to intmax_t 2 - %ju and cast to intmax_t 3 - %lld and cast to long long After looking at man types.h and man printf, it seems off_t is a signed integer, like intmax_t So 1 seems alright but maybe 3 is alright too ? googling a bit leads to a lot of different and confusing answers. But it seems the most correct and portable way is to use a macro for the printf format : %" PRId64 " http://mail-index.netbsd.org/tech-misc/2003/01/20/0002.html http://stackoverflow.com/questions/586928/how-should-i-print-types-like-offt... It looks like PRId64 is defined in #include <inttypes.h> But dload.c does not have this include and it still works. Maybe it's included by another header ? How do I find out ? Should we add #include <inttypes.h> anyway ? diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 683f514..05555f2 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -186,7 +186,7 @@ static int download_internal(const char *url, const char *localpath, _alpm_log(PM_LOG_DEBUG, "ust.mtime: %ld local_time: %ld compare: %ld\n", ust.mtime, local_time, local_time - ust.mtime); - _alpm_log(PM_LOG_DEBUG, "ust.size: %ld local_size: %ld compare: %ld\n", + _alpm_log(PM_LOG_DEBUG, "ust.size: %"PRId64" local_size: %"PRId64" compare: %"PRId64"\n", ust.size, local_size, local_size - ust.size); if(!force && ust.mtime && ust.mtime == local_time && ust.size && ust.size == local_size) { @@ -220,7 +220,7 @@ static int download_internal(const char *url, const char *localpath, fclose(localf); localf = NULL; } else if(fileurl->offset) { - _alpm_log(PM_LOG_DEBUG, "resuming download at position %ld\n", fileurl->offset); + _alpm_log(PM_LOG_DEBUG, "resuming download at position %"PRId64"\n", fileurl->offset); }