示例#1
0
void dsp_chunk_list::remove_bad_chunks()
{
	bool blah = false;
	t_size idx;
	for(idx=0;idx<get_count();)
	{
		audio_chunk * chunk = get_item(idx);
		if (!chunk->is_valid())
		{
			chunk->reset();
			remove_by_idx(idx);
			blah = true;
		}
		else idx++;
	}
	if (blah) console::info("one or more bad chunks removed from dsp chunk list");
}
示例#2
0
/**
 * Get a spell from the player.
 */
int textui_get_spell(const char *verb, item_tester book_filter,
					 cmd_code cmd, const char *error,
					 bool (*spell_filter)(int spell_index))
{
	char prompt[1024];
	struct object *book;

	/* Create prompt */
	strnfmt(prompt, sizeof prompt, "%s which book?", verb);
	my_strcap(prompt);

	if (!get_item(&book, prompt, error,
				  cmd, book_filter, (USE_INVEN | USE_FLOOR)))
		return -1;

	return textui_get_spell_from_book(verb, book, error, spell_filter);
}
示例#3
0
/**
 * \brief Returns the item currently assigned to a slot.
 * \param slot Slot of the item to get (1 or 2).
 * \return The item currently assigned to this slot or nullptr.
 */
EquipmentItem* Equipment::get_item_assigned(int slot) {

  // TODO don't hardcode item slots

  Debug::check_assertion(slot >= 1 && slot <= 2,
      "Invalid item slot");

  char savegame_variable[] = "_item_slot_0";
  savegame_variable[11] = '0' + slot;
  const std::string& item_name = savegame.get_string(savegame_variable);

  EquipmentItem* item = nullptr;
  if (!item_name.empty()) {
    item = &get_item(item_name);
  }
  return item;
}
void playlist_view_cache::on_items_change(unsigned p_playlist, const bit_array & p_mask)
{
	playlist_cache * p_cache = get_item(p_playlist);
	unsigned n, count = p_cache->get_count();
	for(n=0; n<count;n++)
	{
		if (p_mask[n])
		{
			playlist_entry_ui * entry = p_cache->get_item(n);
			if (entry) 
			{
				delete entry;
				p_cache->replace_item(n, 0);
			}
		}
	}
}
示例#5
0
void
missile(int ydelta, int xdelta)
{
    struct object *obj;
    struct linked_list *item, *nitem;

    /*
     * Get which thing we are hurling
     */
    if ((item = get_item("throw", WEAPON)) == NULL)
	return;
    obj = (struct object *) ldata(item);
    if (!dropcheck(obj) || is_current(obj))
	return;
    /*
     * Get rid of the thing.  If it is a non-multiple item object, or
     * if it is the last thing, just drop it.  Otherwise, create a new
     * item with a count of one.
     */
    if (obj->o_count < 2)
    {
	detach(pack, item);
	inpack--;
    }
    else
    {
	obj->o_count--;
	if (obj->o_group == 0)
	    inpack--;
	nitem = (struct linked_list *) new_item(sizeof *obj);
	obj = (struct object *) ldata(nitem);
	*obj = *((struct object *) ldata(item));
	obj->o_count = 1;
	item = nitem;
    }
    do_motion(obj, ydelta, xdelta);
    /*
     * AHA! Here it has hit something.  If it is a wall or a door,
     * or if it misses (combat) the mosnter, put it on the floor
     */
    if (!ismons(CMVWINCH(mw, obj->o_pos.y, obj->o_pos.x))
	|| !hit_monster(unc(obj->o_pos), obj))
	    fall(item, TRUE);
    mvwaddrawch(cw, hero.y, hero.x, PLAYER);
}
示例#6
0
/*
 * Remove the inscription from an object
 * XXX Mention item (when done)?
 */
void do_cmd_uninscribe(void)
{
	int item;

	object_type *o_ptr;

	cptr q, s;


	/* Get an item */
	q = "Un-inscribe which item? ";
	s = "You have nothing to un-inscribe.";
	if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;

	/* Get the item (in the pack) */
	if (item >= 0)
	{
		o_ptr = &inventory[item];
	}

	/* Get the item (on the floor) */
	else
	{
		o_ptr = &o_list[0 - item];
	}

	/* Nothing to remove */
	if (!o_ptr->note)
	{
		msg_print("That item had no inscription to remove.");
		return;
	}

	/* Message */
	msg_print("Inscription removed.");

	/* Remove the incription */
	o_ptr->note = 0;

	/* Combine the pack */
	p_ptr->notice |= (PN_COMBINE);

	/* Window stuff */
	p_ptr->window |= (PW_INVEN | PW_EQUIP);
}
示例#7
0
static protocol_binary_response_status prepend_handler(const void *cookie,
                                                       const void *key,
                                                       uint16_t keylen,
                                                       const void* val,
                                                       uint32_t vallen,
                                                       uint64_t cas,
                                                       uint64_t *result_cas) {
  (void)cookie;
  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;

  struct item *item= get_item(key, keylen);
  struct item *nitem= NULL;

  if (item == NULL)
  {
    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
  }
  else if (cas != 0 && cas != item->cas)
  {
    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
  }
  else if ((nitem= create_item(key, keylen, NULL, item->size + vallen,
                                 item->flags, item->exp)) == NULL)
  {
    rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
  }
  else
  {
    memcpy(nitem->data, val, vallen);
    memcpy(((char*)(nitem->data)) + vallen, item->data, item->size);
    release_item(item);
    item= NULL;
    delete_item(key, keylen);
    put_item(nitem);
    *result_cas= nitem->cas;
  }

  if (item)
    release_item(item);

  if (nitem)
    release_item(nitem);

  return rval;
}
示例#8
0
    int obtain( Character& ch ) override {
        if( !what ) {
            return INT_MIN;
        }

        // invalidate this item_location
        auto it = get_item();
        what = nullptr;

        int mv = 0;
        bool was_worn = false;

        item *holster = who->find_parent( *it );
        if( holster && who->is_worn( *holster ) && holster->can_holster( *it, true ) ) {
            // Immediate parent is a worn holster capable of holding this item
            auto ptr = dynamic_cast<const holster_actor *>( holster->type->get_use( "holster" )->get_actor_ptr() );
            mv += dynamic_cast<player *>( who )->item_handling_cost( *it, false, ptr->draw_cost );
            was_worn = true;
        } else {
            // Unpack the object followed by any nested containers starting with the innermost
            mv += dynamic_cast<player *>( who )->item_handling_cost( *it );
            for( auto obj = who->find_parent( *it ); obj && who->find_parent( *obj ); obj = who->find_parent( *obj ) ) {
                mv += dynamic_cast<player *>( who )->item_handling_cost( *obj );
            }
        }

        if( who->is_worn( *it ) ) {
            it->on_takeoff( *( dynamic_cast<player *>( who ) ) );
        } else if( !was_worn ) {
            mv *= INVENTORY_HANDLING_FACTOR;
        }

        if( &ch != who ) {
            // @todo implement movement cost for transfering item between characters
        }

        who->moves -= mv;

        if( &ch.i_at( ch.get_item_position( it ) ) == it ) {
            // item already in target characters inventory at base of stack
            return ch.get_item_position( it );
        } else {
            return ch.get_item_position( &ch.i_add( who->i_rem( it ) ) );
        }
    }
示例#9
0
void dsp_chain_config::get_name_list(pfc::string_base & p_out) const
{
	const t_size count = get_count();
	bool added = false;
	for(unsigned n=0;n<count;n++)
	{
		service_ptr_t<dsp_entry> ptr;
		if (dsp_entry::g_get_interface(ptr,get_item(n).get_owner()))
		{
			if (added) p_out += ", ";
			added = true;

			pfc::string8 temp;
			ptr->get_name(temp);
			p_out += temp;
		}
	}
}
示例#10
0
static protocol_binary_response_status get_handler(const void *cookie,
                                                   const void *key,
                                                   uint16_t keylen,
                                                   memcached_binary_protocol_get_response_handler response_handler) {
  struct item *item= get_item(key, keylen);

  if (item == NULL)
  {
    return PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
  }

  protocol_binary_response_status rc;
  rc= response_handler(cookie, key, (uint16_t)keylen,
                          item->data, (uint32_t)item->size, item->flags,
                          item->cas);
  release_item(item);
  return rc;
}
示例#11
0
	bool MediaServer::call_http(const http::http_request& /*req*/, const boost::filesystem::path& root, const boost::filesystem::path& rest, http::response& resp)
	{
		auto media_type = items::main_resource;
		if (root == "thumb") media_type = items::thumbnail;
		else if (root == "thumb-160") media_type = items::thumbnail_160;
		else if (root != "media") return false;

		auto item = get_item(rest.string());
		if (!item)
			return false;

		auto info = item->get_media(media_type);
		if (!info)
			return false;

		resp.header().clear(server());
		return info->prep_response(resp);
	}
示例#12
0
int sp_healing(struct castorder * co)
{
  fighter * fi = co->magician.fig;
  int level = co->level;
  double power = co->force;
  battle *b = fi->side->battle;
  unit *mage = fi->unit;
  int j = 0;
  int healhp = (int)power * 200;
  quicklist *fgs;
  message *msg;
  bool use_item = get_item(mage, I_AMULET_OF_HEALING) > 0;

  /* bis zu 11 Personen pro Stufe (einen HP müssen sie ja noch
   * haben, sonst wären sie tot) können geheilt werden */

  if (use_item) {
    healhp *= 2;
  }

  /* gehe alle denen wir helfen der reihe nach durch, heile verwundete,
   * bis zu verteilende HP aufgebraucht sind */

  fgs = fighters(b, fi->side, FIGHT_ROW, AVOID_ROW, FS_HELP);
  scramble_fighters(fgs);
  j += heal_fighters(fgs, &healhp, false);
  j += heal_fighters(fgs, &healhp, true);
  ql_free(fgs);

  if (j <= 0) {
    level = j;
  }
  if (use_item) {
    msg =
      msg_message("healing_effect_1", "mage amount item", mage, j,
      oldresourcetype[R_AMULET_OF_HEALING]);
  } else {
    msg = msg_message("healing_effect_0", "mage amount", mage, j);
  }
  message_all(b, msg);
  msg_release(msg);

  return level;
}
示例#13
0
/*
 * Take off an item
 */
void do_cmd_takeoff(void)
{
	int item;

	object_type *o_ptr;

	cptr q, s;


	/* Get an item */
	q = "Take off which item? ";
	s = "You are not wearing anything to take off.";
	if (!get_item(&item, q, s, (USE_EQUIP))) return;

	/* Get the item (in the pack) */
	if (item >= 0)
	{
		o_ptr = &inventory[item];
	}

	/* Get the item (on the floor) */
	else
	{
		o_ptr = &o_list[0 - item];
	}


	/* Item is cursed */
	if (cursed_p(o_ptr))
	{
		/* Oops */
		msg_print("Hmmm, it seems to be cursed.");

		/* Nope */
		return;
	}


	/* Take a partial turn */
	p_ptr->energy_use = 50;

	/* Take off the item */
	(void)inven_takeoff(item, 255);
}
示例#14
0
void
whatis(struct linked_list *what)
{
    struct object *obj;
    int kludge;
    int print_message = FALSE;

    if (what == NULL)
    {
        print_message = TRUE;

        while ((what = get_item("identify", 0)) == NULL)
            ;
    }

    obj = OBJPTR(what);
    obj->o_flags |= ISKNOW;

    switch (obj->o_type)
    {
        case SCROLL: kludge = TYP_SCROLL; break;
        case POTION: kludge = TYP_POTION; break;
        case STICK:  kludge = TYP_STICK;  break;
        case RING:   kludge = TYP_RING;   break;
        case WEAPON:
        case ARMOR:
        default:     kludge = -1;         break;
    }

    if (kludge != -1)
    {
        know_items[kludge][obj->o_which] = TRUE;

        if (guess_items[kludge][obj->o_which])
        {
            ur_free(guess_items[kludge][obj->o_which]);
            guess_items[kludge][obj->o_which] = NULL;
        }
    }

    if (print_message)
        msg(inv_name(obj, UPPERCASE));
}
示例#15
0
gpointer fslog_thread(gpointer d)
{
    while (TRUE) {
        struct item *item = get_item();

        int fd = openat(dir_fd, item->key, O_CREAT|O_WRONLY|O_TRUNC, 0666);
        g_assert(fd >= 0);

        writebuf(fd, item->data, item->len);

        finish_item(item);

        fsync(fd);
        fsync(dir_fd);
        close(fd);
    }

    return NULL;
}
示例#16
0
static void set_selector(SLIDER *slider, boolean draw, XDINFO *info)
{
	int i;
	FTYPE *f;
	OBJECT *o;

	for (i = 0; i < 4; i++)
	{
		o = &setmask[FTYPE1 + i];

		if ((f = get_item(i + slider->line)) == NULL)
			*o->ob_spec.tedinfo->te_ptext = 0;
		else
			cv_fntoform(o, f->name);				/* HR 240103 */
	}

	if (draw == TRUE)
		xd_draw(info, FTPARENT, MAX_DEPTH);
}
示例#17
0
	//	Match passed string against specified item descriptions and return details for matches
	//	Element in results array set to zero if their description matches the passed string
	//
	void List::filter_by_description(Uint8 *storage_items_filter, const ground_item *storage_items, const char *filter_item_text, int no_storage)
	{
		if (!info_available() || (no_storage<=0) || !storage_items_filter || !storage_items)
			return;
		std::string needle(filter_item_text);
		std::transform(needle.begin(), needle.end(), needle.begin(), tolower);
		for (size_t i=0; i<static_cast<size_t>(no_storage); i++)
		{
			storage_items_filter[i] = 1;
			Item *item = get_item(storage_items[i].id, storage_items[i].image_id);
			if (item)
			{
				std::string haystack(item->get_description());
				std::transform(haystack.begin(), haystack.end(), haystack.begin(), tolower);
				if (haystack.find(needle) != std::string::npos)
					storage_items_filter[i] = 0;
			}
		}
	}
示例#18
0
文件: pc2.c 项目: huaguang/OS_CD
void *calculate(void *arg)
{
    int i;
    int item;
    for (i = 0; i < ITEM_COUNT; i++) {
        sema_wait(&full_buffer1_sema);
        sema_wait(&buffer1_mutex_sema);
        item = get_item(&calOut,buffer1); 
        sema_signal(&buffer1_mutex_sema);
        sema_signal(&empty_buffer1_sema);
		item=item+'A'-'a';
        sema_wait(&empty_buffer2_sema);
        sema_wait(&buffer2_mutex_sema);
        put_item(item,&calIn,buffer2); 
        sema_signal(&buffer2_mutex_sema);
        sema_signal(&full_buffer2_sema);
        printf("    calculate item: %c\n", item);
    }
}
示例#19
0
void playlist_view_cache::update_active_columns(unsigned playlist)
{
	pfc::string8 playlist_name;
	static_api_ptr_t<playlist_manager> playlist_api;

	playlist_api->playlist_get_name(playlist, playlist_name);
		
	column_list_cref_t columns = playlist_view::g_get_columns();
	playlist_cache * p_cache = get_item(playlist);

	int s,e=columns.get_count();
	p_cache->m_active_columns.resize(e);
	for (s=0;s<e;s++)
	{
		bool b_valid = false;
		if (columns[s]->show)
		{
			switch(columns[s]->filter_type)
			{
			case FILTER_NONE:
				{
					b_valid = true;
					break;
				}
			case FILTER_SHOW:
				{
					if (wildcard_helper::test(playlist_name,columns[s]->filter,true))
						b_valid = true;
				}
				break;
			case FILTER_HIDE:
				{
					if (!wildcard_helper::test(playlist_name,columns[s]->filter,true))
						b_valid = true;
				}
				break;
			}
		}
		p_cache->m_active_columns.set(s, b_valid);
	}
	p_cache->m_active_columns_valid = true;
}
示例#20
0
/* returns 1 if it finds an indirect item and gets valid hint info
 * from it, otherwise 0
 */
static int get_left_neighbor(reiserfs_blocknr_hint_t *hint)
{
    struct path * path;
    struct buffer_head * bh;
    struct item_head * ih;
    int pos_in_item;
    __u32 * item;
    int ret = 0;

    if (!hint->path)		/* reiserfs code can call this function w/o pointer to path
				 * structure supplied; then we rely on supplied search_start */
        return 0;

    path = hint->path;
    bh = get_last_bh(path);
    RFALSE( !bh, "green-4002: Illegal path specified to get_left_neighbor");
    ih = get_ih(path);
    pos_in_item = path->pos_in_item;
    item = get_item (path);

    hint->search_start = bh->b_blocknr;

    if (!hint->formatted_node && is_indirect_le_ih (ih)) {
        /* for indirect item: go to left and look for the first non-hole entry
           in the indirect item */
        if (pos_in_item == I_UNFM_NUM (ih))
            pos_in_item--;
//	    pos_in_item = I_UNFM_NUM (ih) - 1;
        while (pos_in_item >= 0) {
            int t=get_block_num(item,pos_in_item);
            if (t) {
                hint->search_start = t;
                ret = 1;
                break;
            }
            pos_in_item --;
        }
    }

    /* does result value fit into specified region? */
    return ret;
}
示例#21
0
static protocol_binary_response_status decrement_handler(const void *cookie,
                                                         const void *key,
                                                         uint16_t keylen,
                                                         uint64_t delta,
                                                         uint64_t initial,
                                                         uint32_t expiration,
                                                         uint64_t *result,
                                                         uint64_t *result_cas) {
    protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
    uint64_t val= initial;
    item_t *item;

    (void)cookie;
    mutex_lock(&storage_lock);

    item = get_item(key, keylen);

    if (item != NULL) {
        if (delta > *(uint64_t*)item->data)
            val= 0;
        else
            val= *(uint64_t*)item->data - delta;

        expiration= (uint32_t)item->exp;
        release_item(item);
        delete_item(key, keylen);
    }

    item= create_item(key, keylen, NULL, sizeof(initial), 0, (time_t)expiration);
    if (item == 0) {
        rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
    } else {
        memcpy(item->data, &val, sizeof(val));
        put_item(item);
        *result= val;
        *result_cas= item->cas;
        release_item(item);
    }

    mutex_unlock(&storage_lock);
    return rval;
}
示例#22
0
	bool bin_index_t::file_node::set(const data_t& key,const data_t& val)
	{
		validate_key_len(key);
		open_index_file();

		if(!root_page)
		{
			root_page=create_page();
			append_page(*root_page);
			save_index_data(0,root_page->page_offset);
			add_page(root_page);
		}
		
		index_t it;
		align_key(key,it);

		if(get_item(it))
		{
			index_t old_i=it;

			if(it.data_len>=val.size())save_data(it.data_offset,val);
			else it.data_offset=append_data(val);
			it.data_len=val.size();

			if(old_i.data_offset==it.data_offset&&
				old_i.data_len==it.data_len)
				return false;

			update_page(it);
			return false;
		}

		index_t v;
		v.key=key;
		align_key(key,v);
		v.data_len=val.size();
		v.data_offset=append_data(val);

		add_item(v);

		return true;
	}
示例#23
0
/**
 * \brief Gives the treasure to the player.
 *
 * Adds the item to the hero's equipment.
 * The item should not be empty.
 */
void Treasure::give_to_player() const {

  Debug::check_assertion(!is_found(), "This treasure was already found");

  // Mark the treasure as found in the savegame.
  if (is_saved()) {
    game->get_savegame().set_boolean(savegame_variable, true);
  }

  // Give the item to the player.
  EquipmentItem& item = get_item();
  if (item.is_saved()) {
    item.set_variant(get_variant());
  }

  // Notify the Lua item and the Lua map.
  LuaContext& lua_context = game->get_lua_context();
  lua_context.item_on_obtaining(item, *this);
  lua_context.map_on_obtaining_treasure(game->get_current_map(), *this);
}
示例#24
0
bool DOSBoxMenu::nsMenuSubInit(DOSBoxMenu::item &p_item) {
    if (p_item.nsMenu == NULL) {
        p_item.nsMenu = sdl_hax_nsMenuAlloc(p_item.get_text().c_str());
        if (p_item.nsMenu != NULL) {
            for (auto id : p_item.display_list.disp_list) {
                DOSBoxMenu::item &item = get_item(id);

                /* if a submenu, make the submenu */
                if (item.type == submenu_type_id) {
                    item.parent_id = p_item.master_id;
                    nsMenuSubInit(item);
                }

                item.nsAppendMenu(p_item.nsMenu);
            }
        }
    }

    return true;
}
示例#25
0
bool DOSBoxMenu::winMenuSubInit(DOSBoxMenu::item &p_item) {
    if (p_item.winMenu == NULL) {
        p_item.winMenu = CreatePopupMenu();
        if (p_item.winMenu != NULL) {
            for (auto id : p_item.display_list.disp_list) {
                DOSBoxMenu::item &item = get_item(id);

                /* if a submenu, make the submenu */
                if (item.type == submenu_type_id) {
                    item.parent_id = p_item.master_id;
                    winMenuSubInit(item);
                }

                item.winAppendMenu(p_item.winMenu);
            }
        }
    }

    return true;
}
 int ObTicketQueue::tail(int64_t& seq, void*& data)
 {
   int err = OB_SUCCESS;
   Item* item = NULL;
   if (NULL == items_)
   {
     err = OB_NOT_INIT;
   }
   else if (pop_ >= push_)
   {
     err = OB_ENTRY_NOT_EXIST;
   }
   else
   {
     item = get_item(pop_);
     seq = item->seq_;
     data = item->data_;
   }
   return err;
 }
static void put_name(bd_addr_t bd_addr, device_name_t *device_name){
    db_mem_device_name_t * existingRecord = (db_mem_device_name_t *) get_item(db_mem_names, bd_addr);
    
    if (existingRecord){
        strncpy(existingRecord->device_name, (const char*) device_name, MAX_NAME_LEN);
        return;
    }
    
    // Record not found, create a new one for this device
    db_mem_device_name_t * newItem = btstack_memory_db_mem_device_name_get();
    if (!newItem) {
        newItem = (db_mem_device_name_t*)linked_list_get_last_item(&db_mem_names);
    };

    if (!newItem) return;
    
    memcpy(newItem->device.bd_addr, bd_addr, sizeof(bd_addr_t));
    strncpy(newItem->device_name, (const char*) device_name, MAX_NAME_LEN);
    linked_list_add(&db_mem_names, (linked_item_t *) newItem);
}
示例#28
0
文件: pcp105.c 项目: gkar/Programs
void *consumer(void *arg2)
{
  int myitem;

  for( ; ; ) {
    sem_wait(&items);
    pthread_mutex_lock(&my_lock);
    if(!producer_done) {
      pthread_mutex_unlock(&my_lock);
      get_item(&myitem);
      sem_post(&slots);
      sum += myitem;      
    } else {
      pthread_mutex_unlock(&my_lock);
      break;
    }
  }

  return NULL;
}
示例#29
0
static void put_link_key(bd_addr_t *bd_addr, link_key_t *link_key){
    db_mem_device_link_key_t * existingRecord = (db_mem_device_link_key_t *) get_item(db_mem_link_keys, bd_addr);
    
    if (existingRecord){
        memcpy(existingRecord->link_key, link_key, LINK_KEY_LEN);
        return;
    }
    
    // Record not found, create new one for this device
    db_mem_device_link_key_t * newItem = (db_mem_device_link_key_t*) btstack_memory_db_mem_device_link_key_get();
    if (!newItem){
        newItem = (db_mem_device_link_key_t*)linked_list_get_last_item(&db_mem_link_keys);
    }
    
    if (!newItem) return;
    
    memcpy(newItem->device.bd_addr, bd_addr, sizeof(bd_addr_t));
    memcpy(newItem->link_key, link_key, LINK_KEY_LEN);
    linked_list_add(&db_mem_link_keys, (linked_item_t *) newItem);
}
示例#30
0
static protocol_binary_response_status replace_handler(const void *cookie,
                                                       const void *key,
                                                       uint16_t keylen,
                                                       const void* data,
                                                       uint32_t datalen,
                                                       uint32_t flags,
                                                       uint32_t exptime,
                                                       uint64_t cas,
                                                       uint64_t *result_cas) {
  (void)cookie;
  protocol_binary_response_status rval= PROTOCOL_BINARY_RESPONSE_SUCCESS;
  struct item* item= get_item(key, keylen);

  if (item == NULL)
  {
    rval= PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
  }
  else if (cas == 0 || cas == item->cas)
  {
    release_item(item);
    delete_item(key, keylen);
    item= create_item(key, keylen, data, datalen, flags, (time_t)exptime);
    if (item == 0)
    {
      rval= PROTOCOL_BINARY_RESPONSE_ENOMEM;
    }
    else
    {
      put_item(item);
      *result_cas= item->cas;
      release_item(item);
    }
  }
  else
  {
    rval= PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS;
    release_item(item);
  }

  return rval;
}