/****************************************************************************** * Fifo_create ******************************************************************************/ Fifo_Handle Fifo_create(Fifo_Attrs *attrs) { Fifo_Handle hFifo; BUF_Attrs bAttrs = BUF_ATTRS; if (attrs == NULL) { return NULL; } hFifo = MEM_calloc(Dmai_Bios_segid, sizeof(Fifo_Object), 0); if (hFifo == NULL) { Dmai_err0("Failed to allocate space for Fifo Object\n"); return NULL; } /* Allocate a buffer pool for messages */ bAttrs.segid = Dmai_Bios_segid; hFifo->hBufPool = BUF_create(attrs->maxElems, sizeof(Fifo_Elem), 0, &bAttrs); if (hFifo->hBufPool == NULL) { Dmai_err0("Failed to allocate space for buffer pool\n"); MEM_free(Dmai_Bios_segid, hFifo, sizeof(Fifo_Object)); return NULL; } /* initialize the object */ QUE_new(&hFifo->queue); SEM_new(&hFifo->sem, 0); SEM_new(&hFifo->mutex, 1); return hFifo; }
void IMG_addsecsize(Image_t *img, int secid, int size) { assert(img != NULL); Section_t *sec; sec = IMG_getsection(img, secid); if (!sec->virt) { if (sec->buf_data == NULL) { sec->buf_data = BUF_create(0); } BUF_addsize(sec->buf_data, size); sec->data = (uint8_t *)BUF_getptr(sec->buf_data); } sec->size += size; }
Buffer_t *BUF_createfromfile(const char *filename) { FILE *fs; Buffer_t *buffer; int size; fs = fopen(filename, "rb"); if (fs == NULL) return NULL; fseek(fs, 0, SEEK_END); size = ftell(fs); fseek(fs, 0, SEEK_SET); buffer = BUF_create(size); if (buffer != NULL) { BUF_setsize(buffer, size); size = fread(buffer->data, 1, size, fs); } fclose(fs); return buffer; }