static apr_status_t slotmem_attach_shm(apr_shm_t **shm, const char **fname,
                                       apr_uint32_t num, apr_pool_t *pool)
{
    char *name = NULL;
    apr_size_t size = 0, offset = 0;

    for (; num; --num) {
        if (!name) {
            name = apr_psprintf(pool, "%s.%u", *fname, APR_UINT32_MAX);
            offset = strlen(*fname) + 1;
            size = offset + strlen(name + offset) + 1;
        }
        apr_snprintf(name + offset, size - offset, "%u", num);

        if (apr_shm_attach(shm, name, pool) == APR_SUCCESS) {
            *fname = name;
            return APR_SUCCESS;
        }
    }

    return apr_shm_attach(shm, *fname, pool);
}