Subject Re: DLL Requirements
Author iananewby
Hi All,
I have been checking this further and it seems that the udfs that
fail all call malloc internally.
in the udf lib below the fn_blob_length works as expected but the
fn_blob_substr returns an empty string on my machine but a populated
on on other machines!!!

Can anyone shed any light on why this is occuring?

Regards
Ian Newby

/*****************************************************************
* File Name: wmudflib.c
* Description:
* This module contains some user defined functions to operate on
blobs.
* example.h taken fromthe interbase examples v5 to support multi
platform
* compilation.
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
*****************************************************************/

#include <string.h>
#include <ibase.h>
#include "example.h"

/****************************************************************/

typedef struct blob {
short (*blob_get_segment) ();
void *blob_handle;
long blob_number_segments;
long blob_max_segment;
long blob_total_length;
void (*blob_put_segment) ();
} *BLOB;

/****************************************************************/
long EXPORT fn_blob_length (ARG(BLOB, sourceBlob))
ARGLIST(BLOB sourceBlob) {
/****************************************************************
fn_blob_length() returns the number of bytes in a blob
****************************************************************/
if (!sourceBlob->blob_handle) {
return 0L;
}
return (sourceBlob->blob_total_length);
}

/****************************************************************/
char* EXPORT fn_blob_substr(ARG(BLOB, sourceBlob), ARG(long*,
startPos), ARG(long*, endPos), ARG(char*, sResult))
ARGLIST(BLOB sourceBlob)
ARGLIST(long *startPos)
ARGLIST(long *endPos)
ARGLIST(char *sResult) {
/****************************************************************
fn_blob_substr() returns portion of TEXT blob beginning at the
startPos character and ended at the endPos character.
****************************************************************/
char *pbuffer;
long i = 0;
long curr_bytecount = 0;
long startChar, endChar;
unsigned short length, actual_length;
long bOffset = 0;
long rOffset = 0;
long bytesRead = 0;
*sResult = 0;
if (!sourceBlob->blob_handle) {
return sResult;
}
length = sourceBlob->blob_max_segment + 1L;
if (*startPos > *endPos || *startPos < 1L || *endPos < 1L) {
return sResult;
}
if (sourceBlob->blob_total_length < (long)*startPos) {
return sResult;
}
startChar = *startPos;
if (sourceBlob->blob_total_length < (long)*endPos) {
endChar = sourceBlob->blob_total_length;
} else {
endChar = *endPos;
}
pbuffer = (char *) malloc (length + 1L);
while ((*sourceBlob->blob_get_segment) (sourceBlob->blob_handle,
pbuffer, length, &actual_length)) {
bOffset = 0;
while ((bOffset < actual_length) && (bytesRead < endChar)) {
if (bytesRead >= startChar) {
sResult[rOffset++] = pbuffer[bOffset];
}
bytesRead++;
bOffset++;
}
if (bytesRead >= endChar) {
sResult[rOffset] = 0;
break;
}
}
free (pbuffer);
return sResult;
}