From: teodor Date: Mon, 30 Oct 2006 15:38:25 +0000 (+0000) Subject: Clean up: use separate function for fatal error X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=1e58e6abeab12d724c3d3a8a67394a38324767a3;p=ftsbench.git Clean up: use separate function for fatal error --- diff --git a/finnegan.c b/finnegan.c index efb0a5a..18630bc 100644 --- a/finnegan.c +++ b/finnegan.c @@ -60,10 +60,9 @@ no_newline(char *filename) FILE *fp; int c , cnt = 0; - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr,"Cannot open %s\n", filename); - exit(1); - } + if ((fp = fopen(filename, "r")) == NULL) + fatal("Cannot open %s\n", filename); + while ((c = getc(fp)) != EOF) if (c == '\n') cnt += 1; @@ -79,22 +78,18 @@ build_word_array(char *filename) FILE *fp; int i , temp_cfreq = 0; - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr,"Cannot open %s\n", filename); - exit(1); - } + if ((fp = fopen(filename, "r")) == NULL) + fatal("Cannot open %s\n", filename); + a = (struct word_info *)malloc(no_of_words * sizeof(struct word_info)); - if (!a) { - fprintf(stderr,"Can't allocate %d bytes\n", no_of_words * sizeof(struct word_info)); - exit(1); - } + if (!a) + fatal("Can't allocate %d bytes\n", no_of_words * sizeof(struct word_info)); + for (i = 0; i < no_of_words; i++) { fscanf(fp, "%s", buf); /* store word in temporary buffer */ a[i].word = strdup(buf); - if (!a[i].word) { - fprintf(stderr,"strdup failed\n"); - exit(1); - } + if (!a[i].word) + fatal("strdup failed\n"); fscanf(fp, "%d", &a[i].freq); a[i].word_len = strlen(a[i].word); a[i].cum_freq = temp_cfreq; @@ -112,11 +107,12 @@ build_doc_array(char *filename) FILE *fp; int i , temp_cfreq = 0; - if ((fp = fopen(filename, "r")) == NULL) { - fprintf(stderr,"Cannot open %s\n", filename); - exit(1); - } + if ((fp = fopen(filename, "r")) == NULL) + fatal("Cannot open %s\n", filename); + d = (struct doc_info *)malloc(no_of_docs * sizeof(struct doc_info)); + if ( !d ) + fatal("Can't allocate %d bytes\n", no_of_docs * sizeof(struct doc_info)); for (i = 0; i < no_of_docs; i++) { fscanf(fp, "%d", &d[i].doc_len); fscanf(fp, "%d", &d[i].doc_freq); @@ -230,10 +226,8 @@ generate_querywords() { void finnegan_init(char *lex_file, char *doc_file, int quiet) { - if ( isInited ) { - fprintf(stderr,"finnegan is already inited\n"); - exit(1); - } + if ( isInited ) + fatal("finnegan is already inited\n"); if (!quiet) { printf("Initialize text generator with:\n"); diff --git a/ftsbench.c b/ftsbench.c index 44788fd..3c8b7f6 100644 --- a/ftsbench.c +++ b/ftsbench.c @@ -88,7 +88,7 @@ usage() { " -l LEXFILE - file with words and its frequents (default gendata/lex)\n" " -g GAMMAFILE - file with doc's length distribution (default \n" " gendata/gamma-lens)\n" - " -l FLGAS - options for db's schema (see below)\n" + " -l FLAGS - options for db's schema (see below)\n" " -s ID - SQL mode: output is a SQL queries, ID is an identifier for insert\n" " statement\n" " -q - do not print progress message\n", @@ -108,7 +108,7 @@ usage() { " -l LEXFILE - file with words and its frequents (default gendata/query-lex)\n" " -g GAMMAFILE - file with doc's length distribution (default \n" " gendata/query-lens)\n" - " -l FLGAS - options for db's schema (see below)\n" + " -l FLAGS - options for db's schema (see below)\n" " -s ID - SQL mode: output is a SQL queries, ID is an identifier for insert\n" " statement\n" " -r - row mode: timing every query\n" @@ -141,16 +141,14 @@ getRDBMS(char *name) { if ( DBDesc[i].init ) return DBDesc[i].rdbms; } else if ( strcasecmp(name,DBDesc[i].shortname) == 0 ) { - if ( DBDesc[i].init == NULL ) { - fprintf(stderr,"Support of '%s' isn't compiled-in\n", DBDesc[i].longname); - exit(1); - } + if ( DBDesc[i].init == NULL ) + fatal("Support of '%s' isn't compiled-in\n", DBDesc[i].longname); + return DBDesc[i].rdbms; } } - fprintf(stderr,"Can't find a RDBMS\n"); - exit(1); + fatal("Can't find a RDBMS\n"); return NULLSQL; } @@ -170,14 +168,11 @@ getFLAGS(char *flg) { if ( strcasestr(flg,"or") ) flags |= FLG_OR; - if ( (flags & FLG_GIST) && (flags & FLG_GIN) ) { - fprintf(stderr,"GIN and GiST flags are mutually exclusive\n"); - exit(1); - } - if ( (flags & FLG_AND) && (flags & FLG_OR) ) { - fprintf(stderr,"AND and OR flags are mutually exclusive\n"); - exit(1); - } else if ( ( flags & ( FLG_AND | FLG_OR ) ) == 0 ) + if ( (flags & FLG_GIST) && (flags & FLG_GIN) ) + fatal("GIN and GiST flags are mutually exclusive\n"); + if ( (flags & FLG_AND) && (flags & FLG_OR) ) + fatal("AND and OR flags are mutually exclusive\n"); + else if ( ( flags & ( FLG_AND | FLG_OR ) ) == 0 ) flags |= FLG_AND; return flags; @@ -188,10 +183,8 @@ initConnections(RDBMS rdbms, int n, char *connstr) { ftsDB **dbs = (ftsDB**)malloc(sizeof(ftsDB*) * n); int i; - if (!dbs) { - fprintf(stderr,"Not enough mwmory\n"); - exit(1); - } + if (!dbs) + fatal("Not enough mwmory\n"); for(i=0;iprepareStmt == NULL ) { db->prepareStmt = mysql_stmt_init(db->conn); - if ( db->prepareStmt == NULL ) { - fprintf(stderr,"mysql_stmt_init failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( db->prepareStmt == NULL ) + fatal("mysql_stmt_init failed: %s\n", mysql_error(db->conn)); #define SEARCH_QUERY "SELECT count(*) FROM ftsbench WHERE MATCH(body) AGAINST ( ? IN BOOLEAN MODE);" - if ( mysql_stmt_prepare( db->prepareStmt, SEARCH_QUERY, strlen(SEARCH_QUERY) ) != 0 ) { - fprintf(stderr,"mysql_stmt_init failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_stmt_prepare( db->prepareStmt, SEARCH_QUERY, strlen(SEARCH_QUERY) ) != 0 ) + fatal("mysql_stmt_init failed: %s\n", mysql_error(db->conn)); - if ( mysql_stmt_param_count(db->prepareStmt) != 1 ) { - fprintf(stderr,"mysql_stmt_param_count: invalid parameter count\n"); - exit(1); - } + if ( mysql_stmt_param_count(db->prepareStmt) != 1 ) + fatal("mysql_stmt_param_count: invalid parameter count\n"); memset(&datain, 0, sizeof(MYSQL_BIND)); datain.buffer_type = MYSQL_TYPE_BLOB; @@ -103,37 +97,26 @@ execQuery(ftsDB *adb, char **words, int flags) { datain.buffer = db->b.str; datain.buffer_length = db->b.strlen; - if ( mysql_stmt_bind_param(db->prepareStmt, &datain) ) { - fprintf(stderr,"mysql_stmt_bind_param failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_stmt_bind_param(db->prepareStmt, &datain) ) + fatal("mysql_stmt_bind_param failed: %s\n", mysql_error(db->conn)); res = mysql_stmt_result_metadata(db->prepareStmt); - if ( !res ) { - fprintf(stderr,"mysql_stmt_result_metadata failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( !res ) + fatal("mysql_stmt_result_metadata failed: %s\n", mysql_error(db->conn)); - if ( mysql_stmt_execute( db->prepareStmt ) ) { - fprintf(stderr,"mysql_stmt_execute failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_stmt_execute( db->prepareStmt ) ) + fatal("mysql_stmt_execute failed: %s\n", mysql_error(db->conn)); - if (mysql_stmt_bind_result( db->prepareStmt, &dataout)) { - fprintf(stderr,"mysql_stmt_bind_result failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if (mysql_stmt_bind_result( db->prepareStmt, &dataout)) + fatal("mysql_stmt_bind_result failed: %s\n", mysql_error(db->conn)); - if ( mysql_stmt_store_result( db->prepareStmt ) ) { - fprintf(stderr,"mysql_stmt_store_result failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_stmt_store_result( db->prepareStmt ) ) + fatal("mysql_stmt_store_result failed: %s\n", mysql_error(db->conn)); if ( !mysql_stmt_fetch( db->prepareStmt) ) { db->db.nres += intout; } else { - fprintf(stderr,"mysql_stmt_fetch returns void result\n"); - exit(1); + fatal("mysql_stmt_fetch returns void result\n"); } mysql_free_result(res); @@ -154,15 +137,11 @@ startCreateScheme(ftsDB *adb, int flags) { if ( flags & (FLG_GIN | FLG_GIST) ) report("MySQL doesn't distinguish 'gin' and 'gist' flags\n"); - if ( mysql_query(db->conn, "DROP TABLE IF EXISTS ftsbench CASCADE;")!= 0 ) { - fprintf(stderr,"mysql_query failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_query(db->conn, "DROP TABLE IF EXISTS ftsbench CASCADE;")!= 0 ) + fatal("mysql_query failed: %s\n", mysql_error(db->conn)); - if ( mysql_query(db->conn, "CREATE TABLE ftsbench (id int not null, body text) ENGINE MyISAM;")!= 0 ) { - fprintf(stderr,"mysql_query failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_query(db->conn, "CREATE TABLE ftsbench (id int not null, body text) ENGINE MyISAM;")!= 0 ) + fatal("mysql_query failed: %s\n", mysql_error(db->conn)); } static void @@ -172,19 +151,15 @@ finishCreateScheme(ftsDB *adb) { if ( db->flags & (FLG_GIN | FLG_GIST) ) { report("(create index, "); - if ( mysql_query(db->conn, "CREATE FULLTEXT INDEX fts ON ftsbench (body);")!= 0 ) { - fprintf(stderr,"mysql_query failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_query(db->conn, "CREATE FULLTEXT INDEX fts ON ftsbench (body);")!= 0 ) + fatal("mysql_query failed: %s\n", mysql_error(db->conn)); } else report("("); report("optimize"); - if ( mysql_query(db->conn, "OPTIMIZE TABLE ftsbench;")!= 0 ) { - fprintf(stderr,"mysql_query failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_query(db->conn, "OPTIMIZE TABLE ftsbench;")!= 0 ) + fatal("mysql_query failed: %s\n", mysql_error(db->conn)); report(") "); } @@ -197,21 +172,15 @@ InsertRow(ftsDB *adb, int id, char *txt) { if ( db->prepareStmt == NULL ) { db->prepareStmt = mysql_stmt_init(db->conn); - if ( db->prepareStmt == NULL ) { - fprintf(stderr,"mysql_stmt_init failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( db->prepareStmt == NULL ) + fatal("mysql_stmt_init failed: %s\n", mysql_error(db->conn)); #define INSERT_QUERY "INSERT INTO ftsbench (id, body) VALUES ( ? , ? );" - if ( mysql_stmt_prepare( db->prepareStmt, INSERT_QUERY, strlen(INSERT_QUERY) ) != 0 ) { - fprintf(stderr,"mysql_stmt_init failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_stmt_prepare( db->prepareStmt, INSERT_QUERY, strlen(INSERT_QUERY) ) != 0 ) + fatal("mysql_stmt_init failed: %s\n", mysql_error(db->conn)); - if ( mysql_stmt_param_count(db->prepareStmt) != 2 ) { - fprintf(stderr,"mysql_stmt_param_count: invalid parameter count\n"); - exit(1); - } + if ( mysql_stmt_param_count(db->prepareStmt) != 2 ) + fatal("mysql_stmt_param_count: invalid parameter count\n"); memset(data, 0, sizeof(data)); data[0].buffer_type = MYSQL_TYPE_LONG; @@ -226,15 +195,11 @@ InsertRow(ftsDB *adb, int id, char *txt) { data[1].buffer = txt; data[1].buffer_length = txtlen; - if ( mysql_stmt_bind_param(db->prepareStmt, data) ) { - fprintf(stderr,"mysql_stmt_bind_param failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_stmt_bind_param(db->prepareStmt, data) ) + fatal("mysql_stmt_bind_param failed: %s\n", mysql_error(db->conn)); - if ( mysql_stmt_execute( db->prepareStmt ) ) { - fprintf(stderr,"mysql_stmt_execute failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( mysql_stmt_execute( db->prepareStmt ) ) + fatal("mysql_stmt_execute failed: %s\n", mysql_error(db->conn)); } static void @@ -252,10 +217,8 @@ MYInit(char * connstr) { db->conn = mysql_init(NULL); - if ( !mysql_real_connect(db->conn, NULL, NULL, NULL, connstr, 0, NULL, 0) ) { - fprintf(stderr,"mysql_real_connect failed: %s\n", mysql_error(db->conn)); - exit(1); - } + if ( !mysql_real_connect(db->conn, NULL, NULL, NULL, connstr, 0, NULL, 0) ) + fatal("mysql_real_connect failed: %s\n", mysql_error(db->conn)); db->db.execQuery = execQuery; db->db.startCreateScheme = startCreateScheme; diff --git a/pgdriver.c b/pgdriver.c index adf329f..0c4c59d 100644 --- a/pgdriver.c +++ b/pgdriver.c @@ -114,8 +114,7 @@ pgflush(ftsPG *db) { /* success write, waits for read */ db->state = SS_READ; } else { - fprintf(stderr, "PQflush failed: %s\n", PQerrorMessage(db->conn)); - exit(1); + fatal( "PQflush failed: %s\n", PQerrorMessage(db->conn)); } } @@ -136,8 +135,7 @@ checkStatus(ftsPG* db) { break; case SS_NONE: default: - fprintf(stderr,"Should not be here!\n"); - exit(1); + fatal( "Should not be here!\n"); break; } @@ -160,14 +158,11 @@ waitResult(ftsPG *db) { if ( pfd.events ) { int ret = poll( &pfd, 1, INFTIM); - if ( ret<0 ) { - fprintf(stderr,"poll failed: %s\n", strerror(errno)); - exit(1); - } + if ( ret<0 ) + fatal("poll failed: %s\n", strerror(errno)); - if ( pfd.revents & (POLLHUP | POLLNVAL | POLLERR) ) { - fprintf(stderr,"Poll report about socket error\n"); - exit(1); + if ( pfd.revents & (POLLHUP | POLLNVAL | POLLERR) ) { + fatal("Poll report about socket error\n"); } else if ( pfd.revents & POLLIN ) { db->state = SS_READYREAD; } else if ( pfd.revents & POLLOUT ) { @@ -177,10 +172,8 @@ waitResult(ftsPG *db) { } while( checkStatus(db) != RS_OK ); while ( (res = PQgetResult(db->conn))!= NULL ) { - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); } } @@ -216,10 +209,8 @@ execQuery(ftsDB* adb, char ** words, int flags) { res = PQprepare( db->conn, "search_ftsbench", buf, 1, NULL ); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "PREPARE SELECT command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "PREPARE SELECT command failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); db->prepared = 1; @@ -256,15 +247,12 @@ execQuery(ftsDB* adb, char ** words, int flags) { if (PQresultStatus(res) != PGRES_TUPLES_OK) { /* skip error ' all words are a stop word' for GIN index - result is empty, in any case */ - if ( checkEmptyQuery(db, res) == 0 ) { - fprintf(stderr, "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if ( checkEmptyQuery(db, res) == 0 ) + fatal( "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn)); } else if ( PQntuples(res) == 1 ) { db->db.nres += atoi( PQgetvalue(res,0,0) ); } else { - fprintf(stderr,"Bad PQntuples %d\n", PQntuples(res)); - exit(1); + fatal("Bad PQntuples %d\n", PQntuples(res)); } PQclear(res); @@ -284,10 +272,8 @@ startCreateScheme(ftsDB* adb, int flags) { db->flags = flags; res = PQexec(db->conn, "DROP TABLE IF EXISTS ftsbench CASCADE;"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "DROP TABLE command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "DROP TABLE command failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); if ( flags & FLG_FUNC ) @@ -298,17 +284,13 @@ startCreateScheme(ftsDB* adb, int flags) { "FOR EACH ROW EXECUTE PROCEDURE tsearch2(fts, body);" ); res = PQexec(db->conn, buf); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); res = PQexec(db->conn, "BEGIN;"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); return; @@ -322,17 +304,13 @@ finishCreateScheme(ftsDB* adb) { if ( db->db.nquery > 0 ) { waitResult(db); - if ( PQsetnonblocking(db->conn, 0) != 0 ) { - fprintf(stderr, "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if ( PQsetnonblocking(db->conn, 0) != 0 ) + fatal( "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn)); } res = PQexec(db->conn, "COMMIT;"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); if ( (db->flags & (FLG_GIST | FLG_GIN)) != 0 ) { @@ -348,10 +326,8 @@ finishCreateScheme(ftsDB* adb) { report("(create index, "); res = PQexec(db->conn, buf); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "CREATE INDEX command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "CREATE INDEX command failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); } else report("("); @@ -359,10 +335,8 @@ finishCreateScheme(ftsDB* adb) { report("vacuum"); res = PQexec(db->conn, "VACUUM ANALYZE ftsbench;"); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "VACUUM ANALYZE command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "VACUUM ANALYZE command failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); report(") "); @@ -387,16 +361,12 @@ InsertRow(ftsDB* adb, int id, char *txt) { "INSERT INTO ftsbench (id, body) VALUES ( $1 ::int4, $2 ::text);", 2, NULL ); - if (PQresultStatus(res) != PGRES_COMMAND_OK) { - fprintf(stderr, "PREPARE INSERT command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQresultStatus(res) != PGRES_COMMAND_OK) + fatal( "PREPARE INSERT command failed: %s\n", PQerrorMessage(db->conn)); PQclear(res); - if ( PQsetnonblocking(db->conn, 1) != 0 ) { - fprintf(stderr, "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if ( PQsetnonblocking(db->conn, 1) != 0 ) + fatal( "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn)); } else { waitResult(db); } @@ -407,10 +377,8 @@ InsertRow(ftsDB* adb, int id, char *txt) { if ( PQsendQueryPrepared( db->conn, "insert_ftsbench", 2, paramValues, - paramLengths, paramFormats, 0) == 0 ) { - fprintf(stderr, "PQsendQueryPrepared failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + paramLengths, paramFormats, 0) == 0 ) + fatal( "PQsendQueryPrepared failed: %s\n", PQerrorMessage(db->conn)); pgflush(db); @@ -434,10 +402,8 @@ PGInit(char * connstr) { sprintf(conninfo, "dbname=%s", connstr); db->conn = PQconnectdb(conninfo); - if (PQstatus(db->conn) != CONNECTION_OK) { - fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(db->conn)); - exit(1); - } + if (PQstatus(db->conn) != CONNECTION_OK) + fatal( "Connection to database failed: %s\n", PQerrorMessage(db->conn)); db->origreceiver = PQsetNoticeReceiver(db->conn, NoticeReceiver, (void *)db); @@ -447,10 +413,8 @@ PGInit(char * connstr) { db->db.InsertRow = InsertRow; db->db.Close = Close; db->socket = PQsocket(db->conn); - if ( db->socket < 0 ) { - fprintf(stderr,"Socket error\n"); - exit(1); - } + if ( db->socket < 0 ) + fatal("Socket error\n"); return (ftsDB*)db; } diff --git a/utils.c b/utils.c index 89a2b30..ccbc42d 100644 --- a/utils.c +++ b/utils.c @@ -50,10 +50,8 @@ sb_add(StringBuf *b, char *s, int length) b->str = (char*)realloc( b->str, sizeof(char) * b->length ); } - if (!b->str) { - fprintf(stderr,"Not enough memory (%d bytes)\n", b->length); - exit(1); - } + if (!b->str) + fatal("Not enough memory (%d bytes)\n", b->length); } memcpy(b->str + b->strlen, s, length);