Commit 2ef26e00 authored by Yoni Fogel's avatar Yoni Fogel

Converted all dos files to unix format (endlines only changed)

git-svn-id: file:///svn/tokudb@4327 c7de825b-a66e-492c-adef-691d508d4ae1
parent 6f7da789
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <limits.h>
#include <memory.h>
#include <hashfun.h>
#include "db_id.h"
BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b) {
assert(a && b);
return a == b ||
(a->saved_hash == b->saved_hash &&
!strcmp(a->absolute_path, b->absolute_path) &&
!strcmp(a->sub_database_name, b->sub_database_name));
}
void toku_db_id_add_ref(toku_db_id* db_id) {
assert(db_id);
assert(db_id->ref_count > 0);
db_id->ref_count++;
}
static void toku_db_id_close(toku_db_id* db_id) {
toku_free(db_id->absolute_path);
toku_free(db_id->sub_database_name);
toku_free(db_id);
}
void toku_db_id_remove_ref(toku_db_id* db_id) {
assert(db_id);
assert(db_id->ref_count > 0);
db_id->ref_count--;
if (db_id->ref_count > 0) { return; }
toku_db_id_close(db_id);
}
int toku_db_id_create(toku_db_id** pdbid, const char* path,
const char* sub_database_name) {
int r = ENOSYS;
assert(sub_database_name);
toku_db_id* db_id = NULL;
db_id = (toku_db_id *)toku_malloc(sizeof(*db_id));
if (!db_id) { r = ENOMEM; goto cleanup; }
memset(db_id, 0, sizeof(*db_id));
db_id->absolute_path = (char *)toku_malloc((PATH_MAX + 1) * sizeof(char));
if (!db_id->absolute_path) { r = ENOMEM; goto cleanup; }
/* TODO: BUG! Buffer overflow if the path > PATH_MAX. */
if (realpath(path, db_id->absolute_path) == NULL) {
r = errno;
goto cleanup;
}
char* tmp = (char*)toku_realloc(db_id->absolute_path,
(strlen(db_id->absolute_path) + 1) * sizeof(char));
if (!tmp) { r = ENOMEM; goto cleanup; }
db_id->absolute_path = tmp;
db_id->sub_database_name = toku_strdup(sub_database_name);
if (!db_id->sub_database_name) { r = ENOMEM; goto cleanup; }
db_id->saved_hash = hash_key((unsigned char*)db_id->absolute_path,
strlen(db_id->absolute_path));
db_id->saved_hash = hash_key_extend(db_id->saved_hash,
(unsigned char*)db_id->sub_database_name,
strlen(db_id->sub_database_name));
db_id->ref_count = 1;
*pdbid = db_id;
r = 0;
cleanup:
if (r != 0) {
if (db_id != NULL) {
if (db_id->absolute_path) { toku_free(db_id->absolute_path); }
if (db_id->sub_database_name) { toku_free(db_id->sub_database_name); }
toku_free(db_id);
}
}
return r;
}
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <limits.h>
#include <memory.h>
#include <hashfun.h>
#include "db_id.h"
BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b) {
assert(a && b);
return a == b ||
(a->saved_hash == b->saved_hash &&
!strcmp(a->absolute_path, b->absolute_path) &&
!strcmp(a->sub_database_name, b->sub_database_name));
}
void toku_db_id_add_ref(toku_db_id* db_id) {
assert(db_id);
assert(db_id->ref_count > 0);
db_id->ref_count++;
}
static void toku_db_id_close(toku_db_id* db_id) {
toku_free(db_id->absolute_path);
toku_free(db_id->sub_database_name);
toku_free(db_id);
}
void toku_db_id_remove_ref(toku_db_id* db_id) {
assert(db_id);
assert(db_id->ref_count > 0);
db_id->ref_count--;
if (db_id->ref_count > 0) { return; }
toku_db_id_close(db_id);
}
int toku_db_id_create(toku_db_id** pdbid, const char* path,
const char* sub_database_name) {
int r = ENOSYS;
assert(sub_database_name);
toku_db_id* db_id = NULL;
db_id = (toku_db_id *)toku_malloc(sizeof(*db_id));
if (!db_id) { r = ENOMEM; goto cleanup; }
memset(db_id, 0, sizeof(*db_id));
db_id->absolute_path = (char *)toku_malloc((PATH_MAX + 1) * sizeof(char));
if (!db_id->absolute_path) { r = ENOMEM; goto cleanup; }
/* TODO: BUG! Buffer overflow if the path > PATH_MAX. */
if (realpath(path, db_id->absolute_path) == NULL) {
r = errno;
goto cleanup;
}
char* tmp = (char*)toku_realloc(db_id->absolute_path,
(strlen(db_id->absolute_path) + 1) * sizeof(char));
if (!tmp) { r = ENOMEM; goto cleanup; }
db_id->absolute_path = tmp;
db_id->sub_database_name = toku_strdup(sub_database_name);
if (!db_id->sub_database_name) { r = ENOMEM; goto cleanup; }
db_id->saved_hash = hash_key((unsigned char*)db_id->absolute_path,
strlen(db_id->absolute_path));
db_id->saved_hash = hash_key_extend(db_id->saved_hash,
(unsigned char*)db_id->sub_database_name,
strlen(db_id->sub_database_name));
db_id->ref_count = 1;
*pdbid = db_id;
r = 0;
cleanup:
if (r != 0) {
if (db_id != NULL) {
if (db_id->absolute_path) { toku_free(db_id->absolute_path); }
if (db_id->sub_database_name) { toku_free(db_id->sub_database_name); }
toku_free(db_id);
}
}
return r;
}
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <brttypes.h>
#if !defined(TOKU_DB_ID_H)
#define TOKU_DB_ID_H
typedef struct __toku_db_id {
char* absolute_path;
char* sub_database_name;
u_int32_t saved_hash;
u_int32_t ref_count;
} toku_db_id;
/* db_id methods */
int toku_db_id_create(toku_db_id** pdbid, const char* path,
const char* sub_database_name);
BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b);
void toku_db_id_add_ref(toku_db_id* db_id);
void toku_db_id_remove_ref(toku_db_id* db_id);
#endif /* #if !defined(TOKU_DB_ID_H) */
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <brttypes.h>
#if !defined(TOKU_DB_ID_H)
#define TOKU_DB_ID_H
typedef struct __toku_db_id {
char* absolute_path;
char* sub_database_name;
u_int32_t saved_hash;
u_int32_t ref_count;
} toku_db_id;
/* db_id methods */
int toku_db_id_create(toku_db_id** pdbid, const char* path,
const char* sub_database_name);
BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b);
void toku_db_id_add_ref(toku_db_id* db_id);
void toku_db_id_remove_ref(toku_db_id* db_id);
#endif /* #if !defined(TOKU_DB_ID_H) */
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment