stats: atomically set sort_status
stats: it's fine to use asserts in internal functions
misc: fixed mistype: Sainity -> Sanity
blob: do not depend on dirname implementation

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