⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dblfcns.c

📁 db.* (pronounced dee-be star) is an advanced, high performance, small footprint embedded database fo
💻 C
📖 第 1 页 / 共 4 页
字号:
        }    }    if (task->rec_locks)    {        for ( i = (dbn == ALL_DBS) ? 0 : task->db_table[dbn].rt_offset,                    ld_ptr = &task->rec_locks[i];                i < ((dbn == ALL_DBS)                    ? task->size_rt : task->db_table[dbn].rt_offset + task->db_table[dbn].Size_rt);                ++i, ++ld_ptr)        {            psp_freeMemory(ld_ptr->fl_list, 0);            ld_ptr->fl_list = NULL;        }        free_table((void **) &task->rec_locks, low, high, total,                sizeof(struct lock_descr),                task);    }    if (dbn == ALL_DBS)    {        task->size_rt = 0;        low = 0;        high = task->size_ft;        total = task->size_ft;    }    else    {        task->size_rt -= task->db_table[dbn].Size_rt;        if (task->rec_locks)        {            for (i = low, ld_ptr = &task->rec_locks[low]; i < task->size_rt; i++, ld_ptr++)            {                fl_ptr = ld_ptr->fl_list;                for (j = 0; j < ld_ptr->fl_cnt; j++, fl_ptr++)                    *fl_ptr = (FILE_NO) ((*fl_ptr) - task->db_table[dbn].Size_ft);            }        }        low = task->db_table[dbn].ft_offset;        high = low + task->db_table[dbn].Size_ft;        total = task->size_ft;    }    if (task->file_table)    {        if (dbn == ALL_DBS)        {            free_table((void **) &task->file_table, low, high + extra_file,                    total + extra_file, sizeof(FILE_ENTRY), task);            task->size_ft = 0;        }        else        {            free_table((void **) &task->file_table, low, high, total + extra_file,                    sizeof(FILE_ENTRY), task);            task->size_ft -= task->db_table[dbn].Size_ft;        }    }    if (task->db_lockmgr)    {                       /* [637] Only alloc task->file_refs for shared open */        if (task->file_refs)        {            free_table((void **) &task->file_refs, low, high, total,                    sizeof(FILE_NO), task);        }        free_table((void **) &task->sgs, low, high, total, sizeof(SG *), task);        if (task->size_ft)        {            if (alloc_lfpkts(task) != S_OKAY)            {                dberr(S_NOMEMORY);                return;            }        }        else        {            if (task->lock_pkt)                psp_lmcFree(task->lock_pkt);            task->lock_pkt = NULL;            if (task->free_pkt)                psp_lmcFree(task->free_pkt);            task->free_pkt = NULL;        }    }#ifdef DBSTAT    if (task->file_stats)    {        free_table((void **) &task->file_stats, low, high, total,                sizeof(FILE_STATS), task);    }#endif    if (task->app_locks)    {        free_table((void **) &task->app_locks, low, high, total, sizeof(int),                task);    }    if (task->excl_locks)    {        free_table((void **) &task->excl_locks, low, high, total, sizeof(int),                task);    }    if (task->kept_locks)    {        free_table((void **) &task->kept_locks, low, high, total, sizeof(int),                task);    }    if (dbn == ALL_DBS)    {        if (task->lock_pkt)            psp_lmcFree(task->lock_pkt);        task->lock_pkt = NULL;        if (task->free_pkt)            psp_lmcFree(task->free_pkt);        task->free_pkt = NULL;    }    if (task->db_table)    {        if (dbn == ALL_DBS)        {            if (task->dboptions & READNAMES)            {                for (i = 0; i < task->no_of_dbs; i++)                {                    if (task->db_table[i].Objnames)                        psp_freeMemory(task->db_table[i].Objnames, 0);                }            }            psp_freeMemory(task->db_table, 0);            task->db_table = NULL;            task->curr_db_table = NULL;        }        else        {            if (task->no_of_dbs > dbn + 1)            {                temp = task->db_table[dbn + 1].key_offset;                close_db_ptr = &task->db_table[dbn];                for (i = dbn + 1; i < task->no_of_dbs; i++)                {                    db_ptr = &task->db_table[i];                    db_ptr->ft_offset -= close_db_ptr->Size_ft;                    db_ptr->rt_offset -= close_db_ptr->Size_rt;                    db_ptr->st_offset -= close_db_ptr->Size_st;                    db_ptr->mt_offset -= close_db_ptr->Size_mt;                    db_ptr->srt_offset -= close_db_ptr->Size_srt;                    db_ptr->kt_offset -= close_db_ptr->Size_kt;                    db_ptr->fd_offset -= close_db_ptr->Size_fd;                    db_ptr->key_offset -= (short) ((temp -                            close_db_ptr->key_offset));                }            }            if (task->dboptions & READNAMES)            {                if (task->db_table[dbn].Objnames)                    psp_freeMemory(task->db_table[dbn].Objnames, 0);            }            free_table((void **) &task->db_table, dbn, dbn + 1, task->no_of_dbs,                    sizeof(DB_ENTRY), task);        }    }    if (task->rn_table)    {        if (dbn == ALL_DBS)            psp_freeMemory(task->rn_table, 0);        else            free_table((void **) &task->rn_table, dbn, dbn + 1, task->no_of_dbs,                    sizeof(RN_ENTRY), task);    }}/* ======================================================================    get lock manager status for a user*/int INTERNAL_FCN dlmstat(DB_TCHAR *userid, int *user_stat, DB_TASK *task){    LM_STATUS *send_pkt = NULL;    short     *recv_pkt = NULL;    if (!task->dbopen)        return dberr(S_DBOPEN);    if (task->dbopen >= 2 || !userid[0])    {        *user_stat = U_EMPTY;        return task->db_status;    }    send_pkt = (LM_STATUS *)  psp_lmcAlloc(sizeof(LM_STATUS));    if (!send_pkt)        return (dberr(S_NOMEMORY));    vtstrcpy(send_pkt->username, userid);    send_pkt->type_of_status = ST_USERSTAT;    msg_trans(L_STATUS, send_pkt, sizeof(LM_STATUS), (void **) &recv_pkt, NULL,            task);    if (task->db_status == S_OKAY)        *user_stat = *recv_pkt;    psp_lmcFree(send_pkt);    if (recv_pkt)        psp_lmcFree(recv_pkt);    return task->db_status;}/* ======================================================================    free all locked files*/int INTERNAL_FCN dfreeall(DB_TASK *task){    if (!task->dbopen)        return (dberr(S_DBOPEN));    if (task->dbopen >= 2)                    /* exclusive access needs no locks */        return (task->db_status);    if (task->trans_id[0])        return (dberr(S_TRFREE));    dio_flush(task);               /* flush any x-locked files */    free_dblocks(ALL_DBS, task);    return (task->db_status);}/* ======================================================================*/int INTERNAL_FCN alloc_table(    void   **table,    size_t   newsz,    size_t   oldsz,    DB_TASK *task){    void *temp_table;    if (oldsz == 0)        temp_table = psp_cGetMemory(newsz, 0);    else    {        temp_table = psp_cExtendMemory(*table, newsz,                newsz > oldsz ? newsz - oldsz : 0, 0);    }    if (temp_table == NULL)        return (dberr(S_NOMEMORY));    *table = temp_table;    return (task->db_status);}/* ======================================================================    Reallocates array, removing elements from low to high-1 inclusive,    after copying the contents of the remaining elements into a new array.*/int INTERNAL_FCN free_table(void **table, int low, int high, int total,                            size_t size, DB_TASK *task){    void *temp_table = NULL;    int   new_count;    if (*table == NULL)    {        dberr(S_INVPTR);        goto EXIT;    }    if (total == low || high < 1)        goto EXIT;    new_count = total - (high - low);    if (size == 0 || new_count < 0)    {        dberr(SYS_BADFREE);        goto EXIT;    }    if (new_count > 0)    {        if ((temp_table = psp_getMemory(new_count * size, 0)) == NULL)        {            dberr(S_NOMEMORY);            goto EXIT;        }        if (low > 0)            memcpy(temp_table, *table, low * size);        if (new_count - low > 0)        {            memcpy((char *) temp_table + (low * size), (char *) *table +                    (high * size), (new_count - low) * size);        }    }    psp_freeMemory(*table, 0);    *table = temp_table;EXIT:    return task->db_status;}/* ======================================================================    free the locks associated with a database*/int INTERNAL_FCN free_dblocks(int dbn, DB_TASK *task){    register int      i;    register int     *appl_ptr;    register FILE_NO *fref_ptr;    int               low, high;    /* exclusive access needs no locks */    if (task->dbopen >= 2)        return (task->db_status);    if (dbn == ALL_DBS)    {        low = 0;        high = task->size_ft;    }    else    {        low = task->db_table[dbn].ft_offset;        high = low + task->db_table[dbn].Size_ft;    }    task->free_pkt->nfiles = 0;    for ( i = low, fref_ptr = &task->file_refs[low], appl_ptr = &task->app_locks[low];            i < high; ++i, ++fref_ptr, ++appl_ptr)    {        if (*appl_ptr)        {            if (!task->excl_locks[i])            {#ifdef DBSTAT                STAT_lock((FILE_NO)i, *appl_ptr > 0 ? STAT_FREE_r : STAT_FREE_w, task);#endif                task->free_pkt->frefs[task->free_pkt->nfiles++] = *fref_ptr;            }            *appl_ptr = FALSE;        }    }    if (send_free_pkt(task) != S_OKAY)   /* send free files packet */        return task->db_status;    if (dbn == ALL_DBS)                 /* reset all lock descriptors */        reset_locks(task);    key_reset(task->size_ft, task);      /* reset all key file positions */    return task->db_status;}/* ======================================================================    Allocate the lock and free pkts*/static int alloc_lfpkts (DB_TASK *task){    task->lp_size = (size_t)(sizeof(LM_LOCK) + (task->size_ft - 1) * sizeof(DB_LOCKREQ));    task->fp_size = (size_t)(sizeof(LM_FREE) + (task->size_ft - 1) * sizeof(short));    /* if packets were previously allocated then free them */    if (task->lock_pkt)        psp_lmcFree(task->lock_pkt);    if (task->free_pkt)        psp_lmcFree(task->free_pkt);    if ((task->lock_pkt = (LM_LOCK *) psp_lmcAlloc(task->lp_size)) == NULL)        return S_NOMEMORY;    if ((task->free_pkt = (LM_FREE *) psp_lmcAlloc(task->fp_size)) == NULL)    {        psp_lmcFree(task->lock_pkt);        return S_NOMEMORY;    }    return S_OKAY;}/* ======================================================================    Process renamed file table*/int INTERNAL_FCN renfiles(DB_TASK *task){    REN_ENTRY *rp;    int        dbn;    DB_ENTRY  *db_ptr;    if (ll_access(&task->ren_list))    {        db_ptr = task->curr_db_table;       /* Have to save it because of macros */        while ((rp = (REN_ENTRY *) ll_next(&task->ren_list)) != NULL)        {            dbn = ddbnum(rp->ren_db_name, task);            if (dbn < 0)                continue;            task->curr_db_table = &task->db_table[dbn];            if ((rp->file_no < 0) || (rp->file_no >= DB_REF(Size_ft)))            {                ll_deaccess(&task->ren_list);                return (dberr(S_RENAME));            }            vtstrcpy(task->file_table[NUM2INT(rp->file_no, ft_offset)].ft_name,                    rp->file_name);        }        task->curr_db_table = db_ptr;       /* restore it */    }    ll_deaccess(&task->ren_list);    return (task->db_status);}/* ======================================================================    Count how many characters are same at start of two strings*/static int INTERNAL_FCN cmpfiles(DB_TCHAR *s1, DB_TCHAR *s2){    int count = 0;    while (*s1 && *s2)    {        if (*s1++ != *s2++)            break;        count++;    }    return count;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -