{"thread":{"id":"15299","subject":"[PATCH v2] Improve portability: Cast pid_t's to intmax_t","startedAt":"2008-08-31T12:09:39Z","lastAt":"2008-08-31T12:26:30Z","messageCount":2,"participants":["David Soria Parra"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"89307","messageId":"1220184579-13808-1-git-send-email-sn_@gmx.net","threadId":"15299","inReplyTo":null,"subject":"[PATCH v2] Improve portability: Cast pid_t's to intmax_t","fromName":"David Soria Parra","fromEmail":"sn_@gmx.net","sentAt":"2008-08-31T12:09:39Z","receivedAt":"2008-08-31T12:09:39Z","isPatch":true,"sender":{"key":"sn_@gmx.net","avatar":"https://gravatar.com/avatar/b1075ecdd33ea094cbc23798fe8b95c73ec1ccf7bb213ac8260c719e2dd97b55?d=mp&s=160"},"body":"From: David Soria Parra <dsp@php.net>\n\nSome systems (like e.g. OpenSolaris) define pid_t as long,\ntherefore all our sprintf that use %i/%d cause a compiler warning\nbeacuse of the implicit long->int cast. To make sure that\nwe fit the limits, we display pids as PRIuMAX and cast them explicitly\nto uintmax_t.\n\nSigned-off-by: David Soria Parra <dsp@php.net>\n---\n\n Here is a revised version of the portability patch. It's based on next to\n avoid conflicts due to the style fixups in\n 460c201039471d22194ca871290c098bfe6ce6a3.\n\n builtin-commit.c     |    2 +-\n builtin-fetch-pack.c |    2 +-\n daemon.c             |    6 +++---\n fast-import.c        |    6 +++---\n receive-pack.c       |    2 +-\n 5 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin-commit.c b/builtin-commit.c\nindex 4182686..8165bb3 100644\n--- a/builtin-commit.c\n+++ b/builtin-commit.c\n@@ -320,7 +320,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)\n \t\tdie(\"unable to write new_index file\");\n \n \tfd = hold_lock_file_for_update(&false_lock,\n-\t\t\t\t       git_path(\"next-index-%d\", getpid()), 1);\n+\t\t\t\t       git_path(\"next-index-%\"PRIuMAX, (uintmax_t) getpid()), 1);\n \n \tcreate_base_index();\n \tadd_remove_files(&partial);\ndiff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c\nindex 273239a..17a5a42 100644\n--- a/builtin-fetch-pack.c\n+++ b/builtin-fetch-pack.c\n@@ -540,7 +540,7 @@ static int get_pack(int xd[2], char **pack_lockfile)\n \t\t\t*av++ = \"--fix-thin\";\n \t\tif (args.lock_pack || unpack_limit) {\n \t\t\tint s = sprintf(keep_arg,\n-\t\t\t\t\t\"--keep=fetch-pack %d on \", getpid());\n+\t\t\t\t\t\"--keep=fetch-pack %\"PRIuMAX \" on \", (uintmax_t) getpid());\n \t\t\tif (gethostname(keep_arg + s, sizeof(keep_arg) - s))\n \t\t\t\tstrcpy(keep_arg + s, \"localhost\");\n \t\t\t*av++ = keep_arg;\ndiff --git a/daemon.c b/daemon.c\nindex 23278e2..c315932 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -86,7 +86,7 @@ static void logreport(int priority, const char *err, va_list params)\n \t\t * Since stderr is set to linebuffered mode, the\n \t\t * logging of different processes will not overlap\n \t\t */\n-\t\tfprintf(stderr, \"[%d] \", (int)getpid());\n+\t\tfprintf(stderr, \"[%\"PRIuMAX\"] \", (uintmax_t)getpid());\n \t\tvfprintf(stderr, err, params);\n \t\tfputc('\\n', stderr);\n \t}\n@@ -658,7 +658,7 @@ static void check_dead_children(void)\n \t\tremove_child(pid);\n \t\tif (!WIFEXITED(status) || (WEXITSTATUS(status) > 0))\n \t\t\tdead = \" (with error)\";\n-\t\tloginfo(\"[%d] Disconnected%s\", (int)pid, dead);\n+\t\tloginfo(\"[%\"PRIuMAX\"] Disconnected%s\", (uintmax_t)pid, dead);\n \t}\n }\n \n@@ -923,7 +923,7 @@ static void store_pid(const char *path)\n \tFILE *f = fopen(path, \"w\");\n \tif (!f)\n \t\tdie(\"cannot open pid file %s: %s\", path, strerror(errno));\n-\tif (fprintf(f, \"%d\\n\", getpid()) < 0 || fclose(f) != 0)\n+\tif (fprintf(f, \"%\"PRIuMAX\"\\n\", (uintmax_t) getpid()) < 0 || fclose(f) != 0)\n \t\tdie(\"failed to write pid file %s: %s\", path, strerror(errno));\n }\n \ndiff --git a/fast-import.c b/fast-import.c\nindex d85b3a5..ccdf2e5 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -376,7 +376,7 @@ static void dump_marks_helper(FILE *, uintmax_t, struct mark_set *);\n \n static void write_crash_report(const char *err)\n {\n-\tchar *loc = git_path(\"fast_import_crash_%d\", getpid());\n+\tchar *loc = git_path(\"fast_import_crash_%\"PRIuMAX, (uintmax_t) getpid());\n \tFILE *rpt = fopen(loc, \"w\");\n \tstruct branch *b;\n \tunsigned long lu;\n@@ -390,8 +390,8 @@ static void write_crash_report(const char *err)\n \tfprintf(stderr, \"fast-import: dumping crash report to %s\\n\", loc);\n \n \tfprintf(rpt, \"fast-import crash report:\\n\");\n-\tfprintf(rpt, \"    fast-import process: %d\\n\", getpid());\n-\tfprintf(rpt, \"    parent process     : %d\\n\", getppid());\n+\tfprintf(rpt, \"    fast-import process: %\"PRIuMAX\"\\n\", (uintmax_t) getpid());\n+\tfprintf(rpt, \"    parent process     : %\"PRIuMAX\"\\n\", (uintmax_t) getppid());\n \tfprintf(rpt, \"    at %s\\n\", show_date(time(NULL), 0, DATE_LOCAL));\n \tfputc('\\n', rpt);\n \ndiff --git a/receive-pack.c b/receive-pack.c\nindex d44c19e..b81678a 100644\n--- a/receive-pack.c\n+++ b/receive-pack.c\n@@ -407,7 +407,7 @@ static const char *unpack(void)\n \t\tchar keep_arg[256];\n \t\tstruct child_process ip;\n \n-\t\ts = sprintf(keep_arg, \"--keep=receive-pack %i on \", getpid());\n+\t\ts = sprintf(keep_arg, \"--keep=receive-pack %\"PRIuMAX\" on \", (uintmax_t) getpid());\n \t\tif (gethostname(keep_arg + s, sizeof(keep_arg) - s))\n \t\t\tstrcpy(keep_arg + s, \"localhost\");\n \n-- \n1.6.0.174.gd789c\n"},{"id":"89308","messageId":"48BA8DF6.9020008@gmx.net","threadId":"15299","inReplyTo":"1220184579-13808-1-git-send-email-sn_@gmx.net","subject":"Re: [PATCH v2] Improve portability: Cast pid_t's to uintmax_t","fromName":"David Soria Parra","fromEmail":"dsoria@gmx.net","sentAt":"2008-08-31T12:26:30Z","receivedAt":"2008-08-31T12:26:30Z","isPatch":true,"sender":{"key":"dsoria@gmx.net","avatar":null},"body":"\n> \n>  Here is a revised version of the portability patch. It's based on next to\n>  avoid conflicts due to the style fixups in\n>  460c201039471d22194ca871290c098bfe6ce6a3.\n\nnot my day. I read the patch and commit message 3 times, but I forgot \nthe topic is 'Cast pid_t's to uintmax_t' and not intmax_t.\n"}]}