File: rc_prc_setf.c

package info (click to toggle)
fis-gtm 6.2-000-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 30,784 kB
  • ctags: 42,554
  • sloc: ansic: 358,483; asm: 4,847; csh: 4,574; sh: 2,261; awk: 200; makefile: 86; sed: 13
file content (119 lines) | stat: -rw-r--r-- 3,297 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/****************************************************************
 *								*
 *	Copyright 2001, 2013 Fidelity Information Services, Inc	*
 *								*
 *	This source code contains the intellectual property	*
 *	of its copyright holder(s), and is made available	*
 *	under a license.  If you do not know the terms of	*
 *	the license, please stop and do not read further.	*
 *								*
 ****************************************************************/

#include "mdef.h"

#include "gtm_string.h"

#include "gdsroot.h"
#include "gdsblk.h"
#include "gtm_facility.h"
#include "fileinfo.h"
#include "gdsbt.h"
#include "gdsfhead.h"
#include "rc.h"
#include "copy.h"
#include "error.h"
#include "gtcm.h"
#include "gvcst_protos.h"	/* for gvcst_put prototype */
#include "hashtab_mname.h"	/* for COMPUTE_HASH_MNAME prototype */

GBLREF gv_key 		*gv_currkey;
GBLREF gv_namehead 	*gv_target;
GBLREF int		rc_set_fragment;
GBLREF gd_region	*gv_cur_region;
GBLREF gd_addr		*gd_header;

int rc_prc_setf(rc_q_hdr *qhdr)
{
    rc_set	*req, *rsp;
    short	 data_off, str_remain, *ptr;
    char	*cp1;
    int		 i;
    mval	 v;
    mname_entry	gvname;
    gvnh_reg_t	*gvnh_reg;

    ESTABLISH_RET(rc_dbms_ch, RC_SUCCESS);
    if ((qhdr->a.erc.value = rc_fnd_file(&qhdr->r.xdsid)) != RC_SUCCESS)
    {
	REVERT;
#ifdef DEBUG
	gtcm_cpktdmp((char *)qhdr,qhdr->a.len.value,"rc_fnd_file failed.");
#endif
	return -1;
    }
    rsp = req = (rc_set *)qhdr;
    v.mvtype = MV_STR;
    for (cp1 = req->key.key; *cp1; cp1++)
	;
    v.str.len = INTCAST(cp1 - req->key.key);
    v.str.addr = req->key.key;
	if (v.str.len > 8)	/* GT.M does not support global variables > 8 chars */
	{	qhdr->a.erc.value = RC_KEYTOOLONG;
		REVERT;
#ifdef DEBUG
	gtcm_cpktdmp((char *)qhdr,qhdr->a.len.value,"RC_KEYTOOLONG.");
#endif
		return -1;
	}
	gvname.var_name = v.str;
	COMPUTE_HASH_MNAME(&gvname);
	GV_BIND_NAME_AND_ROOT_SEARCH(gd_header, &gvname, gvnh_reg);
	assert(NULL == gvnh_reg->gvspan); /* so GV_BIND_SUBSNAME_IF_GVSPAN is not needed */
    memcpy(gv_currkey->base, req->key.key, req->key.len.value);
    gv_currkey->end = req->key.len.value;
    gv_currkey->base[gv_currkey->end] = 0;
    for (i = gv_currkey->end - 2; i > 0; i--)
	if (!gv_currkey->base[i - 1])
	    break;
    gv_currkey->prev = i;

    ptr = (short*)(req->key.key + req->key.len.value);
    GET_SHORT(v.str.len, ptr);
    ptr++;
    GET_SHORT(data_off ,ptr);
    ptr++;
    GET_SHORT(str_remain ,ptr);
    ptr++;
    if (gv_currkey->end + 1 + v.str.len + SIZEOF(rec_hdr) > gv_cur_region->max_rec_size)
    {
	qhdr->a.erc.value = RC_KEYTOOLONG;
#ifdef DEBUG
	gtcm_cpktdmp((char *)qhdr,qhdr->a.len.value,"RC_KEYTOOLONG.");
#endif
    }
    else  /* the total record will fit into a block */
    {
	if (rc_set_fragment = data_off) /* just send fragment */
	{
	    v.str.len = v.str.len - data_off - str_remain;
	    v.str.addr = (char*)ptr;
	}
	else			/* first fragment, put whole record, with zero filler */
	{
	    v.str.addr = (char*)malloc(v.str.len);
	    memset(v.str.addr, 0, v.str.len);
	    memcpy(v.str.addr + data_off, ptr, v.str.len - data_off - str_remain);
	}
	v.mvtype = MV_STR;
	gvcst_put(&v);

	if (rc_set_fragment)
	    rc_set_fragment = 0;
	else
	    free(v.str.addr);
    }

    REVERT;
    return ((qhdr->a.erc.value == RC_SUCCESS) ? 0 : -1);

}