int lmc_set_lock_flag(void *base, lmc_error_t *e) {
  lmc_mem_descriptor_t *md = base;
  if (md->locked != 0) {
    lmc_handle_error_with_err_string("lmc_set_lock_flag",
        "Failed to lock shared memory--may be corrupt!", "ShmLockFailed", e);
    return 0;
  } else {
    md->locked = 1;
  }
  return 1;
}
int lmc_release_lock_flag(void *base, lmc_error_t *e) {
  lmc_mem_descriptor_t *md = base;
  if (md->locked != 1) {
    lmc_handle_error_with_err_string("lmc_release_lock_flag",
        "Shared memory appears to be unlocked already--may be corrupt!", 
        "ShmUnlockFailed", e);
    return 0;
  } else {
    md->locked = 0;
  }
  return 1;
}
Exemple #3
0
int ht_set(void *base, va_ht_hash_t va_ht, const char *key,
           const char *value, lmc_error_t *e) {
    ht_hash_t *ht = base + va_ht;
    ht_hash_entry_t *hr = ht_lookup(base, va_ht, key);
    unsigned v;
    if (hr->va_key == 0) {
        va_ht_hash_entry_t va = lmc_valloc(base, sizeof(ht_hash_entry_t));
        hr = va ? base + va : 0;
        if (hr == NULL || (hr->va_key = ht_strdup(base, key)) == 0) {
            lmc_handle_error_with_err_string("ht_set", "memory pool full", e);
            return 0;
        }
        v = ht_hash_key(key);
        hr->va_next = ht->va_buckets[v];
        ht->va_buckets[v] = va;
    } else {
        lmc_free(base, hr->va_value);
    }
    if ((hr->va_value = ht_strdup(base, value)) == 0) {
        lmc_handle_error_with_err_string("ht_set", "memory pool full", e);
        return 0;
    }
    return 1;
}
int lmc_namespace_or_filename(char *result, const char* ons, const char *ofn,
    lmc_error_t *e) {
  if (ons) {
    lmc_clean_string(result, ons);
    return 1;
  }
  if (ofn) {
    size_t n = strlen(ofn);
    if (n > 1010) { n = 1010; }
    char *d = result;
    if (!lmc_is_filename(ofn)) {
      strcpy(d, "./");
      d += 2;
    }
    strcpy(d, ofn);
    return 1;
  }
  lmc_handle_error_with_err_string("lmc_namespace_or_filename", 
      "Need to supply either namespace or filename argument", "ArgError", e);
  return 0;
}
Exemple #5
0
int lmc_handle_error(int check, const char *ctx, const char *error_type, 
    char *handle, lmc_error_t *e) {
  if (!check) { return LMC_OK; } 
  return lmc_handle_error_with_err_string(ctx, strerror(errno), error_type, 
    handle, e);
}