(ptrace) [PTRACE_TRACEME]: Notify the proc server that we are now traced.
[glibc.git] / manual / examples / rprintf.c
blobeff1d8e7cf7e92517d0092eafa58ad0b01f7e277
1 #include <stdio.h>
2 #include <printf.h>
3 #include <stdarg.h>
5 /*@group*/
6 typedef struct
8 char *name;
9 } Widget;
10 /*@end group*/
12 int
13 print_widget (FILE *stream, const struct printf_info *info, va_list *app)
15 Widget *w;
16 char *buffer;
17 int len;
19 /* Format the output into a string. */
20 w = va_arg (*app, Widget *);
21 len = asprintf (&buffer, "<Widget %p: %s>", w, w->name);
22 if (len == -1)
23 return -1;
25 /* Pad to the minimum field width and print to the stream. */
26 len = fprintf (stream, "%*s",
27 (info->left ? - info->width : info->width),
28 buffer);
30 /* Clean up and return. */
31 free (buffer);
32 return len;
36 int
37 main (void)
39 /* Make a widget to print. */
40 Widget mywidget;
41 mywidget.name = "mywidget";
43 /* Register the print function for widgets. */
44 register_printf_function ('W', print_widget, NULL); /* No arginfo. */
46 /* Now print the widget. */
47 printf ("|%W|\n", &mywidget);
48 printf ("|%35W|\n", &mywidget);
49 printf ("|%-35W|\n", &mywidget);
51 return 0;