本文整理汇总了C++中PR_MALLOC函数的典型用法代码示例。如果您正苦于以下问题:C++ PR_MALLOC函数的具体用法?C++ PR_MALLOC怎么用?C++ PR_MALLOC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PR_MALLOC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MimeInlineTextVCard_parse_line
static int
MimeInlineTextVCard_parse_line (const char *line, int32_t length, MimeObject *obj)
{
// This routine gets fed each line of data, one at a time.
char* linestring;
MimeInlineTextVCardClass *clazz = ((MimeInlineTextVCardClass *) obj->clazz);
if (!obj->output_p) return 0;
if (!obj->options || !obj->options->output_fn) return 0;
if (!obj->options->write_html_p)
{
return COM_MimeObject_write(obj, line, length, true);
}
linestring = (char *) PR_MALLOC (length + 1);
memset(linestring, 0, (length + 1));
if (linestring)
{
strcpySafe((char *)linestring, line, length + 1);
NS_MsgSACat (&clazz->vCardString, linestring);
PR_Free (linestring);
}
return 0;
}
示例2: MimeUntypedText_yenc_begin_line_p
static bool MimeUntypedText_yenc_begin_line_p(const char *line, int32_t length,
MimeDisplayOptions *opt,
char **type_ret,
char **name_ret) {
const char *s;
const char *endofline = line + length;
char *name = 0;
char *type = 0;
if (type_ret) *type_ret = 0;
if (name_ret) *name_ret = 0;
/* we don't support yenc V2 neither multipart yencode,
therefore the second parameter should always be "line="*/
if (length < 13 || strncmp(line, "=ybegin line=", 13)) return false;
/* ...then couple digits. */
for (s = line + 13; s < endofline; s++)
if (*s < '0' || *s > '9') break;
/* ...next, look for <space>size= */
if ((endofline - s) < 6 || strncmp(s, " size=", 6)) return false;
/* ...then couple digits. */
for (s += 6; s < endofline; s++)
if (*s < '0' || *s > '9') break;
/* ...next, look for <space>name= */
if ((endofline - s) < 6 || strncmp(s, " name=", 6)) return false;
/* anything left is the file name */
s += 6;
name = (char *)PR_MALLOC((endofline - s) + 1);
if (!name) return false; /* grr... */
memcpy(name, s, endofline - s);
name[endofline - s] = 0;
/* take off newline. */
if (name[strlen(name) - 1] == '\n') name[strlen(name) - 1] = 0;
if (name[strlen(name) - 1] == '\r') name[strlen(name) - 1] = 0;
/* Now try and figure out a type.
*/
if (opt && opt->file_type_fn)
type = opt->file_type_fn(name, opt->stream_closure);
else
type = 0;
if (name_ret)
*name_ret = name;
else
PR_FREEIF(name);
if (type_ret)
*type_ret = type;
else
PR_FREEIF(type);
return true;
}
示例3: PR_MALLOC
nsresult
RDFContentSinkImpl::AddText(const PRUnichar* aText, PRInt32 aLength)
{
// Create buffer when we first need it
if (0 == mTextSize) {
mText = (PRUnichar *) PR_MALLOC(sizeof(PRUnichar) * 4096);
if (!mText) {
return NS_ERROR_OUT_OF_MEMORY;
}
mTextSize = 4096;
}
// Copy data from string into our buffer; grow the buffer as needed.
// It never shrinks, but since the content sink doesn't stick around,
// this shouldn't be a bloat issue.
PRInt32 amount = mTextSize - mTextLength;
if (amount < aLength) {
// Grow the buffer by at least a factor of two to prevent thrashing.
// Since PR_REALLOC will leave mText intact if the call fails,
// don't clobber mText or mTextSize until the new mem is allocated.
PRInt32 newSize = (2 * mTextSize > (mTextSize + aLength)) ?
(2 * mTextSize) : (mTextSize + aLength);
PRUnichar* newText =
(PRUnichar *) PR_REALLOC(mText, sizeof(PRUnichar) * newSize);
if (!newText)
return NS_ERROR_OUT_OF_MEMORY;
mTextSize = newSize;
mText = newText;
}
memcpy(&mText[mTextLength], aText, sizeof(PRUnichar) * aLength);
mTextLength += aLength;
return NS_OK;
}
示例4: FilterWithoutEnglishLetters
//This filter apply to all scripts that does not use latin letters (english letter)
PRBool SBCSGroupProber::FilterWithoutEnglishLetters(const char* aBuf, PRUint32 aLen, char** newBuf, PRUint32& newLen)
{
//do filtering to reduce load to probers
char *newptr;
char *prevPtr, *curPtr;
PRBool meetMSB = PR_FALSE;
newptr = *newBuf = (char*)PR_MALLOC(aLen);
if (!newptr)
return PR_FALSE;
for (curPtr = prevPtr = (char*)aBuf; curPtr < aBuf+aLen; curPtr++)
{
if (*curPtr & 0x80)
meetMSB = PR_TRUE;
else if (*curPtr < 'A' || (*curPtr > 'Z' && *curPtr < 'a') || *curPtr > 'z')
{
//current char is a symbol, most likely a punctuation. we treat it as segment delimiter
if (meetMSB && curPtr > prevPtr)
//this segment contains more than single symbol, and it has upper ascii, we need to keep it
{
while (prevPtr < curPtr) *newptr++ = *prevPtr++;
prevPtr++;
*newptr++ = ' ';
meetMSB = PR_FALSE;
}
else //ignore current segment. (either because it is just a symbol or just a english word
prevPtr = curPtr+1;
}
}
newLen = newptr - *newBuf;
return PR_TRUE;
}
示例5: assembleCmdLine
/*
* Assemble the command line by concatenating the argv array.
* Special characters intentionally do not get escaped, and it is
* expected that the caller wraps arguments in quotes if needed
* (e.g. for filename with spaces).
*
* On success, this function returns 0 and the resulting command
* line is returned in *cmdLine. On failure, it returns -1.
*/
static int assembleCmdLine(char *const *argv, char **cmdLine)
{
char *const *arg;
int cmdLineSize;
/*
* Find out how large the command line buffer should be.
*/
cmdLineSize = 1; /* final null */
for (arg = argv+1; *arg; arg++) {
cmdLineSize += strlen(*arg) + 1; /* space in between */
}
*cmdLine = PR_MALLOC(cmdLineSize);
if (*cmdLine == NULL) {
return -1;
}
(*cmdLine)[0] = '\0';
for (arg = argv+1; *arg; arg++) {
if (arg > argv +1) {
strcat(*cmdLine, " ");
}
strcat(*cmdLine, *arg);
}
return 0;
}
示例6: return
/* binary block Allocate and Concatenate
*
* destination_length is the length of the existing block
* source_length is the length of the block being added to the
* destination block
*/
static char *il_BACat (char **destination,
size_t destination_length,
const char *source,
size_t source_length)
{
if (source) {
if (*destination) {
*destination = (char *) PR_REALLOC (*destination,
destination_length + source_length);
if (*destination == nsnull)
return (nsnull);
memmove(*destination + destination_length, source, source_length);
}
else {
*destination = (char *) PR_MALLOC (source_length);
if (*destination == nsnull)
return (nsnull);
memcpy(*destination, source, source_length);
}
}
return *destination;
}
示例7: MimeHeaders_copy
MimeHeaders *
MimeHeaders_copy (MimeHeaders *hdrs)
{
MimeHeaders *hdrs2;
if (!hdrs) return 0;
hdrs2 = (MimeHeaders *) PR_MALLOC(sizeof(*hdrs));
if (!hdrs2) return 0;
memset(hdrs2, 0, sizeof(*hdrs2));
if (hdrs->all_headers)
{
hdrs2->all_headers = (char *) PR_MALLOC(hdrs->all_headers_fp);
if (!hdrs2->all_headers)
{
PR_Free(hdrs2);
return 0;
}
memcpy(hdrs2->all_headers, hdrs->all_headers, hdrs->all_headers_fp);
hdrs2->all_headers_fp = hdrs->all_headers_fp;
hdrs2->all_headers_size = hdrs->all_headers_fp;
}
hdrs2->done_p = hdrs->done_p;
if (hdrs->heads)
{
int i;
hdrs2->heads = (char **) PR_MALLOC(hdrs->heads_size
* sizeof(*hdrs->heads));
if (!hdrs2->heads)
{
PR_FREEIF(hdrs2->all_headers);
PR_Free(hdrs2);
return 0;
}
hdrs2->heads_size = hdrs->heads_size;
for (i = 0; i < hdrs->heads_size; i++)
{
hdrs2->heads[i] = (hdrs2->all_headers +
(hdrs->heads[i] - hdrs->all_headers));
}
}
return hdrs2;
}
示例8: DefaultAllocTable
/*
** Stubs for default hash allocator ops.
*/
static void * PR_CALLBACK
DefaultAllocTable(void *pool, PRSize size)
{
#if defined(XP_MAC)
#pragma unused (pool)
#endif
return PR_MALLOC(size);
}
示例9: MimeUntypedText_uu_begin_line_p
static bool MimeUntypedText_uu_begin_line_p(const char *line, int32_t length,
MimeDisplayOptions *opt,
char **type_ret, char **name_ret) {
const char *s;
char *name = 0;
char *type = 0;
if (type_ret) *type_ret = 0;
if (name_ret) *name_ret = 0;
if (strncmp(line, "begin ", 6)) return false;
/* ...then three or four octal digits. */
s = line + 6;
if (*s < '0' || *s > '7') return false;
s++;
if (*s < '0' || *s > '7') return false;
s++;
if (*s < '0' || *s > '7') return false;
s++;
if (*s == ' ')
s++;
else {
if (*s < '0' || *s > '7') return false;
s++;
if (*s != ' ') return false;
}
while (IS_SPACE(*s)) s++;
name = (char *)PR_MALLOC(((line + length) - s) + 1);
if (!name) return false; /* grr... */
memcpy(name, s, (line + length) - s);
name[(line + length) - s] = 0;
/* take off newline. */
if (name[strlen(name) - 1] == '\n') name[strlen(name) - 1] = 0;
if (name[strlen(name) - 1] == '\r') name[strlen(name) - 1] = 0;
/* Now try and figure out a type.
*/
if (opt && opt->file_type_fn)
type = opt->file_type_fn(name, opt->stream_closure);
else
type = 0;
if (name_ret)
*name_ret = name;
else
PR_FREEIF(name);
if (type_ret)
*type_ret = type;
else
PR_FREEIF(type);
return true;
}
示例10: _pr_context_create
pr_context* _pr_context_create(const PRcontextdesc* desc, PRuint width, PRuint height)
{
if (desc == NULL || desc->window == NULL || width <= 0 || height <= 0)
{
_pr_error_set(PR_ERROR_INVALID_ARGUMENT, __FUNCTION__);
return NULL;
}
// Create render context
pr_context* context = PR_MALLOC(pr_context);
// Setup bitmap info structure
BITMAPINFO* bmi = (&context->bmpInfo);
memset(bmi, 0, sizeof(BITMAPINFO));
bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi->bmiHeader.biWidth = (LONG)width;
bmi->bmiHeader.biHeight = (LONG)height;
bmi->bmiHeader.biPlanes = 1;
bmi->bmiHeader.biBitCount = 24;
bmi->bmiHeader.biCompression = BI_RGB;
// Setup context
context->wnd = *((HWND*)desc->window);
context->dc = GetDC(context->wnd);
context->dcBmp = CreateCompatibleDC(context->dc);
context->bmp = CreateCompatibleBitmap(context->dc, width, height);
context->colors = PR_CALLOC(pr_color, width*height);
context->width = width;
context->height = height;
SelectObject(context->dcBmp, context->bmp);
// Create color palette
context->colorPalette = PR_MALLOC(pr_color_palette);
_pr_color_palette_fill_r3g3b2(context->colorPalette);
// Initialize state machine
_pr_state_machine_init(&(context->stateMachine));
_pr_context_makecurrent(context);
return context;
}
示例11: MimePgpe_generate
static char*
MimePgpe_generate(void *output_closure)
{
const char htmlMsg[] = "<html><body><b>GEN MSG<b></body></html>";
char* msg = (char *) PR_MALLOC(strlen(htmlMsg) + 1);
if (msg)
PL_strcpy(msg, htmlMsg);
return msg;
}
示例12: _pr_vertexbuffer_create
pr_vertexbuffer* _pr_vertexbuffer_create()
{
pr_vertexbuffer* vertexBuffer = PR_MALLOC(pr_vertexbuffer);
vertexBuffer->numVertices = 0;
vertexBuffer->vertices = NULL;
_pr_ref_add(vertexBuffer);
return vertexBuffer;
}
示例13: MimeHeaders_new
MimeHeaders *
MimeHeaders_new (void)
{
MimeHeaders *hdrs = (MimeHeaders *) PR_MALLOC(sizeof(MimeHeaders));
if (!hdrs) return 0;
memset(hdrs, 0, sizeof(*hdrs));
hdrs->done_p = false;
return hdrs;
}
示例14: PR_IMPLEMENT
PR_IMPLEMENT(void) PR_SetLogBuffering(PRIntn buffer_size)
{
PR_LogFlush();
if (logBuf)
PR_DELETE(logBuf);
if (buffer_size >= LINE_BUF_SIZE) {
logp = logBuf = (char*) PR_MALLOC(buffer_size);
logEndp = logp + buffer_size;
}
}
示例15: getPRErrorText
// Release the retun value with PR_FREEIF
static char* getPRErrorText ()
{
PRInt32 errTextLen = PR_GetErrorTextLength ();
char *s = (char*)PR_MALLOC (errTextLen + 1);
if (s)
{
s[0] = '\0';
(void)PR_GetErrorText (s);
}
return s;
}