Commit 8b6668da 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 71d55af2
/* -*- mode: C; c-basic-offset: 4 -*- */ /* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved." #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." #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 <errno.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <memory.h> #include <memory.h>
#include <hashfun.h> #include <hashfun.h>
#include "db_id.h" #include "db_id.h"
BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b) { BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b) {
assert(a && b); assert(a && b);
return a == b || return a == b ||
(a->saved_hash == b->saved_hash && (a->saved_hash == b->saved_hash &&
!strcmp(a->absolute_path, b->absolute_path) && !strcmp(a->absolute_path, b->absolute_path) &&
!strcmp(a->sub_database_name, b->sub_database_name)); !strcmp(a->sub_database_name, b->sub_database_name));
} }
void toku_db_id_add_ref(toku_db_id* db_id) { void toku_db_id_add_ref(toku_db_id* db_id) {
assert(db_id); assert(db_id);
assert(db_id->ref_count > 0); assert(db_id->ref_count > 0);
db_id->ref_count++; db_id->ref_count++;
} }
static void toku_db_id_close(toku_db_id* db_id) { static void toku_db_id_close(toku_db_id* db_id) {
toku_free(db_id->absolute_path); toku_free(db_id->absolute_path);
toku_free(db_id->sub_database_name); toku_free(db_id->sub_database_name);
toku_free(db_id); toku_free(db_id);
} }
void toku_db_id_remove_ref(toku_db_id* db_id) { void toku_db_id_remove_ref(toku_db_id* db_id) {
assert(db_id); assert(db_id);
assert(db_id->ref_count > 0); assert(db_id->ref_count > 0);
db_id->ref_count--; db_id->ref_count--;
if (db_id->ref_count > 0) { return; } if (db_id->ref_count > 0) { return; }
toku_db_id_close(db_id); toku_db_id_close(db_id);
} }
int toku_db_id_create(toku_db_id** pdbid, const char* path, int toku_db_id_create(toku_db_id** pdbid, const char* path,
const char* sub_database_name) { const char* sub_database_name) {
int r = ENOSYS; int r = ENOSYS;
assert(sub_database_name); assert(sub_database_name);
toku_db_id* db_id = NULL; toku_db_id* db_id = NULL;
db_id = (toku_db_id *)toku_malloc(sizeof(*db_id)); db_id = (toku_db_id *)toku_malloc(sizeof(*db_id));
if (!db_id) { r = ENOMEM; goto cleanup; } if (!db_id) { r = ENOMEM; goto cleanup; }
memset(db_id, 0, sizeof(*db_id)); memset(db_id, 0, sizeof(*db_id));
db_id->absolute_path = (char *)toku_malloc((PATH_MAX + 1) * sizeof(char)); db_id->absolute_path = (char *)toku_malloc((PATH_MAX + 1) * sizeof(char));
if (!db_id->absolute_path) { r = ENOMEM; goto cleanup; } if (!db_id->absolute_path) { r = ENOMEM; goto cleanup; }
/* TODO: BUG! Buffer overflow if the path > PATH_MAX. */ /* TODO: BUG! Buffer overflow if the path > PATH_MAX. */
if (realpath(path, db_id->absolute_path) == NULL) { if (realpath(path, db_id->absolute_path) == NULL) {
r = errno; r = errno;
goto cleanup; goto cleanup;
} }
char* tmp = (char*)toku_realloc(db_id->absolute_path, char* tmp = (char*)toku_realloc(db_id->absolute_path,
(strlen(db_id->absolute_path) + 1) * sizeof(char)); (strlen(db_id->absolute_path) + 1) * sizeof(char));
if (!tmp) { r = ENOMEM; goto cleanup; } if (!tmp) { r = ENOMEM; goto cleanup; }
db_id->absolute_path = tmp; db_id->absolute_path = tmp;
db_id->sub_database_name = toku_strdup(sub_database_name); db_id->sub_database_name = toku_strdup(sub_database_name);
if (!db_id->sub_database_name) { r = ENOMEM; goto cleanup; } if (!db_id->sub_database_name) { r = ENOMEM; goto cleanup; }
db_id->saved_hash = hash_key((unsigned char*)db_id->absolute_path, db_id->saved_hash = hash_key((unsigned char*)db_id->absolute_path,
strlen(db_id->absolute_path)); strlen(db_id->absolute_path));
db_id->saved_hash = hash_key_extend(db_id->saved_hash, db_id->saved_hash = hash_key_extend(db_id->saved_hash,
(unsigned char*)db_id->sub_database_name, (unsigned char*)db_id->sub_database_name,
strlen(db_id->sub_database_name)); strlen(db_id->sub_database_name));
db_id->ref_count = 1; db_id->ref_count = 1;
*pdbid = db_id; *pdbid = db_id;
r = 0; r = 0;
cleanup: cleanup:
if (r != 0) { if (r != 0) {
if (db_id != NULL) { if (db_id != NULL) {
if (db_id->absolute_path) { toku_free(db_id->absolute_path); } if (db_id->absolute_path) { toku_free(db_id->absolute_path); }
if (db_id->sub_database_name) { toku_free(db_id->sub_database_name); } if (db_id->sub_database_name) { toku_free(db_id->sub_database_name); }
toku_free(db_id); toku_free(db_id);
} }
} }
return r; return r;
} }
/* -*- mode: C; c-basic-offset: 4 -*- */ /* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved." #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." #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> #include <brttypes.h>
#if !defined(TOKU_DB_ID_H) #if !defined(TOKU_DB_ID_H)
#define TOKU_DB_ID_H #define TOKU_DB_ID_H
typedef struct __toku_db_id { typedef struct __toku_db_id {
char* absolute_path; char* absolute_path;
char* sub_database_name; char* sub_database_name;
u_int32_t saved_hash; u_int32_t saved_hash;
u_int32_t ref_count; u_int32_t ref_count;
} toku_db_id; } toku_db_id;
/* db_id methods */ /* db_id methods */
int toku_db_id_create(toku_db_id** pdbid, const char* path, int toku_db_id_create(toku_db_id** pdbid, const char* path,
const char* sub_database_name); const char* sub_database_name);
BOOL toku_db_id_equals(const toku_db_id* a, const toku_db_id* b); 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_add_ref(toku_db_id* db_id);
void toku_db_id_remove_ref(toku_db_id* db_id); void toku_db_id_remove_ref(toku_db_id* db_id);
#endif /* #if !defined(TOKU_DB_ID_H) */ #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