/***************************************************************** program: malloc args: size in kB example: malloc 1024 author: Thomas Belmer *****************************************************************/ #include #include main( int argc, char *argv[ ], char *envp[ ] ) { char *MallocPuffer = NULL; size_t st_Size = 0; if (argc!=2) { printf("malloc ver. 0.1\n"); printf("usage: malloc [size in kB (1024 octetts)]\n"); printf("example: malloc 1024\n"); printf("return value: 0 if successful, else 1.\n"); return(1); } st_Size=(size_t)atol(argv[1]); printf("Allocating %d kB (%d octetts)...",st_Size,st_Size*1024); if ( (MallocPuffer = malloc(st_Size*1024)) != NULL ) { printf(" Ok.\n"); return(0); } else { printf("\nNot enough memory to allocate %d octetts.\n",st_Size*1024); return(1); } }