socsvn commit: r272446 - soc2014/ghostmansd/head/lib/libc/locale
ghostmansd at FreeBSD.org
ghostmansd at FreeBSD.org
Thu Aug 14 22:32:45 UTC 2014
Author: ghostmansd
Date: Thu Aug 14 22:32:43 2014
New Revision: 272446
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272446
Log:
source code reorganization due to namespace collision
Modified:
soc2014/ghostmansd/head/lib/libc/locale/collate.c
soc2014/ghostmansd/head/lib/libc/locale/xlocale.c
Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c
==============================================================================
--- soc2014/ghostmansd/head/lib/libc/locale/collate.c Thu Aug 14 22:23:54 2014 (r272445)
+++ soc2014/ghostmansd/head/lib/libc/locale/collate.c Thu Aug 14 22:32:43 2014 (r272446)
@@ -42,11 +42,6 @@
#include <unistd.h>
#include <sysexits.h>
-#include <sys/types.h>
-#include <db.h>
-#include <fcntl.h>
-#include <limits.h>
-
#include "un-namespace.h"
#include "collate.h"
@@ -56,291 +51,6 @@
#include "libc_private.h"
-struct __colldb {
- uint32_t version;
- void *handle;
-};
-
-
-void *
-__colldb_create(const char *path, int mode)
-{
- DBT key;
- DBT value;
- DB *db = NULL;
- int error = 0;
- void *colldb = NULL;
- uint32_t version = 0;
- int flags = (O_RDWR | O_CREAT | O_TRUNC);
-
- colldb = calloc(1, sizeof(struct __colldb));
- if (colldb == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- db = dbopen(path, flags, mode, DB_HASH, NULL);
- if (db == NULL) {
- error = errno;
- free(colldb);
- errno = error;
- return (NULL);
- }
- ((struct __colldb*)colldb)->version = __COLLDB_VERSION;
-
- key.data = "TYPE";
- value.data = "COLLATION";
- key.size = (strlen("TYPE") + 1);
- value.size = (strlen("COLLATION") + 1);
- if (db->put(db, &key, &value, 0) == -1) {
- error = errno;
- goto failure;
- }
-
- key.data = "VERSION";
- version = htonl(((struct __colldb*)colldb)->version);
- value.data = &version;
- key.size = (strlen("VERSION") + 1);
- value.size = sizeof(((struct __colldb*)colldb)->version);
- if (db->put(db, &key, &value, 0) == -1) {
- error = errno;
- goto failure;
- }
-
- ((struct __colldb*)colldb)->handle = db;
- return (colldb);
-
-failure:
- (void) db->close(db);
- free(colldb);
- errno = error;
- return (NULL);
-}
-
-
-void *
-__colldb_open(const char *path)
-{
- DBT key;
- DBT value;
- DB *db = NULL;
- int error = 0;
- int state = 0;
- void *colldb = NULL;
- int flags = O_RDONLY;
-
- colldb = calloc(1, sizeof(struct __colldb));
- if (colldb == NULL) {
- errno = ENOMEM;
- return (NULL);
- }
- db = dbopen(path, flags, 0, DB_HASH, NULL);
- if (db == NULL) {
- error = errno;
- free(colldb);
- errno = error;
- return (NULL);
- }
-
- key.data = "TYPE";
- key.size = (strlen("TYPE") + 1);
- state = db->get(db, &key, &value, 0);
- if (state != 0) {
- if (state < 0)
- error = errno;
- else
- error = EFTYPE;
- goto failure;
- }
- if (strcmp(value.data, "COLLATION") != 0) {
- error = EFTYPE;
- goto failure;
- }
-
- key.data = "VERSION";
- key.size = (strlen("VERSION") + 1);
- state = db->get(db, &key, &value, 0);
- if (state != 0) {
- if (state < 0)
- error = errno;
- else
- error = EFTYPE;
- goto failure;
- }
- ((struct __colldb*)colldb)->version =
- ntohl(*(const uint32_t*)value.data);
-
- ((struct __colldb*)colldb)->handle = db;
- return (colldb);
-
-failure:
- (void) db->close(db);
- free(colldb);
- errno = error;
- return (NULL);
-}
-
-
-int
-__colldb_close(void *colldb)
-{
- DB *db = NULL;
- int error = 0;
-
- if (colldb == NULL) {
- errno = EINVAL;
- return (-1);
- }
- db = ((struct __colldb*)colldb)->handle;
- if (db == NULL) {
- errno = EINVAL;
- return (-1);
- }
- if (db->close(db) == -1) {
- error = errno;
- free(colldb);
- errno = error;
- return (-1);
- }
- free(colldb);
- return (0);
-}
-
-
-int
-__colldb_sync(void *colldb)
-{
- DB *db = NULL;
-
- if (colldb == NULL) {
- errno = EINVAL;
- return (-1);
- }
- db = ((struct __colldb*)colldb)->handle;
- if (db == NULL) {
- errno = EINVAL;
- return (-1);
- }
- return db->sync(db, 0);
-}
-
-
-int
-__colldb_get(void *colldb,
- struct __colldb_key *key,
- struct __colldb_value *value)
-{
- DBT dbkey;
- DBT dbvalue;
- DB *db = NULL;
- size_t i = 0;
- int error = 0;
- int state = 0;
- uint32_t *keybuf = NULL;
- struct __colldb_weight *weights = NULL;
-
- if ((colldb == NULL) || (key == NULL) || (value == NULL)) {
- errno = EINVAL;
- return (-1);
- }
- db = ((struct __colldb*)colldb)->handle;
- if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) {
- errno = EINVAL;
- return (-1);
- }
-
- keybuf = malloc(key->count * sizeof(*key->chars));
- if (keybuf == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- for (i = 0; i < key->count; ++i)
- keybuf[i] = htonl(key->chars[i]);
-
- dbkey.data = keybuf;
- dbkey.size = (key->count * sizeof(*key->chars));
- state = db->get(db, &dbkey, &dbvalue, 0);
- if (state != 0) {
- error = errno;
- free(keybuf);
- errno = error;
- return (state);
- }
-
- weights = dbvalue.data;
- if ((dbvalue.size / sizeof(*weights)) > value->count) {
- free(keybuf);
- errno = ERANGE;
- return (-1);
- }
- value->count = (dbvalue.size / sizeof(*weights));
- for (i = 0; i < value->count; ++i) {
- value->weights[i].alternate = weights[i].alternate;
- value->weights[i].level1 = ntohl(weights[i].level1);
- value->weights[i].level2 = ntohl(weights[i].level2);
- value->weights[i].level3 = ntohl(weights[i].level3);
- value->weights[i].level4 = ntohl(weights[i].level4);
- }
- free(keybuf);
- return (0);
-}
-
-
-int
-__colldb_put(void *colldb,
- struct __colldb_key *key,
- struct __colldb_value *value)
-{
- DBT dbkey;
- DBT dbvalue;
- DB *db = NULL;
- size_t i = 0;
- int state = 0;
- int error = 0;
- uint32_t *keybuf = NULL;
- struct __colldb_weight *valuebuf = NULL;
-
- if ((colldb == NULL) || (key == NULL) || (value == NULL)) {
- errno = EINVAL;
- return (-1);
- }
- db = ((struct __colldb*)colldb)->handle;
- if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) {
- errno = EINVAL;
- return (-1);
- }
-
- valuebuf = value->weights;
- keybuf = malloc(key->count * sizeof(*key->chars));
- valuebuf = malloc(value->count * sizeof(*value->weights));
- if ((keybuf == NULL) || (valuebuf == NULL)) {
- errno = ENOMEM;
- return (-1);
- }
- for (i = 0; i < key->count; ++i)
- keybuf[i] = htonl(key->chars[i]);
- for (i = 0; i < value->count; ++i) {
- valuebuf[i].alternate = value->weights[i].alternate;
- valuebuf[i].level1 = htonl(value->weights[i].level1);
- valuebuf[i].level2 = htonl(value->weights[i].level2);
- valuebuf[i].level3 = htonl(value->weights[i].level3);
- valuebuf[i].level4 = htonl(value->weights[i].level4);
- }
-
- dbkey.data = keybuf;
- dbvalue.data = valuebuf;
- dbkey.size = (key->count * sizeof(*key->chars));
- dbvalue.size = (value->count * sizeof(*value->weights));
- state = db->put(db, &dbkey, &dbvalue, 0);
- if (state != 0) {
- error = errno;
- free(keybuf);
- free(valuebuf);
- errno = error;
- }
- return state;
-}
-
-
/*
* To avoid modifying the original (single-threaded) code too much, we'll just
* define the old globals as fields inside the table.
Modified: soc2014/ghostmansd/head/lib/libc/locale/xlocale.c
==============================================================================
--- soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Thu Aug 14 22:23:54 2014 (r272445)
+++ soc2014/ghostmansd/head/lib/libc/locale/xlocale.c Thu Aug 14 22:32:43 2014 (r272446)
@@ -33,11 +33,15 @@
#include <stdio.h>
#include <string.h>
#include <runetype.h>
+#include <sys/types.h>
+#include <db.h>
+#include <fcntl.h>
+#include <limits.h>
#include "libc_private.h"
#include "xlocale_private.h"
-/* Collation Database implementation. */
+/* Collation Database. */
static void *colldb_root_handle = NULL;
static pthread_once_t colldb_root_once = PTHREAD_ONCE_INIT;
@@ -53,6 +57,284 @@
return (colldb_root_handle);
}
+struct __colldb {
+ uint32_t version;
+ void *handle;
+};
+
+void *
+__colldb_create(const char *path, int mode)
+{
+ DBT key;
+ DBT value;
+ DB *db = NULL;
+ int error = 0;
+ void *colldb = NULL;
+ uint32_t version = 0;
+ int flags = (O_RDWR | O_CREAT | O_TRUNC);
+
+ colldb = calloc(1, sizeof(struct __colldb));
+ if (colldb == NULL) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ db = dbopen(path, flags, mode, DB_HASH, NULL);
+ if (db == NULL) {
+ error = errno;
+ free(colldb);
+ errno = error;
+ return (NULL);
+ }
+ ((struct __colldb*)colldb)->version = __COLLDB_VERSION;
+
+ key.data = "TYPE";
+ value.data = "COLLATION";
+ key.size = (strlen("TYPE") + 1);
+ value.size = (strlen("COLLATION") + 1);
+ if (db->put(db, &key, &value, 0) == -1) {
+ error = errno;
+ goto failure;
+ }
+
+ key.data = "VERSION";
+ version = htonl(((struct __colldb*)colldb)->version);
+ value.data = &version;
+ key.size = (strlen("VERSION") + 1);
+ value.size = sizeof(((struct __colldb*)colldb)->version);
+ if (db->put(db, &key, &value, 0) == -1) {
+ error = errno;
+ goto failure;
+ }
+
+ ((struct __colldb*)colldb)->handle = db;
+ return (colldb);
+
+failure:
+ (void) db->close(db);
+ free(colldb);
+ errno = error;
+ return (NULL);
+}
+
+void *
+__colldb_open(const char *path)
+{
+ DBT key;
+ DBT value;
+ DB *db = NULL;
+ int error = 0;
+ int state = 0;
+ void *colldb = NULL;
+ int flags = O_RDONLY;
+
+ colldb = calloc(1, sizeof(struct __colldb));
+ if (colldb == NULL) {
+ errno = ENOMEM;
+ return (NULL);
+ }
+ db = dbopen(path, flags, 0, DB_HASH, NULL);
+ if (db == NULL) {
+ error = errno;
+ free(colldb);
+ errno = error;
+ return (NULL);
+ }
+
+ key.data = "TYPE";
+ key.size = (strlen("TYPE") + 1);
+ state = db->get(db, &key, &value, 0);
+ if (state != 0) {
+ if (state < 0)
+ error = errno;
+ else
+ error = EFTYPE;
+ goto failure;
+ }
+ if (strcmp(value.data, "COLLATION") != 0) {
+ error = EFTYPE;
+ goto failure;
+ }
+
+ key.data = "VERSION";
+ key.size = (strlen("VERSION") + 1);
+ state = db->get(db, &key, &value, 0);
+ if (state != 0) {
+ if (state < 0)
+ error = errno;
+ else
+ error = EFTYPE;
+ goto failure;
+ }
+ ((struct __colldb*)colldb)->version =
+ ntohl(*(const uint32_t*)value.data);
+
+ ((struct __colldb*)colldb)->handle = db;
+ return (colldb);
+
+failure:
+ (void) db->close(db);
+ free(colldb);
+ errno = error;
+ return (NULL);
+}
+
+int
+__colldb_close(void *colldb)
+{
+ DB *db = NULL;
+ int error = 0;
+
+ if (colldb == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ db = ((struct __colldb*)colldb)->handle;
+ if (db == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ if (db->close(db) == -1) {
+ error = errno;
+ free(colldb);
+ errno = error;
+ return (-1);
+ }
+ free(colldb);
+ return (0);
+}
+
+int
+__colldb_sync(void *colldb)
+{
+ DB *db = NULL;
+
+ if (colldb == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ db = ((struct __colldb*)colldb)->handle;
+ if (db == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ return db->sync(db, 0);
+}
+
+int
+__colldb_get(void *colldb,
+ struct __colldb_key *key,
+ struct __colldb_value *value)
+{
+ DBT dbkey;
+ DBT dbvalue;
+ DB *db = NULL;
+ size_t i = 0;
+ int error = 0;
+ int state = 0;
+ uint32_t *keybuf = NULL;
+ struct __colldb_weight *weights = NULL;
+
+ if ((colldb == NULL) || (key == NULL) || (value == NULL)) {
+ errno = EINVAL;
+ return (-1);
+ }
+ db = ((struct __colldb*)colldb)->handle;
+ if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ keybuf = malloc(key->count * sizeof(*key->chars));
+ if (keybuf == NULL) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ for (i = 0; i < key->count; ++i)
+ keybuf[i] = htonl(key->chars[i]);
+
+ dbkey.data = keybuf;
+ dbkey.size = (key->count * sizeof(*key->chars));
+ state = db->get(db, &dbkey, &dbvalue, 0);
+ if (state != 0) {
+ error = errno;
+ free(keybuf);
+ errno = error;
+ return (state);
+ }
+
+ weights = dbvalue.data;
+ if ((dbvalue.size / sizeof(*weights)) > value->count) {
+ free(keybuf);
+ errno = ERANGE;
+ return (-1);
+ }
+ value->count = (dbvalue.size / sizeof(*weights));
+ for (i = 0; i < value->count; ++i) {
+ value->weights[i].alternate = weights[i].alternate;
+ value->weights[i].level1 = ntohl(weights[i].level1);
+ value->weights[i].level2 = ntohl(weights[i].level2);
+ value->weights[i].level3 = ntohl(weights[i].level3);
+ value->weights[i].level4 = ntohl(weights[i].level4);
+ }
+ free(keybuf);
+ return (0);
+}
+
+int
+__colldb_put(void *colldb,
+ struct __colldb_key *key,
+ struct __colldb_value *value)
+{
+ DBT dbkey;
+ DBT dbvalue;
+ DB *db = NULL;
+ size_t i = 0;
+ int state = 0;
+ int error = 0;
+ uint32_t *keybuf = NULL;
+ struct __colldb_weight *valuebuf = NULL;
+
+ if ((colldb == NULL) || (key == NULL) || (value == NULL)) {
+ errno = EINVAL;
+ return (-1);
+ }
+ db = ((struct __colldb*)colldb)->handle;
+ if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ valuebuf = value->weights;
+ keybuf = malloc(key->count * sizeof(*key->chars));
+ valuebuf = malloc(value->count * sizeof(*value->weights));
+ if ((keybuf == NULL) || (valuebuf == NULL)) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ for (i = 0; i < key->count; ++i)
+ keybuf[i] = htonl(key->chars[i]);
+ for (i = 0; i < value->count; ++i) {
+ valuebuf[i].alternate = value->weights[i].alternate;
+ valuebuf[i].level1 = htonl(value->weights[i].level1);
+ valuebuf[i].level2 = htonl(value->weights[i].level2);
+ valuebuf[i].level3 = htonl(value->weights[i].level3);
+ valuebuf[i].level4 = htonl(value->weights[i].level4);
+ }
+
+ dbkey.data = keybuf;
+ dbvalue.data = valuebuf;
+ dbkey.size = (key->count * sizeof(*key->chars));
+ dbvalue.size = (value->count * sizeof(*value->weights));
+ state = db->put(db, &dbkey, &dbvalue, 0);
+ if (state != 0) {
+ error = errno;
+ free(keybuf);
+ free(valuebuf);
+ errno = error;
+ }
+ return state;
+}
+
/**
* Each locale loader declares a global component. This is used by setlocale()
More information about the svn-soc-all
mailing list