Use printf()'s '#' flag character to prepend the string "0x".
However, when the number is printed in uppercase, and the prefix
is in lowercase, the string "0x" needs to be manually written.
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
s = read(efd, &u, sizeof(uint64_t));
if (s != sizeof(uint64_t))
handle_error("read");
- printf("Parent read %"PRIu64" (0x%"PRIx64") from efd\en", u, u);
+ printf("Parent read %"PRIu64" (%#"PRIx64") from efd\en", u, u);
exit(EXIT_SUCCESS);
case \-1:
Nevertheless, we use printf() here as a simple way of
showing that the handler was called. */
- printf("Got SIGSEGV at address: 0x%lx\en",
+ printf("Got SIGSEGV at address: %#lx\en",
(long) si\->si_addr);
exit(EXIT_FAILURE);
}
if (buffer == NULL)
handle_error("memalign");
- printf("Start of region: 0x%lx\en", (long) buffer);
+ printf("Start of region: %#lx\en", (long) buffer);
if (mprotect(buffer + pagesize * 2, pagesize,
PROT_READ) == \-1)
exit(EXIT_FAILURE);
}
- printf("Events (0x%x): POLLIN is %sset\en", pollfd.revents,
+ printf("Events (%#x): POLLIN is %sset\en", pollfd.revents,
(pollfd.revents & POLLIN) ? "" : "not ");
close(pidfd);
* 0x00000002 (spu was stopped due to stop\-and\-signal)
* | 0x12340000 (the stop\-and\-signal code)
*/
- printf("SPU Status: 0x%08x\en", spu_status);
+ printf("SPU Status: %#08x\en", spu_status);
exit(EXIT_SUCCESS);
}
tidp = si\->si_value.sival_ptr;
printf(" sival_ptr = %p; ", si\->si_value.sival_ptr);
- printf(" *sival_ptr = 0x%lx\en", (unsigned long) *tidp);
+ printf(" *sival_ptr = %#lx\en", (unsigned long) *tidp);
or = timer_getoverrun(*tidp);
if (or == \-1)
if (timer_create(CLOCKID, &sev, &timerid) == \-1)
errExit("timer_create");
- printf("timer ID is 0x%lx\en", (unsigned long) timerid);
+ printf("timer ID is %#lx\en", (unsigned long) timerid);
/* Start the timer */
}
x = strtoull(argv[1], NULL, 0);
- printf("0x%" PRIx64 " ==> 0x%" PRIx64 "\en", x, bswap_64(x));
+ printf("%#" PRIx64 " ==> %#" PRIx64 "\en", x, bswap_64(x));
exit(EXIT_SUCCESS);
}
(p_type == PT_GNU_STACK) ? "PT_GNU_STACK" :
(p_type == PT_GNU_RELRO) ? "PT_GNU_RELRO" : NULL;
- printf(" %2d: [%14p; memsz:%7lx] flags: 0x%x; ", j,
+ printf(" %2d: [%14p; memsz:%7lx] flags: %#x; ", j,
(void *) (info\->dlpi_addr + info\->dlpi_phdr[j].p_vaddr),
info\->dlpi_phdr[j].p_memsz,
info\->dlpi_phdr[j].p_flags);
if (type != NULL)
printf("%s\en", type);
else
- printf("[other (0x%x)]\en", p_type);
+ printf("[other (%#x)]\en", p_type);
}
return 0;
x.arr[2] = 0x33;
x.arr[3] = 0x44; /* Highest-address byte */
- printf("x.u32 = 0x%x\en", x.u32);
- printf("htole32(x.u32) = 0x%x\en", htole32(x.u32));
- printf("htobe32(x.u32) = 0x%x\en", htobe32(x.u32));
+ printf("x.u32 = %#x\en", x.u32);
+ printf("htole32(x.u32) = %#x\en", htole32(x.u32));
+ printf("htobe32(x.u32) = %#x\en", htobe32(x.u32));
exit(EXIT_SUCCESS);
}
if (s != 0)
handle_error_en(s, "pthread_attr_getstack");
printf("%sStack address = %p\en", prefix, stkaddr);
- printf("%sStack size = 0x%zx bytes\en", prefix, v);
+ printf("%sStack size = %#zx bytes\en", prefix, v);
}
static void *
if (stack_size > 0)
printf(" (EOS = %p)", (char *) stack_addr + stack_size);
printf("\en");
- printf("%sStack size = 0x%zx (%zu) bytes\en",
+ printf("%sStack size = %#zx (%zu) bytes\en",
prefix, stack_size, stack_size);
}
if (s & mask)
ch |= 0x100;
attrib = ((s & \(timask) >> 8);
- printf("ch=0x%03x attrib=0x%02x\en", ch, attrib);
+ printf("ch=%#03x attrib=%#02x\en", ch, attrib);
s \(ha= 0x1000;
(void) lseek(fd, \-2, SEEK_CUR);
(void) write(fd, &s, 2);
{
printf("la_symbind32(): symname = %s; sym\->st_value = %p\en",
symname, sym\->st_value);
- printf(" ndx = %d; flags = 0x%x", ndx, *flags);
+ printf(" ndx = %d; flags = %#x", ndx, *flags);
printf("; refcook = %p; defcook = %p\en", refcook, defcook);
return sym\->st_value;
{
printf("la_symbind64(): symname = %s; sym\->st_value = %p\en",
symname, sym\->st_value);
- printf(" ndx = %d; flags = 0x%x", ndx, *flags);
+ printf(" ndx = %d; flags = %#x", ndx, *flags);
printf("; refcook = %p; defcook = %p\en", refcook, defcook);
return sym\->st_value;