void test_list_remove_data (void) { list *l = list_empty(); assert(list_remove_head(l) == NULL); element *tmp = NULL; element* e1 = element_init("plop"); element* e2 = element_init("plap"); element* e3 = element_init("plup"); list_add_head(l,e1); list_add_head(l,e2); assert(list_remove_data(l,"plup") == NULL); list_add_head(l,e3); tmp = list_remove_data(l,"plup"); assert( tmp == e3); assert(l->head == e2); free(tmp); tmp = list_remove_data(l,"plop"); assert( tmp == e1); assert(l->head == e2); assert(e2->next == NULL); free(tmp); list_free(l); printf("Les tests de list_remove_data sont réussis!\n"); }
int main() { struct list *l; struct node *n; struct node *n1; printf("\ntesting node_create..."); n = node_create('e'); n1 = node_create('i'); if( n == NULL || n->c != 'e' || n->next != NULL ) goto fail; if( n1 == NULL || n1->c != 'i' || n1->next != NULL ) goto fail; printf("[ok]\n"); printf("\ntesting list_create..."); l = list_create(); if(l) printf("[ok]\n"); else goto fail; printf("testing list_add_head..."); list_add_head(l,n); if (l->head != n) goto fail; list_add_head(l,n1); if(l->head != n1) goto fail; printf("[ok]\n"); printf("testing list_find..."); if ( list_find( l, 'e' ) != n || list_find( l, 'i' ) != n1 ) goto fail; printf("[ok]\n"); printf("testing list_del..."); list_del(l, n); if(l->head == n) goto fail; else printf("[ok]\n"); printf("testing list_find..."); if ( list_find( l, 'e' ) != NULL || list_find( l, 'i' ) != n1 ) goto fail; printf("[ok]\n"); return 0; fail: printf("[failed]\n"); return -1; }
struct wined3d_rendertarget_view *d3d8_surface_acquire_rendertarget_view(struct d3d8_surface *surface) { HRESULT hr; /* The surface reference count can be equal to 0 when this function is * called. In order to properly manage the render target view reference * count, we temporarily increment the surface reference count. */ d3d8_surface_AddRef(&surface->IDirect3DSurface8_iface); if (surface->wined3d_rtv) return surface->wined3d_rtv; if (FAILED(hr = wined3d_rendertarget_view_create_from_sub_resource(surface->wined3d_texture, surface->sub_resource_idx, surface, &d3d8_view_wined3d_parent_ops, &surface->wined3d_rtv))) { ERR("Failed to create rendertarget view, hr %#x.\n", hr); d3d8_surface_Release(&surface->IDirect3DSurface8_iface); return NULL; } if (surface->texture) list_add_head(&surface->texture->rtv_list, &surface->rtv_entry); return surface->wined3d_rtv; }
void add_2_active(t_r_peer *peer) { list_head_t *alllist = allto + syscall(SYS_gettid)%threadcount; INIT_LIST_HEAD(&(peer->alist)); peer->last = time(NULL); list_add_head(&(peer->alist), alllist); }
struct dbg_thread* dbg_add_thread(struct dbg_process* p, DWORD tid, HANDLE h, void* teb) { struct dbg_thread* t = HeapAlloc(GetProcessHeap(), 0, sizeof(struct dbg_thread)); if (!t) return NULL; t->handle = h; t->tid = tid; t->teb = teb; t->process = p; t->exec_mode = dbg_exec_cont; t->exec_count = 0; t->step_over_bp.enabled = FALSE; t->step_over_bp.refcount = 0; t->stopped_xpoint = -1; t->in_exception = FALSE; t->frames = NULL; t->num_frames = 0; t->curr_frame = -1; t->addr_mode = AddrModeFlat; snprintf(t->name, sizeof(t->name), "%04x", tid); list_add_head(&p->threads, &t->entry); return t; }
static int cache_insert( struct idmap_cache *cache, const struct idmap_lookup *lookup, const struct list_entry *src) { struct list_entry *entry; int status = NO_ERROR; AcquireSRWLockExclusive(&cache->lock); /* search for an existing match */ entry = list_search(&cache->head, lookup->value, lookup->compare); if (entry) { /* overwrite the existing entry with the new results */ cache->ops->entry_copy(entry, src); goto out; } /* initialize a new entry and add it to the list */ entry = cache->ops->entry_alloc(); if (entry == NULL) { status = GetLastError(); goto out; } cache->ops->entry_copy(entry, src); list_add_head(&cache->head, entry); out: ReleaseSRWLockExclusive(&cache->lock); return status; }
static HRESULT StdMemAllocator_Alloc(IMemAllocator * iface) { StdMemAllocator *This = (StdMemAllocator *)iface; StdMediaSample2 * pSample = NULL; SYSTEM_INFO si; long i; assert(list_empty(&This->base.free_list)); /* check alignment */ GetSystemInfo(&si); /* we do not allow a courser alignment than the OS page size */ if ((si.dwPageSize % This->base.pProps->cbAlign) != 0) return VFW_E_BADALIGN; /* FIXME: each sample has to have its buffer start on the right alignment. * We don't do this at the moment */ /* allocate memory */ This->pMemory = VirtualAlloc(NULL, (This->base.pProps->cbBuffer + This->base.pProps->cbPrefix) * This->base.pProps->cBuffers, MEM_COMMIT, PAGE_READWRITE); for (i = This->base.pProps->cBuffers - 1; i >= 0; i--) { /* pbBuffer does not start at the base address, it starts at base + cbPrefix */ BYTE * pbBuffer = (BYTE *)This->pMemory + i * (This->base.pProps->cbBuffer + This->base.pProps->cbPrefix) + This->base.pProps->cbPrefix; StdMediaSample2_Construct(pbBuffer, This->base.pProps->cbBuffer, iface, &pSample); list_add_head(&This->base.free_list, &pSample->listentry); } return S_OK; }
static HRESULT WINAPI BaseMemAllocator_GetBuffer(IMemAllocator * iface, IMediaSample ** pSample, REFERENCE_TIME *pStartTime, REFERENCE_TIME *pEndTime, DWORD dwFlags) { BaseMemAllocator *This = impl_from_IMemAllocator(iface); HRESULT hr = S_OK; /* NOTE: The pStartTime and pEndTime parameters are not applied to the sample. * The allocator might use these values to determine which buffer it retrieves */ TRACE("(%p)->(%p, %p, %p, %x)\n", This, pSample, pStartTime, pEndTime, dwFlags); *pSample = NULL; EnterCriticalSection(This->pCritSect); if (!This->bCommitted || This->bDecommitQueued) { WARN("Not committed\n"); hr = VFW_E_NOT_COMMITTED; } else ++This->lWaiting; LeaveCriticalSection(This->pCritSect); if (FAILED(hr)) return hr; if (WaitForSingleObject(This->hSemWaiting, (dwFlags & AM_GBF_NOWAIT) ? 0 : INFINITE) != WAIT_OBJECT_0) { EnterCriticalSection(This->pCritSect); --This->lWaiting; LeaveCriticalSection(This->pCritSect); WARN("Timed out\n"); return VFW_E_TIMEOUT; } EnterCriticalSection(This->pCritSect); { --This->lWaiting; if (!This->bCommitted) hr = VFW_E_NOT_COMMITTED; else if (This->bDecommitQueued) hr = VFW_E_TIMEOUT; else { StdMediaSample2 *ms; struct list * free = list_head(&This->free_list); list_remove(free); list_add_head(&This->used_list, free); ms = LIST_ENTRY(free, StdMediaSample2, listentry); assert(ms->ref == 0); *pSample = (IMediaSample *)&ms->IMediaSample2_iface; IMediaSample_AddRef(*pSample); } } LeaveCriticalSection(This->pCritSect); if (hr != S_OK) WARN("%08x\n", hr); return hr; }
void test_list_add_head (void) { list *l = list_empty(); char* c1 = "plop"; char* c2 = "plap"; list_add_head(l, element_init(c1)); assert(l->head->data == c1); list_add_head(l, element_init(c2)); assert(l->head->data == c2); list_free(l); printf("Les tests de list_add_head sont réussis!\n"); }
/* retrieve the mapping parameters for an executable (PE) image */ static int get_image_params( struct mapping *mapping ) { IMAGE_DOS_HEADER dos; IMAGE_NT_HEADERS nt; IMAGE_SECTION_HEADER *sec = NULL; struct fd *fd; off_t pos; int unix_fd, size, toread; /* load the headers */ if (!(fd = mapping_get_fd( &mapping->obj ))) return 0; if ((unix_fd = get_unix_fd( fd )) == -1) goto error; if (pread( unix_fd, &dos, sizeof(dos), 0 ) != sizeof(dos)) goto error; if (dos.e_magic != IMAGE_DOS_SIGNATURE) goto error; pos = dos.e_lfanew; if (pread( unix_fd, &nt.Signature, sizeof(nt.Signature), pos ) != sizeof(nt.Signature)) goto error; pos += sizeof(nt.Signature); if (nt.Signature != IMAGE_NT_SIGNATURE) goto error; if (pread( unix_fd, &nt.FileHeader, sizeof(nt.FileHeader), pos ) != sizeof(nt.FileHeader)) goto error; pos += sizeof(nt.FileHeader); /* zero out Optional header in the case it's not present or partial */ memset(&nt.OptionalHeader, 0, sizeof(nt.OptionalHeader)); toread = min( sizeof(nt.OptionalHeader), nt.FileHeader.SizeOfOptionalHeader ); if (pread( unix_fd, &nt.OptionalHeader, toread, pos ) != toread) goto error; pos += nt.FileHeader.SizeOfOptionalHeader; /* load the section headers */ size = sizeof(*sec) * nt.FileHeader.NumberOfSections; if (!(sec = malloc( size ))) goto error; if (pread( unix_fd, sec, size, pos ) != size) goto error; if (!build_shared_mapping( mapping, unix_fd, sec, nt.FileHeader.NumberOfSections )) goto error; if (mapping->shared_file) list_add_head( &shared_list, &mapping->shared_entry ); mapping->size = ROUND_SIZE( nt.OptionalHeader.SizeOfImage ); mapping->base = (void *)nt.OptionalHeader.ImageBase; mapping->header_size = pos + size; mapping->protect = VPROT_IMAGE; /* sanity check */ if (mapping->header_size > mapping->size) goto error; free( sec ); release_object( fd ); return 1; error: if (sec) free( sec ); release_object( fd ); set_error( STATUS_INVALID_FILE_FOR_SECTION ); return 0; }
int vm_translation_map_create(vm_translation_map *new_map, bool kernel) { ASSERT(new_map); // initialize the new object new_map->ops = &tmap_ops; new_map->map_count = 0; if(recursive_lock_create(&new_map->lock) < 0) return ERR_NO_MEMORY; new_map->arch_data = kmalloc(sizeof(vm_translation_map_arch_info)); if(new_map->arch_data == NULL) { recursive_lock_destroy(&new_map->lock); return ERR_NO_MEMORY; } if (!kernel) { // user vm_page *page = vm_page_allocate_page(PAGE_STATE_CLEAR); list_add_head(&new_map->arch_data->pagetable_list, &page->queue_node); new_map->arch_data->pgdir_phys = page->ppn * PAGE_SIZE; get_physical_page_tmap(page->ppn * PAGE_SIZE, (addr_t *)&new_map->arch_data->pgdir_virt, PHYSICAL_PAGE_NO_WAIT); // copy the kernel bits into this one (one entry at the top) memcpy(new_map->arch_data->pgdir_virt + 256, (unsigned long *)kernel_pgdir_virt + 256, sizeof(unsigned long) * 256); } else { // kernel top level page dir is already allocated new_map->arch_data->pgdir_phys = kernel_pgdir_phys; new_map->arch_data->pgdir_virt = (unsigned long *)kernel_pgdir_virt; vm_page *page = vm_lookup_page(kernel_pgdir_phys / PAGE_SIZE); TMAP_TRACE("page %p, state %d\n", page, page->state); list_add_head(&new_map->arch_data->pagetable_list, &page->queue_node); // zero out the bottom of it, where user space mappings would go memset(new_map->arch_data->pgdir_virt, 0, sizeof(unsigned long) * 256); // XXX account for prexisting kernel page tables } return 0; }
/* grab a mutex for a given thread */ static void do_grab( struct mutex *mutex, struct thread *thread ) { assert( !mutex->count || (mutex->owner == thread) ); if (!mutex->count++) /* FIXME: avoid wrap-around */ { assert( !mutex->owner ); mutex->owner = thread; list_add_head( &thread->mutex_list, &mutex->entry ); } }
void *vbsheap_alloc(vbsheap_t *heap, size_t size) { struct list *list; void *tmp; size = (size+3)&~3; if(!heap->block_cnt) { if(!heap->blocks) { heap->blocks = heap_alloc(sizeof(void*)); if(!heap->blocks) return NULL; } tmp = heap_alloc(block_size(0)); if(!tmp) return NULL; heap->blocks[0] = tmp; heap->block_cnt = 1; } if(heap->offset + size <= block_size(heap->last_block)) { tmp = ((BYTE*)heap->blocks[heap->last_block])+heap->offset; heap->offset += size; return tmp; } if(size <= block_size(heap->last_block+1)) { if(heap->last_block+1 == heap->block_cnt) { tmp = heap_realloc(heap->blocks, (heap->block_cnt+1)*sizeof(void*)); if(!tmp) return NULL; heap->blocks = tmp; heap->blocks[heap->block_cnt] = heap_alloc(block_size(heap->block_cnt)); if(!heap->blocks[heap->block_cnt]) return NULL; heap->block_cnt++; } heap->last_block++; heap->offset = size; return heap->blocks[heap->last_block]; } list = heap_alloc(size + sizeof(struct list)); if(!list) return NULL; list_add_head(&heap->custom_blocks, list); return list+1; }
/** * @brief Add a string to the console text */ void text_draw(int x, int y, const char *string) { struct text_line *line = malloc(sizeof(struct text_line)); line->str = strdup(string); line->x = x; line->y = y; list_add_head(&text_list, &line->node); text_update(); }
int usb_pm_register_callback(struct device *dev, void (*cb)(bool, void*), void *priv) { struct usb_pm_info *usb_dev = (struct usb_pm_info*)dev->priv; // Alloc memory for cb and priv argument struct usb_pm_cb_list *item = (struct usb_pm_cb_list*)balloc(sizeof(struct usb_pm_cb_list), NULL); // Fill new allocated item item->priv = priv; item->cb = cb; // Add item in list list_add_head(&usb_dev->cb_head, (list_t*)item); return 0; }
static HRESULT WINAPI BaseMemAllocator_ReleaseBuffer(IMemAllocator * iface, IMediaSample * pSample) { BaseMemAllocator *This = impl_from_IMemAllocator(iface); StdMediaSample2 * pStdSample = unsafe_impl_from_IMediaSample(pSample); HRESULT hr = S_OK; TRACE("(%p)->(%p)\n", This, pSample); /* FIXME: make sure that sample is currently on the used list */ /* FIXME: we should probably check the ref count on the sample before freeing * it to make sure that it is not still in use */ EnterCriticalSection(This->pCritSect); { if (!This->bCommitted) ERR("Releasing a buffer when the allocator is not committed?!?\n"); /* remove from used_list */ list_remove(&pStdSample->listentry); list_add_head(&This->free_list, &pStdSample->listentry); if (list_empty(&This->used_list) && This->bDecommitQueued && This->bCommitted) { HRESULT hrfree; if (This->lWaiting != 0) ERR("Waiting: %d\n", This->lWaiting); This->bCommitted = FALSE; This->bDecommitQueued = FALSE; CloseHandle(This->hSemWaiting); This->hSemWaiting = NULL; if (FAILED(hrfree = This->fnFree(iface))) ERR("fnFree failed with error 0x%x\n", hrfree); } } LeaveCriticalSection(This->pCritSect); /* notify a waiting thread that there is now a free buffer */ if (This->hSemWaiting && !ReleaseSemaphore(This->hSemWaiting, 1, NULL)) { ERR("ReleaseSemaphore failed with error %u\n", GetLastError()); hr = HRESULT_FROM_WIN32(GetLastError()); } return hr; }
static struct undo_item *add_undo( ME_TextEditor *editor, enum undo_type type ) { struct undo_item *undo, *item; struct list *head; if (editor->nUndoMode == umIgnore) return NULL; if (editor->nUndoLimit == 0) return NULL; undo = heap_alloc( sizeof(*undo) ); if (!undo) return NULL; undo->type = type; if (editor->nUndoMode == umAddToUndo || editor->nUndoMode == umAddBackToUndo) { head = list_head( &editor->undo_stack ); if (head) { item = LIST_ENTRY( head, struct undo_item, entry ); if (item->type == undo_potential_end_transaction) item->type = undo_end_transaction; } if (editor->nUndoMode == umAddToUndo) TRACE("Pushing id=%d to undo stack, deleting redo stack\n", type); else TRACE("Pushing id=%d to undo stack\n", type); list_add_head( &editor->undo_stack, &undo->entry ); if (type == undo_end_transaction || type == undo_potential_end_transaction) editor->nUndoStackSize++; if (editor->nUndoStackSize > editor->nUndoLimit) { struct undo_item *cursor2; /* remove oldest undo from stack */ LIST_FOR_EACH_ENTRY_SAFE_REV( item, cursor2, &editor->undo_stack, struct undo_item, entry ) { BOOL done = (item->type == undo_end_transaction); list_remove( &item->entry ); destroy_undo_item( item ); if (done) break; } editor->nUndoStackSize--; } /* any new operation (not redo) clears the redo stack */ if (editor->nUndoMode == umAddToUndo) empty_redo_stack( editor ); }
void test_list_is_end_mark (void) { list *l = list_empty(); assert(list_is_end_mark(l->head)); char* c1 = "plop"; list_add_head(l, element_init(c1)); assert(!list_is_end_mark(l->head)); assert(list_is_end_mark(l->head->next)); list_free(l); printf("Les tests de list_is_end_mark sont réussis!\n"); }
static int mutex_satisfied( struct object *obj, struct thread *thread ) { struct mutex *mutex = (struct mutex *)obj; assert( obj->ops == &mutex_ops ); assert( !mutex->count || (mutex->owner == thread) ); if (!mutex->count++) /* FIXME: avoid wrap-around */ { assert( !mutex->owner ); mutex->owner = thread; list_add_head( &thread->mutex_list, &mutex->entry ); } if (!mutex->abandoned) return 0; mutex->abandoned = 0; return 1; }
void heap_delayed_free(void *ptr) { LTRACEF("ptr %p\n", ptr); // check for the old allocation structure struct alloc_struct_begin *as = (struct alloc_struct_begin *)ptr; as--; DEBUG_ASSERT(as->magic == HEAP_MAGIC); struct free_heap_chunk *chunk = heap_create_free_chunk(as->ptr, as->size, false); enter_critical_section(); list_add_head(&theheap.delayed_free_list, &chunk->node); exit_critical_section(); }
static status_t mount(const char *path, const char *device, const struct fs_api *api) { struct fs_mount *mount; char temppath[FS_MAX_PATH_LEN]; strlcpy(temppath, path, sizeof(temppath)); fs_normalize_path(temppath); if (temppath[0] != '/') return ERR_BAD_PATH; /* see if there's already something at this path, abort if there is */ mount = find_mount(temppath, NULL); if (mount) { put_mount(mount); return ERR_ALREADY_MOUNTED; } /* open a bio device if the string is nonnull */ bdev_t *dev = NULL; if (device && device[0] != '\0') { dev = bio_open(device); if (!dev) return ERR_NOT_FOUND; } /* call into the fs implementation */ fscookie *cookie; status_t err = api->mount(dev, &cookie); if (err < 0) { if (dev) bio_close(dev); return err; } /* create the mount structure and add it to the list */ mount = malloc(sizeof(struct fs_mount)); mount->path = strdup(temppath); mount->dev = dev; mount->cookie = cookie; mount->ref = 1; mount->api = api; list_add_head(&mounts, &mount->node); return 0; }
HRESULT d3drm_object_add_destroy_callback(struct d3drm_object *object, D3DRMOBJECTCALLBACK cb, void *ctx) { struct destroy_callback *callback; if (!cb) return D3DRMERR_BADVALUE; callback = HeapAlloc(GetProcessHeap(), 0, sizeof(*callback)); if (!callback) return E_OUTOFMEMORY; callback->cb = cb; callback->ctx = ctx; list_add_head(&object->destroy_callbacks, &callback->entry); return D3DRM_OK; }
void err_put(err_t * self) { assert(self != NULL); list_t *list = pthread_getspecific(__err_key); if (list == NULL) { list = (list_t *) malloc(sizeof(*list)); assert(list != NULL); list_init(list); assert(pthread_setspecific(__err_key, list) == 0); } list_add_head(list, &self->node); return; }
void heap_delayed_free(void *ptr) { LTRACEF("ptr %p\n", ptr); // check for the old allocation structure struct alloc_struct_begin *as = (struct alloc_struct_begin *)ptr; as--; DEBUG_ASSERT(as->magic == HEAP_MAGIC); struct free_heap_chunk *chunk = heap_create_free_chunk(as->ptr, as->size, false); spin_lock_saved_state_t state; spin_lock_irqsave(&theheap.delayed_free_lock, state); list_add_head(&theheap.delayed_free_list, &chunk->node); spin_unlock_irqrestore(&theheap.delayed_free_lock, state); }
static HRESULT WINAPI BaseMemAllocator_GetBuffer(IMemAllocator * iface, IMediaSample ** pSample, REFERENCE_TIME *pStartTime, REFERENCE_TIME *pEndTime, DWORD dwFlags) { BaseMemAllocator *This = (BaseMemAllocator *)iface; HRESULT hr = S_OK; /* NOTE: The pStartTime and pEndTime parameters are not applied to the sample. * The allocator might use these values to determine which buffer it retrieves */ TRACE("(%p)->(%p, %p, %p, %lx)\n", This, pSample, pStartTime, pEndTime, dwFlags); *pSample = NULL; if (!This->bCommitted) return VFW_E_NOT_COMMITTED; This->lWaiting++; if (WaitForSingleObject(This->hSemWaiting, (dwFlags & AM_GBF_NOWAIT) ? 0 : INFINITE) != WAIT_OBJECT_0) { This->lWaiting--; return VFW_E_TIMEOUT; } This->lWaiting--; EnterCriticalSection(&This->csState); { if (!This->bCommitted) hr = VFW_E_NOT_COMMITTED; else if (This->bDecommitQueued) hr = VFW_E_TIMEOUT; else { struct list * free = list_head(&This->free_list); list_remove(free); list_add_head(&This->used_list, free); *pSample = (IMediaSample *)LIST_ENTRY(free, StdMediaSample2, listentry); assert(((StdMediaSample2 *)*pSample)->ref == 0); IMediaSample_AddRef(*pSample); } } LeaveCriticalSection(&This->csState); return hr; }
/********************************************************************** * DRIVER_load_driver */ const DC_FUNCTIONS *DRIVER_load_driver( LPCWSTR name ) { HMODULE module; struct graphics_driver *driver, *new_driver; static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 }; static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0}; /* display driver is a special case */ if (!strcmpiW( name, displayW ) || !strcmpiW( name, display1W )) return DRIVER_get_display_driver(); if ((module = GetModuleHandleW( name ))) { if (display_driver && display_driver->module == module) return &display_driver->funcs; EnterCriticalSection( &driver_section ); LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry ) { if (driver->module == module) goto done; } LeaveCriticalSection( &driver_section ); } if (!(module = LoadLibraryW( name ))) return NULL; if (!(new_driver = create_driver( module ))) { FreeLibrary( module ); return NULL; } /* check if someone else added it in the meantime */ EnterCriticalSection( &driver_section ); LIST_FOR_EACH_ENTRY( driver, &drivers, struct graphics_driver, entry ) { if (driver->module != module) continue; FreeLibrary( module ); HeapFree( GetProcessHeap(), 0, new_driver ); goto done; } driver = new_driver; list_add_head( &drivers, &driver->entry ); TRACE( "loaded driver %p for %s\n", driver, debugstr_w(name) ); done: LeaveCriticalSection( &driver_section ); return &driver->funcs; }
void managed_comparator_register_callback(struct td_device *dev, void (*cb)(bool, void *), void *priv) { struct managed_comparator_info *managed_comparator_dev = (struct managed_comparator_info *)dev->priv; /* Alloc memory for cb and priv argument */ struct managed_comparator_cb_list *item = (struct managed_comparator_cb_list *)balloc(sizeof(struct managed_comparator_cb_list), NULL); /* Fill new allocated item */ item->priv = priv; item->cb = cb; /* Add item in list */ list_add_head(&managed_comparator_dev->cb_head, (list_t *)item); }
void test_list_add_head( ) { list_type *list; TEST_INIT("list_add_head", "testing"); list = NULL; list = list_add_head(list, (void *) 'g'); DUMP_POINTERS(list); list = list_add_head(list, (void *) 'n'); DUMP_POINTERS(list); list = list_add_head(list, (void *) 'i'); DUMP_POINTERS(list); list = list_add_head(list, (void *) 't'); DUMP_POINTERS(list); list = list_add_head(list, (void *) 's'); DUMP_POINTERS(list); list = list_add_head(list, (void *) 'e'); DUMP_POINTERS(list); list = list_add_head(list, (void *) 't'); DUMP_POINTERS(list); TEST_FINISH(list); }
static HRESULT WINAPI httprequest_setRequestHeader(IXMLHTTPRequest *iface, BSTR header, BSTR value) { httprequest *This = impl_from_IXMLHTTPRequest( iface ); struct reqheader *entry; TRACE("(%p)->(%s %s)\n", This, debugstr_w(header), debugstr_w(value)); if (!header || !*header) return E_INVALIDARG; if (This->state != READYSTATE_LOADING) return E_FAIL; if (!value) return E_INVALIDARG; /* replace existing header value if already added */ LIST_FOR_EACH_ENTRY(entry, &This->reqheaders, struct reqheader, entry) { if (lstrcmpW(entry->header, header) == 0) { LONG length = SysStringLen(entry->value); HRESULT hr; hr = SysReAllocString(&entry->value, value) ? S_OK : E_OUTOFMEMORY; if (hr == S_OK) This->reqheader_size += (SysStringLen(entry->value) - length); return hr; } } entry = heap_alloc(sizeof(*entry)); if (!entry) return E_OUTOFMEMORY; /* new header */ entry->header = SysAllocString(header); entry->value = SysAllocString(value); /* header length including null terminator */ This->reqheader_size += SysStringLen(entry->header) + sizeof(colspaceW)/sizeof(WCHAR) + SysStringLen(entry->value) + sizeof(crlfW)/sizeof(WCHAR) - 1; list_add_head(&This->reqheaders, &entry->entry); return S_OK; }
void add_importlib(const char *name) { importlib_t *importlib; if(!typelib) return; LIST_FOR_EACH_ENTRY( importlib, &typelib->importlibs, importlib_t, entry ) if(!strcmp(name, importlib->name)) return; chat("add_importlib: %s\n", name); importlib = xmalloc(sizeof(*importlib)); memset( importlib, 0, sizeof(*importlib) ); importlib->name = xstrdup(name); read_importlib(importlib); list_add_head( &typelib->importlibs, &importlib->entry ); }