standalone version of git's strbuf api