summaryrefslogtreecommitdiff
path: root/util/cairo-trace/trace.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/cairo-trace/trace.c')
-rw-r--r--util/cairo-trace/trace.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index f8275a69..3c47aafc 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -651,22 +651,29 @@ _trace_printf (const char *fmt, ...)
static void
get_prog_name (char *buf, int length)
{
- FILE *file = fopen ("/proc/self/cmdline", "rb");
- *buf = '\0';
- if (file != NULL) {
- char *slash;
+ char *slash;
+ FILE *file;
- slash = fgets (buf, length, file);
- fclose (file);
- if (slash == NULL)
- return;
+ memset (buf, 0, length);
+ if (length == 0)
+ return;
- slash = strrchr (buf, '/');
- if (slash != NULL) {
- int len = strlen (slash+1);
- memmove (buf, slash+1, len+1);
+ file = fopen ("/proc/self/cmdline", "rb");
+ if (file != NULL) {
+ fgets (buf, length, file);
+ fclose (file);
+ } else {
+ char const *name = getenv ("CAIRO_TRACE_PROG_NAME");
+ if (name != NULL) {
+ strncpy (buf, name, length-1);
}
}
+
+ slash = strrchr (buf, '/');
+ if (slash != NULL) {
+ size_t len = strlen (slash+1);
+ memmove (buf, slash+1, len+1);
+ }
}
static void