File: ghash_set.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (19 lines) | stat: -rw-r--r-- 485 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string.h>
#include "ghash.h"

/** Replace or add an entry into a generic hash table. */
void* ghash_set(struct ghash* d, const void* key, const void* data)
{
  void* e;
  void* dataptr;

  if ((e = ghash_get(d, key)) == 0)
    return ghash_add(d, key, data);

  dataptr = ghash_entry_dataptr(e, d->keysize);
  if (d->datacopy == 0)
    memcpy(dataptr, data, d->entrysize - d->keysize - sizeof(adt_hash_t));
  else if (!d->datacopy(dataptr, data))
    return 0;
  return e;
}