blob: do not depend on dirname implementation

Also use snprintf() so we always get NULL-terminated string.