cast pid_t's to uintmax_t to improve portability
Some systems (like e.g. OpenSolaris) define pid_t as long, therefore all our sprintf that use %i/%d cause a compiler warning beacuse of the implicit long->int cast. To make sure that we fit the limits, we display pids as PRIuMAX and cast them explicitly to uintmax_t. Signed-off-by: David Soria Parra <dsp@php.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Soria Parra committed
Aug 31, 2008 at 14:09 UTC
85e72830697a23dd6b1af8b6bfb3c1a7be60dfae
5 files changed
+9
-9
builtin-commit.c
+1
-1
@@ -320,7 +320,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
320
die("unable to write new_index file");
321
322
fd = hold_lock_file_for_update(&false_lock,
323
- git_path("next-index-%d", getpid()), 1);
323
+ git_path("next-index-%"PRIuMAX, (uintmax_t) getpid()), 1);
324
325
create_base_index();
326
add_remove_files(&partial);
builtin-fetch-pack.c
+1
-1
@@ -540,7 +540,7 @@ static int get_pack(int xd[2], char **pack_lockfile)
540
*av++ = "--fix-thin";
541
if (args.lock_pack || unpack_limit) {
542
int s = sprintf(keep_arg,
543
- "--keep=fetch-pack %d on ", getpid());
543
+ "--keep=fetch-pack %"PRIuMAX " on ", (uintmax_t) getpid());
544
if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
545
strcpy(keep_arg + s, "localhost");
546
*av++ = keep_arg;
daemon.c
+3
-3
@@ -86,7 +86,7 @@ static void logreport(int priority, const char *err, va_list params)
86
* Since stderr is set to linebuffered mode, the
87
* logging of different processes will not overlap
88
*/
89
- fprintf(stderr, "[%d] ", (int)getpid());
89
+ fprintf(stderr, "[%"PRIuMAX"] ", (uintmax_t)getpid());
90
vfprintf(stderr, err, params);
91
fputc('\n', stderr);
92
}
@@ -658,7 +658,7 @@ static void check_dead_children(void)
658
remove_child(pid);
659
if (!WIFEXITED(status) || (WEXITSTATUS(status) > 0))
660
dead = " (with error)";
661
- loginfo("[%d] Disconnected%s", (int)pid, dead);
661
+ loginfo("[%"PRIuMAX"] Disconnected%s", (uintmax_t)pid, dead);
662
}
663
}
664
@@ -923,7 +923,7 @@ static void store_pid(const char *path)
923
FILE *f = fopen(path, "w");
924
if (!f)
925
die("cannot open pid file %s: %s", path, strerror(errno));
926
- if (fprintf(f, "%d\n", getpid()) < 0 || fclose(f) != 0)
926
+ if (fprintf(f, "%"PRIuMAX"\n", (uintmax_t) getpid()) < 0 || fclose(f) != 0)
927
die("failed to write pid file %s: %s", path, strerror(errno));
928
}
929
fast-import.c
+3
-3
@@ -376,7 +376,7 @@ static void dump_marks_helper(FILE *, uintmax_t, struct mark_set *);
376
377
static void write_crash_report(const char *err)
378
{
379
- char *loc = git_path("fast_import_crash_%d", getpid());
379
+ char *loc = git_path("fast_import_crash_%"PRIuMAX, (uintmax_t) getpid());
380
FILE *rpt = fopen(loc, "w");
381
struct branch *b;
382
unsigned long lu;
@@ -390,8 +390,8 @@ static void write_crash_report(const char *err)
390
fprintf(stderr, "fast-import: dumping crash report to %s\n", loc);
391
392
fprintf(rpt, "fast-import crash report:\n");
393
- fprintf(rpt, " fast-import process: %d\n", getpid());
394
- fprintf(rpt, " parent process : %d\n", getppid());
393
+ fprintf(rpt, " fast-import process: %"PRIuMAX"\n", (uintmax_t) getpid());
394
+ fprintf(rpt, " parent process : %"PRIuMAX"\n", (uintmax_t) getppid());
395
fprintf(rpt, " at %s\n", show_date(time(NULL), 0, DATE_LOCAL));
396
fputc('\n', rpt);
397
receive-pack.c
+1
-1
@@ -407,7 +407,7 @@ static const char *unpack(void)
407
char keep_arg[256];
408
struct child_process ip;
409
410
- s = sprintf(keep_arg, "--keep=receive-pack %i on ", getpid());
410
+ s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid());
411
if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
412
strcpy(keep_arg + s, "localhost");
413