FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 11-14-2009, 06:30 PM
Xavier Chantry
 
Default 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)
",
- percent*100.0, pos, (intmax_t)newpkg->size);
+ "%f%% (%"PRId64" / %"PRId64")
",
+ 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%%
"
- "%ju

", (uintmax_t)info->builddate);
+ "%ld

", info->builddate);
}
if(info->installdate) {
fprintf(fp, "%%INSTALLDATE%%
"
- "%ju

", (uintmax_t)info->installdate);
+ "%ld

", info->installdate);
}
if(info->packager) {
fprintf(fp, "%%PACKAGER%%
"
@@ -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%%
"
- "%jd

", (intmax_t)info->isize);
+ "%"PRId64"

", info->isize);
}
if(info->reason) {
fprintf(fp, "%%REASON%%
"
@@ -719,11 +719,11 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
} else {
if(info->size) {
fprintf(fp, "%%CSIZE%%
"
- "%jd

", (intmax_t)info->size);
+ "%"PRId64"

", info->size);
}
if(info->isize) {
fprintf(fp, "%%ISIZE%%
"
- "%jd

", (intmax_t)info->isize);
+ "%"PRId64"

", info->isize);
}
if(info->md5sum) {
fprintf(fp, "%%MD5SUM%%
"
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'
", (intmax_t)bestsize);
+ _alpm_log(PM_LOG_DEBUG, "delta shortest-path search complete : '%"PRId64"'
", 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'
", delta->from, delta->to, (long long)delta->delta_size);
+ _alpm_log(PM_LOG_DEBUG, "delta : %s %s '%"PRId64"'
", 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
"),
- filename, (intmax_t)dl_thisfile, (intmax_t)ust.size);
+ _alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %"PRId64"/%"PRId64" bytes
"),
+ 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
",
- (intmax_t)size, alpm_pkg_get_name(newpkg));
+ _alpm_log(PM_LOG_DEBUG, "setting download size %"PRId64" for pkg %s
",
+ size, alpm_pkg_get_name(newpkg));

newpkg->download_size = size;
return(0);
--
1.6.5.2
 
Old 11-16-2009, 12:57 AM
Dan McGee
 
Default More consistent printing of off_t and time_t

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)
",
> - * * * * * * * * * * * * * * * * * * * * * * * percent*100.0, pos, (intmax_t)newpkg->size);
> + * * * * * * * * * * * * * * * * * * * * * * * "%f%% (%"PRId64" / %"PRId64")
",
> + * * * * * * * * * * * * * * * * * * * * * * * 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%%
"
> - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%ju

", (uintmax_t)info->builddate);
> + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%ld

", info->builddate);
> * * * * * * * * * * * *}
> * * * * * * * * * * * *if(info->installdate) {
> * * * * * * * * * * * * * * * *fprintf(fp, "%%INSTALLDATE%%
"
> - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%ju

", (uintmax_t)info->installdate);
> + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%ld

", info->installdate);
> * * * * * * * * * * * *}
> * * * * * * * * * * * *if(info->packager) {
> * * * * * * * * * * * * * * * *fprintf(fp, "%%PACKAGER%%
"
> @@ -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%%
"
> - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%jd

", (intmax_t)info->isize);
> + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%"PRId64"

", info->isize);
> * * * * * * * * * * * *}
> * * * * * * * * * * * *if(info->reason) {
> * * * * * * * * * * * * * * * *fprintf(fp, "%%REASON%%
"
> @@ -719,11 +719,11 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
> * * * * * * * *} else {
> * * * * * * * * * * * *if(info->size) {
> * * * * * * * * * * * * * * * *fprintf(fp, "%%CSIZE%%
"
> - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%jd

", (intmax_t)info->size);
> + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%"PRId64"

", info->size);
> * * * * * * * * * * * *}
> * * * * * * * * * * * *if(info->isize) {
> * * * * * * * * * * * * * * * *fprintf(fp, "%%ISIZE%%
"
> - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%jd

", (intmax_t)info->isize);
> + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "%"PRId64"

", info->isize);
> * * * * * * * * * * * *}
> * * * * * * * * * * * *if(info->md5sum) {
> * * * * * * * * * * * * * * * *fprintf(fp, "%%MD5SUM%%
"
> 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'
", (intmax_t)bestsize);
> + * * * _alpm_log(PM_LOG_DEBUG, "delta shortest-path search complete : '%"PRId64"'
", 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'
", delta->from, delta->to, (long long)delta->delta_size);
> + * * * _alpm_log(PM_LOG_DEBUG, "delta : %s %s '%"PRId64"'
", 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
"),
> - * * * * * * * * * * * * * * * filename, (intmax_t)dl_thisfile, (intmax_t)ust.size);
> + * * * * * * * _alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %"PRId64"/%"PRId64" bytes
"),
> + * * * * * * * * * * * * * * * 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
",
> - * * * * * * * * * * * (intmax_t)size, alpm_pkg_get_name(newpkg));
> + * * * _alpm_log(PM_LOG_DEBUG, "setting download size %"PRId64" for pkg %s
",
> + * * * * * * * * * * * size, alpm_pkg_get_name(newpkg));
>
> * * * *newpkg->download_size = size;
> * * * *return(0);
> --
> 1.6.5.2
>
>
>
 
Old 11-16-2009, 09:30 AM
Xavier
 
Default More consistent printing of off_t and time_t

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=F reeBSD+7.2-RELEASE
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man3/printf.3.html#//apple_ref/doc/man/3/printf
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
 
Old 11-16-2009, 12:52 PM
Xavier Chantry
 
Default More consistent printing of off_t and time_t

time_t : %ld
off_t : %jd and cast to intmax_t

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
---
lib/libalpm/be_files.c | 6 +++---
lib/libalpm/delta.c | 2 +-
lib/libalpm/dload.c | 6 +++---
3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 5cbc881..7fc20b8 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 <stdint.h> /* intmax_t */
#include <sys/stat.h>
#include <dirent.h>
#include <ctype.h>
@@ -839,11 +839,11 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
}
if(info->builddate) {
fprintf(fp, "%%BUILDDATE%%
"
- "%ju

", (uintmax_t)info->builddate);
+ "%ld

", info->builddate);
}
if(info->installdate) {
fprintf(fp, "%%INSTALLDATE%%
"
- "%ju

", (uintmax_t)info->installdate);
+ "%ld

", info->installdate);
}
if(info->packager) {
fprintf(fp, "%%PACKAGER%%
"
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index 0fc37d9..a5ce611 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -337,7 +337,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'
", delta->from, delta->to, (long long)delta->delta_size);
+ _alpm_log(PM_LOG_DEBUG, "delta : %s %s '%jd'
", delta->from, delta->to, (intmax_t)delta->delta_size);

return(delta);
}
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 05555f2..bc5cdfd 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -186,8 +186,8 @@ static int download_internal(const char *url, const char *localpath,

_alpm_log(PM_LOG_DEBUG, "ust.mtime: %ld local_time: %ld compare: %ld
",
ust.mtime, local_time, local_time - ust.mtime);
- _alpm_log(PM_LOG_DEBUG, "ust.size: %"PRId64" local_size: %"PRId64" compare: %"PRId64"
",
- ust.size, local_size, local_size - ust.size);
+ _alpm_log(PM_LOG_DEBUG, "ust.size: %jd local_size: %jd compare: %jd
",
+ (intmax_t)ust.size, (intmax_t)local_size, (intmax_t)(local_size - ust.size));
if(!force && ust.mtime && ust.mtime == local_time
&& ust.size && ust.size == local_size) {
/* the remote time and size values agreed with what we have, so move on
@@ -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 %"PRId64"
", fileurl->offset);
+ _alpm_log(PM_LOG_DEBUG, "resuming download at position %jd
", (intmax_t)fileurl->offset);
}


--
1.6.5.2
 

Thread Tools




All times are GMT. The time now is 11:01 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org