Replace snprintf(NULL, 0, ...) with strlen().

snprintf(NULL, 0, ...) behavior is inconsistent and breaks on some systems.
strlen() should always work properly.