Product Documentation

FairCom DB API for C

Previous Topic

Next Topic

ctdbSetResourceData

Set the resource data.

DECLARATION

CTDBRET ctdbDECL ctdbSetResourceData(CTHANDLE resource, cpVOID data, VRLEN size);

DESCRIPTION

Set the resource data. The internal resource buffer is resized and the resource data is copied. If the resource data parameter is NULL, the internal resource data buffer is released.

  • resource is a handle allocated with ctdbAllocHandle().
  • data is a pointer to resource data. If data is NULL the internal resource data buffer is cleared. size indicate the number of bytes pointed by data.

RETURN

ctdbSetResourceData() return CTDBRET_OK on success.

EXAMPLE

CTDBRET ReadMyResource(CTHANDLE Handle, ULONG type, ULONG number, ppVOID data, pVRLEN size)

{

CTDBRET eRet;

CTHANDLE hRes = ctdbAllocResource(Handle, type, number, NULL);

/* check the resource handle allocation */

if (hRes == NULL)

{

eRet = ctdbGetError(Handle);

goto Exit;

}

/* get the resource */

if ((eRet = ctdbFindResource(hRes, type, number, NO)) != CTDBRET_OK)

goto Exit;

/* allocate a buffer large enough for the resource data */

*size = ctdbGetResourceDataLength(hRes);

if (*size > 0)

{

*data = (pVOID)malloc(*size);

if (*data == NULL)

{

eRet = CTDBRET_NOMEMORY;

goto Exit;

}

memcpy(*data, ctdbGetResourceData(hRes), *size);

}

Exit:

if (hRes)

ctdbFreeResource(hRes);

return eRet;

}

SEE ALSO

ctdbAllocResource(), ctdbFreeResource(), ctdbAddResource(), ctdbDeleteResource(), ctdbUpdateResource(), ctdbFirstResource(), ctdbNextResource(), ctdbFindResource(), ctdbFindResourceByName(), ctdbGetResourceType(), ctdbGetResourceNumber(), ctdbSetResourceNumber(), ctdbGetResourceName(), ctdbSetResourceName(), ctdbGetResourceDataLength(), ctdbGetResourceData(), ctdbSetResourceType(), ctdbIsResourceLocked(), ctdbUnlockResource()

TOCIndex