#include stdio.h
#include stdlib.h
#include string.h
#if !defined(__wtypes_h__) && !defined(_SCODE_)
typedef unsigned int SCODE;
#define _SCODE_
#endif
#ifndef HANDLE // h
typedef void * HANDLE;
#endif
#ifndef S_OK
#define S_OK ((SCODE) 0)
#endif
#ifndef S_FAIL
#define S_FAIL ((SCODE) -1)
#endif
#ifndef UCHAR // uc
typedef unsigned char UCHAR;
#endif
SCODE my_malloc(HANDLE *ph,size_t size)
{
void *ptr=(void *)malloc(size);
if(ptr== NULL)
{
return S_FAIL;
}
*ph=ptr;
printf("ptr=%p\n",ptr);
return S_OK;
}
SCODE my_free(HANDLE *ph)
{
void *ptr=(void *)(*ph);
if(ptr != NULL)
{
free(ptr);
}
return S_OK;
}
int main()
{
HANDLE handle=NULL;
char *szMsg=NULL;
if(my_malloc(&handle,sizeof(char)*128)==S_OK)
{
szMsg=(char *)(handle);
strncpy(szMsg,"hello!",strlen("hello!"));
}
printf("szMsg=%p handle=%p\n",szMsg,handle);
printf("szMsg=%s\n",szMsg);
if(handle != NULL)
{
my_free(&handle);
}
return 0;
}
沒有留言:
張貼留言