本文整理汇总了C++中MyMalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ MyMalloc函数的具体用法?C++ MyMalloc怎么用?C++ MyMalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MyMalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TakeOwnershipOfFile
/**************************************************************************
* TakeOwnershipOfFile [[email protected]]
*
* Takes the ownership of the given file.
*
* PARAMS
* lpFileName [I] Name of the file
*
* RETURNS
* Success: ERROR_SUCCESS
* Failure: other
*/
DWORD WINAPI TakeOwnershipOfFile(LPCWSTR lpFileName)
{
SECURITY_DESCRIPTOR SecDesc;
HANDLE hToken = NULL;
PTOKEN_OWNER pOwner = NULL;
DWORD dwError;
DWORD dwSize;
TRACE("%s\n", debugstr_w(lpFileName));
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
return GetLastError();
if (!GetTokenInformation(hToken, TokenOwner, NULL, 0, &dwSize))
{
goto fail;
}
pOwner = (PTOKEN_OWNER)MyMalloc(dwSize);
if (pOwner == NULL)
{
CloseHandle(hToken);
return ERROR_NOT_ENOUGH_MEMORY;
}
if (!GetTokenInformation(hToken, TokenOwner, pOwner, dwSize, &dwSize))
{
goto fail;
}
if (!InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION))
{
goto fail;
}
if (!SetSecurityDescriptorOwner(&SecDesc, pOwner->Owner, FALSE))
{
goto fail;
}
if (!SetFileSecurityW(lpFileName, OWNER_SECURITY_INFORMATION, &SecDesc))
{
goto fail;
}
MyFree(pOwner);
CloseHandle(hToken);
return ERROR_SUCCESS;
fail:;
dwError = GetLastError();
MyFree(pOwner);
if (hToken != NULL)
CloseHandle(hToken);
return dwError;
}
示例2: SetupGetFileCompressionInfoW
/***********************************************************************
* SetupGetFileCompressionInfoW ([email protected])
*
* Get compression type and compressed/uncompressed sizes of a given file.
*
* PARAMS
* source [I] File to examine.
* name [O] Actual filename used.
* source_size [O] Size of compressed file.
* target_size [O] Size of uncompressed file.
* type [O] Compression type.
*
* RETURNS
* Success: ERROR_SUCCESS
* Failure: Win32 error code.
*/
DWORD WINAPI SetupGetFileCompressionInfoW( PCWSTR source, PWSTR *name, PDWORD source_size,
PDWORD target_size, PUINT type )
{
BOOL ret;
DWORD error, required;
LPWSTR actual_name;
TRACE("%s, %p, %p, %p, %p\n", debugstr_w(source), name, source_size, target_size, type);
if (!source || !name || !source_size || !target_size || !type)
return ERROR_INVALID_PARAMETER;
ret = SetupGetFileCompressionInfoExW( source, NULL, 0, &required, NULL, NULL, NULL );
if (!(actual_name = MyMalloc( required*sizeof(WCHAR) ))) return ERROR_NOT_ENOUGH_MEMORY;
ret = SetupGetFileCompressionInfoExW( source, actual_name, required, &required,
source_size, target_size, type );
if (!ret)
{
error = GetLastError();
MyFree( actual_name );
return error;
}
*name = actual_name;
return ERROR_SUCCESS;
}
示例3: sizeof
aServer *make_server(aClient *cptr)
{
aServer *serv = cptr->serv;
if (!serv)
{
serv = (aServer *)MyMalloc(sizeof(aServer));
memset(serv, 0, sizeof(aServer));
#ifdef DEBUGMODE
servs.inuse++;
#endif
cptr->serv = serv;
cptr->name = serv->namebuf;
*serv->namebuf = '\0';
serv->user = NULL;
serv->snum = -1;
*serv->by = '\0';
serv->up = NULL;
serv->refcnt = 1;
serv->nexts = NULL;
serv->prevs = NULL;
serv->bcptr = cptr;
serv->lastload = 0;
}
return cptr->serv;
}
示例4:
aClass *make_class()
{
aClass *tmp;
tmp = (aClass *)MyMalloc(sizeof(aClass));
return tmp;
}
示例5: init_events
int
init_events()
{
struct timeval tv;
struct event *timer = MyMalloc(sizeof(struct event));
// struct event *sigint = MyMalloc(sizeof(struct event));
ev_base = event_init();
event_set_log_callback(&libevent_log_cb);
if(evdns_init() == -1)
{
ilog(L_ERROR, "libevent dns init failed");
return FALSE;
}
ilog(L_DEBUG, "libevent init %p", ev_base);
memset(&tv, 0, sizeof(tv));
tv.tv_usec = 100;
event_set(timer, -1, EV_PERSIST, timer_callback, timer);
event_base_set(ev_base, timer);
evtimer_add(timer, &tv);
/* event_set(sigint, SIGINT, EV_SIGNAL|EV_PERSIST, sigint_callback, sigint);
event_add(sigint, NULL);*/
return TRUE;
}
示例6: crypt_pass
char *
crypt_pass(char *password, int encode)
{
EVP_MD_CTX *mdctx;
const EVP_MD *md;
unsigned char md_value[EVP_MAX_MD_SIZE];
char buffer[2*DIGEST_LEN + 1];
char *ret;
unsigned int md_len;
md = EVP_get_digestbyname(DIGEST_FUNCTION);
mdctx = EVP_MD_CTX_create();
EVP_MD_CTX_init(mdctx);
EVP_DigestInit_ex(mdctx, md, NULL);
EVP_DigestUpdate(mdctx, password, strlen(password));
EVP_DigestFinal_ex(mdctx, md_value, &md_len);
EVP_MD_CTX_destroy(mdctx);
if(encode)
{
base16_encode(buffer, sizeof(buffer), (char *)md_value, DIGEST_LEN);
DupString(ret, buffer);
}
else
{
ret = MyMalloc(DIGEST_LEN);
memcpy(ret, md_value, DIGEST_LEN);
}
return ret;
}
示例7: main
int main(int argc, char **argv)
{
char* pw, *crypted_pw;
crypt_mechs_root = (crypt_mechs_t*)MyMalloc(sizeof(crypt_mechs_t));
crypt_mechs_root->mech = NULL;
crypt_mechs_root->next = crypt_mechs_root->prev = NULL;
if (argc < 2)
{
show_help();
exit(0);
}
pw = parse_arguments(argc, argv);
load_mechs();
if (NULL == umkpasswd_conf->mech)
{
fprintf(stderr, "No mechanism specified.\n");
abort();
}
if (NULL == pw)
{
pw = getpass("Password: ");
}
crypted_pw = crypt_pass(pw, umkpasswd_conf->mech);
printf("Crypted Pass: %s\n", crypted_pw);
memset(pw, 0, strlen(pw));
return 0;
}
示例8: init_tree_parse
/* Initialize the msgtab parsing tree -orabidoo
*/
void init_tree_parse(struct Message *mptr)
{
int i;
struct Message *mpt = mptr;
for (i=0; mpt->cmd; mpt++)
i++;
qsort((void *)mptr, i, sizeof(struct Message),
(int (*)(const void *, const void *)) mcmp);
expect_malloc;
msg_tree_root = (MESSAGE_TREE *)MyMalloc(sizeof(MESSAGE_TREE));
malloc_log("init_tree_parse() allocating MESSAGE_TREE (%zd bytes) at %p",
sizeof(MESSAGE_TREE), (void *)msg_tree_root);
mpt = do_msg_tree(msg_tree_root, "", mptr);
/*
* this happens if one of the msgtab entries included characters
* other than capital letters -orabidoo
*/
if (mpt->cmd)
{
logprintf(L_CRIT, "bad msgtab entry: ``%s''\n", mpt->cmd);
exit(1);
}
}
示例9: AddBan
void
AddBan(char *who, struct Channel *cptr, char *ban)
{
time_t CurrTime = current_ts;
struct ChannelBan *tempban;
/* don't add any duplicates -- jilles */
if (FindBan(cptr, ban) != NULL)
return;
tempban = (struct ChannelBan *) MyMalloc(sizeof(struct ChannelBan));
memset(tempban, 0, sizeof(struct ChannelBan));
if (who)
tempban->who = MyStrdup(who);
tempban->mask = MyStrdup(ban);
tempban->when = CurrTime;
tempban->next = cptr->firstban;
tempban->prev = NULL;
if (tempban->next)
tempban->next->prev = tempban;
cptr->firstban = tempban;
} /* AddBan() */
示例10: UnicodeToMultiByte
/**************************************************************************
* UnicodeToMultiByte [[email protected]]
*
* Converts a Unicode string to a multi-byte string.
*
* PARAMS
* lpUnicodeStr [I] Unicode string to be converted
* uCodePage [I] Code page
*
* RETURNS
* Success: pointer to the converted multi-byte string
* Failure: NULL
*
* NOTE
* Use MyFree to release the returned multi-byte string.
*/
LPSTR WINAPI UnicodeToMultiByte(LPCWSTR lpUnicodeStr, UINT uCodePage)
{
LPSTR lpMultiByteStr;
int nLength;
TRACE("%s %d\n", debugstr_w(lpUnicodeStr), uCodePage);
nLength = WideCharToMultiByte(uCodePage, 0, lpUnicodeStr, -1,
NULL, 0, NULL, NULL);
if (nLength == 0)
return NULL;
lpMultiByteStr = MyMalloc(nLength);
if (lpMultiByteStr == NULL)
return NULL;
if (!WideCharToMultiByte(uCodePage, 0, lpUnicodeStr, -1,
lpMultiByteStr, nLength, NULL, NULL))
{
MyFree(lpMultiByteStr);
return NULL;
}
return lpMultiByteStr;
}
示例11: ReadLCDRegister
/***************************************************************************************************
*FunctionName: ReadLCDRegister
*Description: 读取屏幕寄存器值
*Input: reg -- 寄存器地址
* len -- 读取长度
*Output:
*Return:
*Author: xsx
*Date: 2016年12月12日11:01:48
***************************************************************************************************/
static void ReadLCDRegister(unsigned char reg, unsigned char len)
{
char *q = NULL;
txdat = MyMalloc(16);
if(txdat == NULL)
return;
memset(txdat, 0, 16);
q = txdat;
*q++ = LCD_Head_1;
*q++ = LCD_Head_2;
*q++ = 1 + 4;
*q++ = R_REGSITER;
*q++ = reg;
*q++ = len;
CalModbusCRC16Fun2(txdat+3, 1 + 2, q);
SendDataToQueue(GetUsart6TXQueue(), NULL, txdat, txdat[2]+3, 1, 50 / portTICK_RATE_MS, 100 / portTICK_RATE_MS, EnableUsart6TXInterrupt);
MyFree(txdat);
}
示例12: AddException
void
AddException(char *who, struct Channel *cptr, char *mask)
{
struct Exception *tempe;
/* don't add any duplicates -- jilles */
if (FindException(cptr, mask) != NULL)
return;
tempe = (struct Exception *) MyMalloc(sizeof(struct Exception));
memset(tempe, 0, sizeof(struct Exception));
if (who)
tempe->who = MyStrdup(who);
tempe->mask = MyStrdup(mask);
tempe->when = current_ts;
tempe->next = cptr->exceptlist;
tempe->prev = NULL;
if (tempe->next)
tempe->next->prev = tempe;
cptr->exceptlist = tempe;
} /* AddException() */
示例13: WriteLCDRegister
/***************************************************************************************************
*FunctionName: WriteRegister
*Description: 写寄存器
*Input: reg -- 寄存器地址
* data -- 写入数据
* datalen -- 写入数据的长度
*Output: 无
*Author: xsx
*Date: 2016年8月5日15:18:01
***************************************************************************************************/
static void WriteLCDRegister(unsigned char reg, void *data, unsigned char len)
{
char *q = NULL;
unsigned char *p = (unsigned char *)data;
unsigned char i=0;
txdat = MyMalloc(len + 10);
if(txdat == NULL)
return;
memset(txdat, 0, len + 10);
q = txdat;
*q++ = LCD_Head_1;
*q++ = LCD_Head_2;
*q++ = len+4;
*q++ = W_REGSITER;
*q++ = reg;
for(i=0; i<len; i++)
*q++ = *p++;
CalModbusCRC16Fun2(txdat+3, len + 2, q);
SendDataToQueue(GetUsart6TXQueue(), NULL, txdat, txdat[2]+3, 1, 50 / portTICK_RATE_MS, 100 / portTICK_RATE_MS, EnableUsart6TXInterrupt);
MyFree(txdat);
}
示例14: inithashtables
void inithashtables(void)
{
Reg int i;
clear_client_hash_table((_HASHSIZE) ? _HASHSIZE : HASHSIZE);
clear_uid_hash_table((_UIDSIZE) ? _UIDSIZE : UIDSIZE);
clear_channel_hash_table((_CHANNELHASHSIZE) ? _CHANNELHASHSIZE
: CHANNELHASHSIZE);
clear_sid_hash_table((_SIDSIZE) ? _SIDSIZE : SIDSIZE);
#ifdef USE_HOSTHASH
clear_hostname_hash_table((_HOSTNAMEHASHSIZE) ? _HOSTNAMEHASHSIZE :
HOSTNAMEHASHSIZE);
#endif
#ifdef USE_IPHASH
clear_ip_hash_table((_IPHASHSIZE) ? _IPHASHSIZE : IPHASHSIZE);
#endif
/*
* Moved multiplication out from the hashfunctions and into
* a pre-generated lookup table. Should save some CPU usage
* even on machines with a fast mathprocessor. -- Core
*/
hashtab = (u_int *) MyMalloc(256 * sizeof(u_int));
for (i = 0; i < 256; i++)
hashtab[i] = tolower((char)i) * 109;
}
示例15: init_begin
static int init_begin(adns_state *ads_r, adns_initflags flags, FBFILE *diagfile)
{
adns_state ads;
ads = MyMalloc(sizeof(*ads));
/* Under hybrid, MyMalloc would have aborted already */
#if 0
if (!ads) return errno;
#endif
ads->iflags= flags;
ads->diagfile= diagfile;
ads->configerrno= 0;
ADNS_LIST_INIT(ads->udpw);
ADNS_LIST_INIT(ads->tcpw);
ADNS_LIST_INIT(ads->childw);
ADNS_LIST_INIT(ads->output);
ads->forallnext= 0;
ads->nextid= 0x311f;
ads->udpsocket= ads->tcpsocket= -1;
adns__vbuf_init(&ads->tcpsend);
adns__vbuf_init(&ads->tcprecv);
ads->tcprecv_skip= 0;
ads->nservers= ads->nsortlist= ads->nsearchlist= ads->tcpserver= 0;
ads->searchndots= 1;
ads->tcpstate= server_disconnected;
timerclear(&ads->tcptimeout);
ads->searchlist= 0;
*ads_r= ads;
return 0;
}