return to OCLUG Web Site
A Django site.
August 21, 2009

Bart Trojanowski
jukie
Bart's Blog
» prettier function tracing

This is a follow up to my pretty function tracing article. I base this work on the code presented there.

Some one asked me how to get the gcc -finstrument-functions feature working. If you don't know this flag will modify the entry and exit to/from each function to make a call out to a special set of functions used for tracing.

While I've read about this feature, I never actually tried it. So here is what I learned...

[Read More]

June 25, 2009

Bart Trojanowski
jukie
Bart's Blog
» portable printf

I was squashing some warnings in uzbl code:

    printf("set %s = %d\n", (char *)k, (int)*c->ptr);

Ignoring the fact that, at first glance, it's weird to cast a pointer to int (ptr is defined as void**), compiling this code on 64bit would warn you that you were casting a pointer to an int. That's because a pointer is 64bit and an int is 32bit.

[Read More]

March 23, 2009

Bart Trojanowski
jukie
Bart's Blog
» popen with stdin, stdout, and stderr

I've look around for an open source implementation of popen() that can handle redirection of stdin, stdout, and stderr of the program executed. I was unable to find one, so I wrote my own.

If you need to fork a helper process and maintain bidirectional communication wtih it, then you can use my popenRWE() (source: popenRWE.c.

Here is an example of how it might be used:

    int pipe[3];
    int pid;
    const char *const args[] = {
            "cat",
            "-n",
            NULL
    };

    pid = popenRWE(pipe, args[0], args);

    // write to pipe[0] - input to cat
    // read from pipe[1] - output from cat
    // read from pipe[2] - errors from cat

    pcloseRWE(pid, pipe);