25 #include <grass/spawn.h>
26 #include <grass/dbmi.h>
46 dbDbmscap *list, *cur;
51 dbConnection connection;
63 G_debug(3,
"G_GISRC_MODE_MEMORY\n");
64 sprintf(ebuf,
"%d", G_GISRC_MODE_MEMORY);
65 G_putenv(
"GRASS_DB_DRIVER_GISRC_MODE", ebuf);
81 sprintf(ebuf,
"%d", G_GISRC_MODE_FILE);
82 G_putenv(
"GRASS_DB_DRIVER_GISRC_MODE", ebuf);
87 return (dbDriver *)
NULL;
92 if (
NULL == (name = connection.driverName))
93 return (dbDriver *)
NULL;
97 for (cur = list; cur; cur = cur->next)
98 if (strcmp(cur->driverName, name) == 0)
104 sprintf(msg,
"%s: no such driver available", name);
106 return (dbDriver *)
NULL;
110 driver = (dbDriver *)
db_malloc(
sizeof(dbDriver));
111 if (driver ==
NULL) {
113 return (dbDriver *)
NULL;
118 startup = driver->dbmscap.startup;
126 #define pipe(fds) _pipe(fds, 250000, _O_BINARY | _O_NOINHERIT)
130 if ((pipe(p1) < 0) || (pipe(p2) < 0)) {
132 return (dbDriver *)
NULL;
137 SF_REDIRECT_DESCRIPTOR, 0, p1[
READ],
138 SF_CLOSE_DESCRIPTOR, p1[
WRITE],
139 SF_REDIRECT_DESCRIPTOR, 1, p2[WRITE],
140 SF_CLOSE_DESCRIPTOR, p2[READ],
146 return (dbDriver *)
NULL;
156 driver->send = fdopen(p1[WRITE],
"wb");
157 driver->recv = fdopen(p2[READ],
"rb");
160 #ifndef USE_BUFFERED_IO
161 setbuf(driver->send,
NULL);
162 setbuf(driver->recv,
NULL);
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void db__set_protocol_fds(FILE *send, FILE *recv)
char * G__getenv(const char *name)
Get environment variable.
dbDbmscap * db_read_dbmscap(void)
int G_spawn_ex(const char *command,...)
Spawn new process based on command.
void G_putenv(const char *name, const char *value)
void db_error(const char *s)
int db_get_connection(dbConnection *connection)
get default db connection settings
void db_syserror(const char *s)
int G_get_gisrc_mode(void)
Get info where variables are stored.
void db_copy_dbmscap_entry(dbDbmscap *dst, dbDbmscap *src)
int db__recv_return_code(int *ret_code)
int G_debug(int level, const char *msg,...)
Print debugging message.
void db_free_dbmscap(dbDbmscap *list)
dbDriver * db_start_driver(const char *name)
Initialize a new dbDriver for db transaction.