Wednesday, March 24, 2010

Perforce has the best error messages.

I wanted to know what the path to something was on the server, but I couldn't remember. Little did I know that perforce would be so judgemental:

c:\source>p4 dirs *
//depot/foo/bar/baz
//depot/foo/bar/qux
Client map too twisted for directory list.

And then there was the time I made a perfectly reasonable request, I wanted to edit all the unittest files in the entire tree, and it had to go and get all preachy:

c:\source\v2-dev>p4 edit foo\...*unittest.cc
Senseless juxtaposition of wildcards in '//jeff-src/foo/...*unittest.cc'.

I mean, yeah, maybe there's a typo there, but you don't have to insult me.

Wednesday, March 17, 2010

GetModuleFileName() on OS X.

So, you want to know the path to your module.  On Windows, it's easy: you call GetModuleFileName() and pass NULL for the HMODULE.

But what if you're trying to do it on OS X?

#include <dlfcn.h>
std::string GetModuleFileNameOSX() {
  Dl_info module_info;
  if (dladdr(reinterpret_cast<void*>(GetModuleFileNameOSX), &module_info) == 0) {
    // Failed to find the symbol we asked for.
    return std::string();
  }
  return std::string(module_info.dli_fname);
}

For the first param to dladdr, you can pass any symbol you know will be in your module. In theory, something similar should work on linux, but I haven't tried.