Modified:
trunk/c/include/toweldb.h
trunk/c/lib/CMakeLists.txt
trunk/c/lib/parser.c
trunk/c/lib/record.c
trunk/c/lib/record.h
Log:
-Encapsulate the record struct to preserve the ABI.
-Turn on warning reporting in the CMake build system.
Modified: trunk/c/include/toweldb.h
==============================================================================
--- trunk/c/include/toweldb.h (original)
+++ trunk/c/include/toweldb.h Tue Jul 22 07:53:10 2008
@@ -72,13 +72,7 @@
} toweldb_db;
/* Record */
-typedef struct toweldb_rec
-{
- time_t read_time;
- toweldb_db* parent;
- char* key;
- toweldb_field_node* contents_start;
-} toweldb_rec;
+typedef struct _toweldb_rec *toweldb_rec;
/* Database stuff */
toweldb_db* toweldb_open( const char* path, const char mode );
@@ -89,6 +83,10 @@
/* Close a database and free the memory storing it. */
/* Record functions */
+unsigned int toweldb_get_num_recs( toweldb_db* db );
+ /* Get the number of records in the database. */
+time_t toweldb_record_get_time( toweldb_rec rec );
+ /* Get the modification time of a record */
char* toweldb_get_next_key( toweldb_db* db );
/* Get the next key in the database. This is a wrapper around the POSIX
* readdir that skips entries that the programmer doesn't need. It will
@@ -99,9 +97,9 @@
/* Remove the record with name key from the database */
/* Record parsing functions */
-toweldb_rec* toweldb_read_rec( toweldb_db* db, const char* key );
+toweldb_rec toweldb_read_rec( toweldb_db* db, const char* key );
/* Read the record specified by key */
-void toweldb_free_rec( toweldb_rec* rec );
+void toweldb_free_rec( toweldb_rec rec );
/* Free the record memory */
#endif
Modified: trunk/c/lib/CMakeLists.txt
==============================================================================
--- trunk/c/lib/CMakeLists.txt (original)
+++ trunk/c/lib/CMakeLists.txt Tue Jul 22 07:53:10 2008
@@ -2,4 +2,5 @@
include_directories(${TOWELDB_SOURCE_DIR}/include)
add_library(toweldb SHARED ${Source} )
+set_target_properties(toweldb PROPERTIES COMPILE_FLAGS -Wall)
install(TARGETS toweldb DESTINATION lib)
Modified: trunk/c/lib/parser.c
==============================================================================
--- trunk/c/lib/parser.c (original)
+++ trunk/c/lib/parser.c Tue Jul 22 07:53:10 2008
@@ -26,12 +26,12 @@
#define TOWELDB_PHASE_START 1
#define TOWELDB_PHASE_FINISH 3
-toweldb_rec*
+toweldb_rec
toweldb_read_rec( toweldb_db* db, const char* key )
{
char* path = NULL;
FILE* rec_file = NULL;
- toweldb_rec* rec = NULL;
+ toweldb_rec rec = NULL;
struct stat rec_info;
char* rec_contents = NULL;
toweldb_field_node* cur_node = NULL;
@@ -43,7 +43,7 @@
char rec_component = TOWELDB_COMPONENT_NONE;
/* Allocate the record */
- rec = malloc( sizeof( toweldb_rec ));
+ rec = malloc( sizeof( struct _toweldb_rec ));
rec->parent = db;
rec->key = malloc( sizeof( char ) * ( strlen( key ) + 1 ));
strcpy( rec->key, key );
@@ -206,7 +206,7 @@
}
void
-toweldb_free_rec( toweldb_rec* rec )
+toweldb_free_rec( toweldb_rec rec )
{
toweldb_field_node* cur_node = NULL;
toweldb_field_node* next_node = NULL;
Modified: trunk/c/lib/record.c
==============================================================================
--- trunk/c/lib/record.c (original)
+++ trunk/c/lib/record.c Tue Jul 22 07:53:10 2008
@@ -156,3 +156,11 @@
return toweldb_err_noerror;
}
}
+
+time_t toweldb_record_get_time( toweldb_rec rec )
+{
+ struct stat rec_info;
+ stat( toweldb_get_path( rec->parent, rec->key ), &rec_info );
+
+ return rec_info.st_mtime;
+}
Modified: trunk/c/lib/record.h
==============================================================================
--- trunk/c/lib/record.h (original)
+++ trunk/c/lib/record.h Tue Jul 22 07:53:10 2008
@@ -20,11 +20,20 @@
#include "toweldb.h"
+struct _toweldb_rec
+{
+ toweldb_db* parent;
+ char* key;
+ toweldb_field_node* contents_start;
+};
+
/* Record functions */
char* toweldb_get_path( toweldb_db* db, const char* key );
/* Get the path to the record specified jointly by the database and the
* key */
-unsigned int toweldb_get_num_recs( toweldb_db* db );
- /* Get the number of records in the database. */
+
+/* Data structure accessor "methods" */
+toweldb_db* toweldb_record_get_parent( toweldb_rec rec );
+ /* Get the parent database that a record is a member of */
#endif