Cast pid_t to long for fprintf()

pid_t is defined by POSIX to be a signed integer type, so the %u format is wrong.

Cast to long and print with %ld - it is unlikely that any real-world system has pid_t bigger than long.
This commit is contained in:
Kevin Easton
2017-02-17 16:50:41 +11:00
parent 686344314f
commit a0e8bd5742

View File

@@ -1425,7 +1425,7 @@ FILE *t;
void setup_pid(void) void setup_pid(void)
{ {
#ifdef WANT_DETACH #ifdef WANT_DETACH
pid_t pid; pid_t pid;
if (!do_check_pid) if (!do_check_pid)
return; return;
if ((pid = getpid())) if ((pid = getpid()))
@@ -1434,7 +1434,7 @@ pid_t pid;
unlink(pidfile); unlink(pidfile);
if ((t = fopen(pidfile, "w"))) if ((t = fopen(pidfile, "w")))
{ {
fprintf(t, "%u\n", pid); fprintf(t, "%ld\n", (long)pid);
fclose(t); fclose(t);
} }
} }