.title calloc Allocate and Initialize Memory .ident /000003/ ; ;+ ; ; Index Allocate and initialize memory ; ; Usage ; ; char * ; calloc(n, m); /* NULL if no space */ ; int n; /* Number of elements */ ; int m; /* Size of an element */ ; ; Description ; ; Calloc() allocates space for n elements, each m bytes long. ; On return, the space is zero'ed. The program image will ; be expanded as needed. ; ; If the requested space cannot be allocated, calloc() returns NULL. ; ; See also the description of malloc(), realloc() and sbrk(). ; ; The space is returned by calling free(). ; ; Diagnostics ; ; Bugs ; ;- ; ; Edit history ; 000001 28-Jul-80 MM (Complete rewrite of alloc()) ; 000002 05-Aug-80 MM Real dumb bug. Talk about clever. ; 000003 09-Jul-82 JSL Use .sob in the "clear core" loop. ; .psect c$code calloc:: jsr r5,csv$ ; Get some registers mov c$pmtr+0(r5),-(sp) ; Get size in bytes. mov c$pmtr+2(r5),-(sp) ; call mul$i ; size = (nbr * size of each) mov r0,r4 ; Save size. (cret$ clears the stack) call $$aloc ; Try to allocate the space. mov r0,r3 ; Copy pointer to allocated space. beq 30$ ; NULL? if so, just duck. inc r4 ; Round byte count up... ;03+ clc ; (Make sure ror shifts in a 0.) ror r4 ; ...into a word count. ; (This relys on $$aloc's rounding ; the request up, too.) beq 30$ ; Nothing really to do? Leave. ;03- 10$: clr (r3)+ ; Clear another .sob r4,10$ ; Repeat as indicated ;03 30$: ;02 jmp cret$ ; Done. .end