FairCom Corporation


F.3 AddCtResource


Add a Resource to a data file.

SHORT NAME

ADDRES

TYPE

Low level file resource function

DECLARATION

COUNT AddCtResource(COUNT filno, pVOID resptr, VRLEN varlen)

DESCRIPTION

AddCtResource is used to add a Resource to file filno. Every Resource is identified by a unique combination of a Resource Type and a Resource Number. The Resource Number can optionally be assigned by c-tree Plus during the call to AddCtResource. In addition, each Resource can be identified by a Resource Name. The Resource Name is not guaranteed to be unique.

resptr points to a resource data block. This block contains the following fields:

Byte Offset
Data Type
Field Name
0 - 3
unsigned long integer
Resource Type
4 - 7
unsigned long integer
Resource Number
8 - m
null terminated character string
Resource Name
m+1 - n
any collection of data types desired
Resource Information

The Resource Type must be a value greater than 65536. 0 through 65536 are reserved for FairCom use.

If the Resource Number is a value of 0xffffffffL, c-tree Plus assigns this Resource the next available Resource Number for this Resource Type in the specified data file. AddCtResource places assigned Resource Number in the Resource Data Block.

The Resource Name is optional. c-tree Plus does not guarantee unique Resource Names. Names starting with "FC!" or "RD!", are reserved for FairCom use.

The Resource Information is any collection of data that you wish to store as a Resource. It can be a character string, a structure, or any variable type.

RETURN

Value
Symbolic Constant
Explanation
0
NO_ERROR
Successful addition of a new Resource.
37
WRITE_ERR
Most likely disk or directory is full. Files are left in an indeterminate state and should be rebuilt
147
VDLFLG_ERR
Attempt to re-use a data record that is still active. Apparently, the data file is corrupted in which case you should rebuild the file.
401
RNON_ERR
Resources have not been enabled for this data file.
403
RZRO_ERR
Empty Resource ID.
405
RDUP_ERR
Resource ID already added. There must be a unique combination of Type and Number.

See Appendix A "c-tree Plus Error Codes" of the c-tree Plus Programmer's Reference Guide for a complete listing of valid c-tree Plus error values.

EXAMPLE

/* add a resource and retrieve using GetCtResource */
struct { /* Resource Data Block structure */
ULONG resource_type;
ULONG resource_number;
TEXT variable_info[1016]; * Holds Resource Name and Data */
} my_resource;
my_resource.resource_type = 0x10001L; /* 65537 */ my_resource.resource_number = 0xffffffffL; /* c-tree Plus to
assign number */ strcpy(my_resource.variable_info,"MY!resource"); strcpy(my_resource.variable_info + 12,"Actual Resource Data");
if (AddCtResource(filno,&my_resource,
(VRLEN)(8+12 + strlen(my_resource.variable_info+12))) == 0 ) {
printf("\nThe resource has been assigned number %ld",
my_resource.resource_number);
printf("\nThe resource is located at byte offset %ld.", GetCtRe- source(filno,"MY!resource",&my_resource,1024L,RES_NAME); } else
printf("\nCould not add resource. Error #%d",uerr_cod);

Limitations

The recbyt parameter in this function is a 4-byte value capable of addressing at most 4 gigabytes. If your application supports HUGE files (greater than 4 gigabytes), you must use the ctSetHgh() and ctGetHgh() functions to set or get the high order 4 bytes of the file offset.

SEE ALSO

GetCtResource, UpdateCtResource, and DeleteCtResource. Section 8.1 "Resources" on page 8-1 in c-tree Plus Programmer's Reference Guide.


FairCom Corporation
www.faircom.com