diff --git a/src/bin/pg4_dump/common.c b/src/bin/pg4_dump/common.c index da66dc6929196d28e4a52e8366053c6cd557a980..0bf6cca533fc110d5a5ffa50e0210c0769cbb2d6 100644 --- a/src/bin/pg4_dump/common.c +++ b/src/bin/pg4_dump/common.c @@ -43,23 +43,6 @@ check_conn_and_db() } -/* dupstr : copies a string, while allocating space for it. - the CALLER is responsible for freeing the space - returns NULL if the argument is NULL*/ -char* -dupstr(char *s) -{ - char* result; - - if (s == NULL) - return NULL; - - result = (char*)malloc(strlen(s)+1); - strcpy(result, s); - return result; -} - - /* * findTypeByOid * given an oid of a type, return its typename @@ -173,7 +156,7 @@ parseArgTypes(char **argtypes, char* str) while ( (s = *str) != '\0') { if (s == ' ') { temp[j] = '\0'; - argtypes[argNum] = dupstr(temp); + argtypes[argNum] = strdup(temp); argNum++; j = 0; } else { @@ -184,7 +167,7 @@ parseArgTypes(char **argtypes, char* str) } if (j != 0) { temp[j] = '\0'; - argtypes[argNum] = dupstr(temp); + argtypes[argNum] = strdup(temp); } } diff --git a/src/bin/pg4_dump/pg4_dump.c b/src/bin/pg4_dump/pg4_dump.c index a7f54004dc136032ba0e238fd89ce48a0d31de0a..9944ca1190ebb88b47138642009b1cf520b11f63 100644 --- a/src/bin/pg4_dump/pg4_dump.c +++ b/src/bin/pg4_dump/pg4_dump.c @@ -289,19 +289,19 @@ getTypes(int *numTypes) i_typbyval = PQfnumberGroup(pbuf,0,"typbyval"); for (i=0;i<ntups;i++) { - tinfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); - tinfo[i].typowner = dupstr(PQgetvalue(pbuf,i,i_typowner)); - tinfo[i].typname = dupstr(PQgetvalue(pbuf,i,i_typname)); - tinfo[i].typlen = dupstr(PQgetvalue(pbuf,i,i_typlen)); - tinfo[i].typprtlen = dupstr(PQgetvalue(pbuf,i,i_typprtlen)); - tinfo[i].typinput = dupstr(PQgetvalue(pbuf,i,i_typinput)); - tinfo[i].typoutput = dupstr(PQgetvalue(pbuf,i,i_typoutput)); - tinfo[i].typreceive = dupstr(PQgetvalue(pbuf,i,i_typreceive)); - tinfo[i].typsend = dupstr(PQgetvalue(pbuf,i,i_typsend)); - tinfo[i].typelem = dupstr(PQgetvalue(pbuf,i,i_typelem)); - tinfo[i].typdelim = dupstr(PQgetvalue(pbuf,i,i_typdelim)); - tinfo[i].typdefault = dupstr(PQgetvalue(pbuf,i,i_typdefault)); - tinfo[i].typrelid = dupstr(PQgetvalue(pbuf,i,i_typrelid)); + tinfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid)); + tinfo[i].typowner = strdup(PQgetvalue(pbuf,i,i_typowner)); + tinfo[i].typname = strdup(PQgetvalue(pbuf,i,i_typname)); + tinfo[i].typlen = strdup(PQgetvalue(pbuf,i,i_typlen)); + tinfo[i].typprtlen = strdup(PQgetvalue(pbuf,i,i_typprtlen)); + tinfo[i].typinput = strdup(PQgetvalue(pbuf,i,i_typinput)); + tinfo[i].typoutput = strdup(PQgetvalue(pbuf,i,i_typoutput)); + tinfo[i].typreceive = strdup(PQgetvalue(pbuf,i,i_typreceive)); + tinfo[i].typsend = strdup(PQgetvalue(pbuf,i,i_typsend)); + tinfo[i].typelem = strdup(PQgetvalue(pbuf,i,i_typelem)); + tinfo[i].typdelim = strdup(PQgetvalue(pbuf,i,i_typdelim)); + tinfo[i].typdefault = strdup(PQgetvalue(pbuf,i,i_typdefault)); + tinfo[i].typrelid = strdup(PQgetvalue(pbuf,i,i_typrelid)); if (strcmp(PQgetvalue(pbuf,i,i_typbyval), "f") == 0) tinfo[i].passedbyvalue = 0; @@ -390,19 +390,19 @@ getOperators(int *numOprs) i_oprrsortop = PQfnumberGroup(pbuf,0,"oprrsortop"); for (i=0;i<ntups;i++) { - oprinfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); - oprinfo[i].oprname = dupstr(PQgetvalue(pbuf,i,i_oprname)); - oprinfo[i].oprkind = dupstr(PQgetvalue(pbuf,i,i_oprkind)); - oprinfo[i].oprcode = dupstr(PQgetvalue(pbuf,i,i_oprcode)); - oprinfo[i].oprleft = dupstr(PQgetvalue(pbuf,i,i_oprleft)); - oprinfo[i].oprright = dupstr(PQgetvalue(pbuf,i,i_oprright)); - oprinfo[i].oprcom = dupstr(PQgetvalue(pbuf,i,i_oprcom)); - oprinfo[i].oprnegate = dupstr(PQgetvalue(pbuf,i,i_oprnegate)); - oprinfo[i].oprrest = dupstr(PQgetvalue(pbuf,i,i_oprrest)); - oprinfo[i].oprjoin = dupstr(PQgetvalue(pbuf,i,i_oprjoin)); - oprinfo[i].oprcanhash = dupstr(PQgetvalue(pbuf,i,i_oprcanhash)); - oprinfo[i].oprlsortop = dupstr(PQgetvalue(pbuf,i,i_oprlsortop)); - oprinfo[i].oprrsortop = dupstr(PQgetvalue(pbuf,i,i_oprrsortop)); + oprinfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid)); + oprinfo[i].oprname = strdup(PQgetvalue(pbuf,i,i_oprname)); + oprinfo[i].oprkind = strdup(PQgetvalue(pbuf,i,i_oprkind)); + oprinfo[i].oprcode = strdup(PQgetvalue(pbuf,i,i_oprcode)); + oprinfo[i].oprleft = strdup(PQgetvalue(pbuf,i,i_oprleft)); + oprinfo[i].oprright = strdup(PQgetvalue(pbuf,i,i_oprright)); + oprinfo[i].oprcom = strdup(PQgetvalue(pbuf,i,i_oprcom)); + oprinfo[i].oprnegate = strdup(PQgetvalue(pbuf,i,i_oprnegate)); + oprinfo[i].oprrest = strdup(PQgetvalue(pbuf,i,i_oprrest)); + oprinfo[i].oprjoin = strdup(PQgetvalue(pbuf,i,i_oprjoin)); + oprinfo[i].oprcanhash = strdup(PQgetvalue(pbuf,i,i_oprcanhash)); + oprinfo[i].oprlsortop = strdup(PQgetvalue(pbuf,i,i_oprlsortop)); + oprinfo[i].oprrsortop = strdup(PQgetvalue(pbuf,i,i_oprrsortop)); } PQclear(res+1); @@ -471,16 +471,16 @@ getAggregates(int *numAggs) i_agginitval2 = PQfnumberGroup(pbuf,0,"agginitval2"); for (i=0;i<ntups;i++) { - agginfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); - agginfo[i].aggname = dupstr(PQgetvalue(pbuf,i,i_aggname)); - agginfo[i].aggtransfn1 = dupstr(PQgetvalue(pbuf,i,i_aggtransfn1)); - agginfo[i].aggtransfn2 = dupstr(PQgetvalue(pbuf,i,i_aggtransfn2)); - agginfo[i].aggfinalfn = dupstr(PQgetvalue(pbuf,i,i_aggfinalfn)); - agginfo[i].aggtranstype1 = dupstr(PQgetvalue(pbuf,i,i_aggtranstype1)); - agginfo[i].aggbasetype = dupstr(PQgetvalue(pbuf,i,i_aggbasetype)); - agginfo[i].aggtranstype2 = dupstr(PQgetvalue(pbuf,i,i_aggtranstype2)); - agginfo[i].agginitval1 = dupstr(PQgetvalue(pbuf,i,i_agginitval1)); - agginfo[i].agginitval2 = dupstr(PQgetvalue(pbuf,i,i_agginitval2)); + agginfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid)); + agginfo[i].aggname = strdup(PQgetvalue(pbuf,i,i_aggname)); + agginfo[i].aggtransfn1 = strdup(PQgetvalue(pbuf,i,i_aggtransfn1)); + agginfo[i].aggtransfn2 = strdup(PQgetvalue(pbuf,i,i_aggtransfn2)); + agginfo[i].aggfinalfn = strdup(PQgetvalue(pbuf,i,i_aggfinalfn)); + agginfo[i].aggtranstype1 = strdup(PQgetvalue(pbuf,i,i_aggtranstype1)); + agginfo[i].aggbasetype = strdup(PQgetvalue(pbuf,i,i_aggbasetype)); + agginfo[i].aggtranstype2 = strdup(PQgetvalue(pbuf,i,i_aggtranstype2)); + agginfo[i].agginitval1 = strdup(PQgetvalue(pbuf,i,i_agginitval1)); + agginfo[i].agginitval2 = strdup(PQgetvalue(pbuf,i,i_agginitval2)); } PQclear(res+1); @@ -553,14 +553,14 @@ getFuncs(int *numFuncs) i_probin = PQfnumberGroup(pbuf,0,"probin"); for (i=0;i<ntups;i++) { - finfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); - finfo[i].proname = dupstr(PQgetvalue(pbuf,i,i_proname)); - finfo[i].proowner = dupstr(PQgetvalue(pbuf,i,i_proowner)); + finfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid)); + finfo[i].proname = strdup(PQgetvalue(pbuf,i,i_proname)); + finfo[i].proowner = strdup(PQgetvalue(pbuf,i,i_proowner)); finfo[i].prosrc = checkForQuote(PQgetvalue(pbuf,i,i_prosrc)); - finfo[i].probin = dupstr(PQgetvalue(pbuf,i,i_probin)); + finfo[i].probin = strdup(PQgetvalue(pbuf,i,i_probin)); - finfo[i].prorettype = dupstr(PQgetvalue(pbuf,i,i_prorettype)); + finfo[i].prorettype = strdup(PQgetvalue(pbuf,i,i_prorettype)); finfo[i].retset = (strcmp(PQgetvalue(pbuf,i,i_proretset),"t") == 0); finfo[i].nargs = atoi(PQgetvalue(pbuf,i,i_pronargs)); finfo[i].lang = (atoi(PQgetvalue(pbuf,i,i_prolang)) == C_PROLANG_OID); @@ -624,9 +624,9 @@ getTables(int *numTables) i_relarch = PQfnumberGroup(pbuf,0,"relarch"); for (i=0;i<ntups;i++) { - tblinfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); - tblinfo[i].relname = dupstr(PQgetvalue(pbuf,i,i_relname)); - tblinfo[i].relarch = dupstr(PQgetvalue(pbuf,i,i_relarch)); + tblinfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid)); + tblinfo[i].relname = strdup(PQgetvalue(pbuf,i,i_relname)); + tblinfo[i].relarch = strdup(PQgetvalue(pbuf,i,i_relarch)); } PQclear(res+1); @@ -677,8 +677,8 @@ getInherits(int *numInherits) i_inhparent = PQfnumberGroup(pbuf,0,"inhparent"); for (i=0;i<ntups;i++) { - inhinfo[i].inhrel = dupstr(PQgetvalue(pbuf,i,i_inhrel)); - inhinfo[i].inhparent = dupstr(PQgetvalue(pbuf,i,i_inhparent)); + inhinfo[i].inhrel = strdup(PQgetvalue(pbuf,i,i_inhrel)); + inhinfo[i].inhparent = strdup(PQgetvalue(pbuf,i,i_inhparent)); } PQclear(res+1); @@ -740,8 +740,8 @@ if (g_verbose) tblinfo[i].parentRels = NULL; tblinfo[i].numParents = 0; for (j=0;j<ntups;j++) { - tblinfo[i].attnames[j] = dupstr(PQgetvalue(pbuf,j,i_attname)); - tblinfo[i].typnames[j] = dupstr(PQgetvalue(pbuf,j,i_typname)); + tblinfo[i].attnames[j] = strdup(PQgetvalue(pbuf,j,i_attname)); + tblinfo[i].typnames[j] = strdup(PQgetvalue(pbuf,j,i_typname)); tblinfo[i].inhAttrs[j] = 0; /* this flag is set in flagInhAttrs()*/ } PQclear(res+1); @@ -809,12 +809,12 @@ getIndices(int *numIndices) i_indclassname = PQfnumberGroup(pbuf,0,"indclassname"); for (i=0;i<ntups;i++) { - indinfo[i].indexrelname = dupstr(PQgetvalue(pbuf,i,i_indexrelname)); - indinfo[i].indrelname = dupstr(PQgetvalue(pbuf,i,i_indrelname)); - indinfo[i].indamname = dupstr(PQgetvalue(pbuf,i,i_indamname)); - indinfo[i].indproc = dupstr(PQgetvalue(pbuf,i,i_indproc)); - indinfo[i].indkey = dupstr(PQgetvalue(pbuf,i,i_indkey)); - indinfo[i].indclassname = dupstr(PQgetvalue(pbuf,i,i_indclassname)); + indinfo[i].indexrelname = strdup(PQgetvalue(pbuf,i,i_indexrelname)); + indinfo[i].indrelname = strdup(PQgetvalue(pbuf,i,i_indrelname)); + indinfo[i].indamname = strdup(PQgetvalue(pbuf,i,i_indamname)); + indinfo[i].indproc = strdup(PQgetvalue(pbuf,i,i_indproc)); + indinfo[i].indkey = strdup(PQgetvalue(pbuf,i,i_indkey)); + indinfo[i].indclassname = strdup(PQgetvalue(pbuf,i,i_indclassname)); } PQclear(res+1); PQexec("end"); @@ -1368,7 +1368,7 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices, indinfo[i].indproc); res = PQexec(q); pbuf = PQparray(res+1); - funcname = dupstr(PQgetvalue(pbuf,0, + funcname = strdup(PQgetvalue(pbuf,0, PQfnumberGroup(pbuf,0,"proname"))); PQclear(res+1); } @@ -1594,7 +1594,7 @@ checkForQuote(char* s) } r[j] = '\0'; - result = dupstr(r); + result = strdup(r); free(r); return result; diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index 1e2ac00e61ff88acd893e1fe71f3ea00fdb19aa4..b7d737536aaf43ce0ceffe1171b4efea5050d650 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.4 1996/08/24 20:49:17 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.5 1996/09/16 06:05:47 scrappy Exp $ * * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2 * @@ -21,6 +21,7 @@ #include <stdlib.h> #include <stdio.h> +#include <string.h> #include <sys/param.h> /* for MAXHOSTNAMELEN on most */ #ifdef PORTNAME_sparc_solaris #include <netdb.h> /* for MAXHOSTNAMELEN on some */ @@ -31,22 +32,6 @@ #include "pg_dump.h" -/* dupstr : copies a string, while allocating space for it. - the CALLER is responsible for freeing the space - returns NULL if the argument is NULL*/ -char* -dupstr(char *s) -{ - char* result; - - if (s == NULL) - return NULL; - - result = (char*)malloc(strlen(s)+1); - strcpy(result, s); - return result; -} - /* * findTypeByOid * given an oid of a type, return its typename @@ -160,7 +145,7 @@ parseArgTypes(char **argtypes, char* str) while ( (s = *str) != '\0') { if (s == ' ') { temp[j] = '\0'; - argtypes[argNum] = dupstr(temp); + argtypes[argNum] = strdup(temp); argNum++; j = 0; } else { @@ -171,7 +156,7 @@ parseArgTypes(char **argtypes, char* str) } if (j != 0) { temp[j] = '\0'; - argtypes[argNum] = dupstr(temp); + argtypes[argNum] = strdup(temp); } } diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index c6fd237012cf085eebd374b65166eb6af2c0fb94..bd02d0c1d304e14364c2efef40edcd32c427bc11 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -20,7 +20,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.7 1996/08/24 20:49:22 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.8 1996/09/16 06:05:54 scrappy Exp $ * * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * @@ -305,19 +305,19 @@ getTypes(int *numTypes) i_typbyval = PQfnumber(res,"typbyval"); for (i=0;i<ntups;i++) { - tinfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); - tinfo[i].typowner = dupstr(PQgetvalue(res,i,i_typowner)); - tinfo[i].typname = dupstr(PQgetvalue(res,i,i_typname)); - tinfo[i].typlen = dupstr(PQgetvalue(res,i,i_typlen)); - tinfo[i].typprtlen = dupstr(PQgetvalue(res,i,i_typprtlen)); - tinfo[i].typinput = dupstr(PQgetvalue(res,i,i_typinput)); - tinfo[i].typoutput = dupstr(PQgetvalue(res,i,i_typoutput)); - tinfo[i].typreceive = dupstr(PQgetvalue(res,i,i_typreceive)); - tinfo[i].typsend = dupstr(PQgetvalue(res,i,i_typsend)); - tinfo[i].typelem = dupstr(PQgetvalue(res,i,i_typelem)); - tinfo[i].typdelim = dupstr(PQgetvalue(res,i,i_typdelim)); - tinfo[i].typdefault = dupstr(PQgetvalue(res,i,i_typdefault)); - tinfo[i].typrelid = dupstr(PQgetvalue(res,i,i_typrelid)); + tinfo[i].oid = strdup(PQgetvalue(res,i,i_oid)); + tinfo[i].typowner = strdup(PQgetvalue(res,i,i_typowner)); + tinfo[i].typname = strdup(PQgetvalue(res,i,i_typname)); + tinfo[i].typlen = strdup(PQgetvalue(res,i,i_typlen)); + tinfo[i].typprtlen = strdup(PQgetvalue(res,i,i_typprtlen)); + tinfo[i].typinput = strdup(PQgetvalue(res,i,i_typinput)); + tinfo[i].typoutput = strdup(PQgetvalue(res,i,i_typoutput)); + tinfo[i].typreceive = strdup(PQgetvalue(res,i,i_typreceive)); + tinfo[i].typsend = strdup(PQgetvalue(res,i,i_typsend)); + tinfo[i].typelem = strdup(PQgetvalue(res,i,i_typelem)); + tinfo[i].typdelim = strdup(PQgetvalue(res,i,i_typdelim)); + tinfo[i].typdefault = strdup(PQgetvalue(res,i,i_typdefault)); + tinfo[i].typrelid = strdup(PQgetvalue(res,i,i_typrelid)); if (strcmp(PQgetvalue(res,i,i_typbyval), "f") == 0) tinfo[i].passedbyvalue = 0; @@ -415,19 +415,19 @@ getOperators(int *numOprs) i_oprrsortop = PQfnumber(res,"oprrsortop"); for (i=0;i<ntups;i++) { - oprinfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); - oprinfo[i].oprname = dupstr(PQgetvalue(res,i,i_oprname)); - oprinfo[i].oprkind = dupstr(PQgetvalue(res,i,i_oprkind)); - oprinfo[i].oprcode = dupstr(PQgetvalue(res,i,i_oprcode)); - oprinfo[i].oprleft = dupstr(PQgetvalue(res,i,i_oprleft)); - oprinfo[i].oprright = dupstr(PQgetvalue(res,i,i_oprright)); - oprinfo[i].oprcom = dupstr(PQgetvalue(res,i,i_oprcom)); - oprinfo[i].oprnegate = dupstr(PQgetvalue(res,i,i_oprnegate)); - oprinfo[i].oprrest = dupstr(PQgetvalue(res,i,i_oprrest)); - oprinfo[i].oprjoin = dupstr(PQgetvalue(res,i,i_oprjoin)); - oprinfo[i].oprcanhash = dupstr(PQgetvalue(res,i,i_oprcanhash)); - oprinfo[i].oprlsortop = dupstr(PQgetvalue(res,i,i_oprlsortop)); - oprinfo[i].oprrsortop = dupstr(PQgetvalue(res,i,i_oprrsortop)); + oprinfo[i].oid = strdup(PQgetvalue(res,i,i_oid)); + oprinfo[i].oprname = strdup(PQgetvalue(res,i,i_oprname)); + oprinfo[i].oprkind = strdup(PQgetvalue(res,i,i_oprkind)); + oprinfo[i].oprcode = strdup(PQgetvalue(res,i,i_oprcode)); + oprinfo[i].oprleft = strdup(PQgetvalue(res,i,i_oprleft)); + oprinfo[i].oprright = strdup(PQgetvalue(res,i,i_oprright)); + oprinfo[i].oprcom = strdup(PQgetvalue(res,i,i_oprcom)); + oprinfo[i].oprnegate = strdup(PQgetvalue(res,i,i_oprnegate)); + oprinfo[i].oprrest = strdup(PQgetvalue(res,i,i_oprrest)); + oprinfo[i].oprjoin = strdup(PQgetvalue(res,i,i_oprjoin)); + oprinfo[i].oprcanhash = strdup(PQgetvalue(res,i,i_oprcanhash)); + oprinfo[i].oprlsortop = strdup(PQgetvalue(res,i,i_oprlsortop)); + oprinfo[i].oprrsortop = strdup(PQgetvalue(res,i,i_oprrsortop)); } PQclear(res); @@ -504,16 +504,16 @@ getAggregates(int *numAggs) i_agginitval2 = PQfnumber(res,"agginitval2"); for (i=0;i<ntups;i++) { - agginfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); - agginfo[i].aggname = dupstr(PQgetvalue(res,i,i_aggname)); - agginfo[i].aggtransfn1 = dupstr(PQgetvalue(res,i,i_aggtransfn1)); - agginfo[i].aggtransfn2 = dupstr(PQgetvalue(res,i,i_aggtransfn2)); - agginfo[i].aggfinalfn = dupstr(PQgetvalue(res,i,i_aggfinalfn)); - agginfo[i].aggtranstype1 = dupstr(PQgetvalue(res,i,i_aggtranstype1)); - agginfo[i].aggbasetype = dupstr(PQgetvalue(res,i,i_aggbasetype)); - agginfo[i].aggtranstype2 = dupstr(PQgetvalue(res,i,i_aggtranstype2)); - agginfo[i].agginitval1 = dupstr(PQgetvalue(res,i,i_agginitval1)); - agginfo[i].agginitval2 = dupstr(PQgetvalue(res,i,i_agginitval2)); + agginfo[i].oid = strdup(PQgetvalue(res,i,i_oid)); + agginfo[i].aggname = strdup(PQgetvalue(res,i,i_aggname)); + agginfo[i].aggtransfn1 = strdup(PQgetvalue(res,i,i_aggtransfn1)); + agginfo[i].aggtransfn2 = strdup(PQgetvalue(res,i,i_aggtransfn2)); + agginfo[i].aggfinalfn = strdup(PQgetvalue(res,i,i_aggfinalfn)); + agginfo[i].aggtranstype1 = strdup(PQgetvalue(res,i,i_aggtranstype1)); + agginfo[i].aggbasetype = strdup(PQgetvalue(res,i,i_aggbasetype)); + agginfo[i].aggtranstype2 = strdup(PQgetvalue(res,i,i_aggtranstype2)); + agginfo[i].agginitval1 = strdup(PQgetvalue(res,i,i_agginitval1)); + agginfo[i].agginitval2 = strdup(PQgetvalue(res,i,i_agginitval2)); } PQclear(res); @@ -591,14 +591,14 @@ getFuncs(int *numFuncs) i_probin = PQfnumber(res,"probin"); for (i=0;i<ntups;i++) { - finfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); - finfo[i].proname = dupstr(PQgetvalue(res,i,i_proname)); - finfo[i].proowner = dupstr(PQgetvalue(res,i,i_proowner)); + finfo[i].oid = strdup(PQgetvalue(res,i,i_oid)); + finfo[i].proname = strdup(PQgetvalue(res,i,i_proname)); + finfo[i].proowner = strdup(PQgetvalue(res,i,i_proowner)); finfo[i].prosrc = checkForQuote(PQgetvalue(res,i,i_prosrc)); - finfo[i].probin = dupstr(PQgetvalue(res,i,i_probin)); + finfo[i].probin = strdup(PQgetvalue(res,i,i_probin)); - finfo[i].prorettype = dupstr(PQgetvalue(res,i,i_prorettype)); + finfo[i].prorettype = strdup(PQgetvalue(res,i,i_prorettype)); finfo[i].retset = (strcmp(PQgetvalue(res,i,i_proretset),"t") == 0); finfo[i].nargs = atoi(PQgetvalue(res,i,i_pronargs)); finfo[i].lang = (atoi(PQgetvalue(res,i,i_prolang)) == C_PROLANG_OID); @@ -673,9 +673,9 @@ getTables(int *numTables) i_relarch = PQfnumber(res,"relarch"); for (i=0;i<ntups;i++) { - tblinfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); - tblinfo[i].relname = dupstr(PQgetvalue(res,i,i_relname)); - tblinfo[i].relarch = dupstr(PQgetvalue(res,i,i_relarch)); + tblinfo[i].oid = strdup(PQgetvalue(res,i,i_oid)); + tblinfo[i].relname = strdup(PQgetvalue(res,i,i_relname)); + tblinfo[i].relarch = strdup(PQgetvalue(res,i,i_relarch)); } PQclear(res); @@ -735,8 +735,8 @@ getInherits(int *numInherits) i_inhparent = PQfnumber(res,"inhparent"); for (i=0;i<ntups;i++) { - inhinfo[i].inhrel = dupstr(PQgetvalue(res,i,i_inhrel)); - inhinfo[i].inhparent = dupstr(PQgetvalue(res,i,i_inhparent)); + inhinfo[i].inhrel = strdup(PQgetvalue(res,i,i_inhrel)); + inhinfo[i].inhparent = strdup(PQgetvalue(res,i,i_inhparent)); } PQclear(res); @@ -804,8 +804,8 @@ getTableAttrs(TableInfo* tblinfo, int numTables) tblinfo[i].parentRels = NULL; tblinfo[i].numParents = 0; for (j=0;j<ntups;j++) { - tblinfo[i].attnames[j] = dupstr(PQgetvalue(res,j,i_attname)); - tblinfo[i].typnames[j] = dupstr(PQgetvalue(res,j,i_typname)); + tblinfo[i].attnames[j] = strdup(PQgetvalue(res,j,i_attname)); + tblinfo[i].typnames[j] = strdup(PQgetvalue(res,j,i_typname)); tblinfo[i].attlen[j] = atoi(PQgetvalue(res,j,i_attlen)); if (tblinfo[i].attlen[j] > 0) tblinfo[i].attlen[j] = tblinfo[i].attlen[j] - 4; @@ -883,12 +883,12 @@ getIndices(int *numIndices) i_indclassname = PQfnumber(res,"indclassname"); for (i=0;i<ntups;i++) { - indinfo[i].indexrelname = dupstr(PQgetvalue(res,i,i_indexrelname)); - indinfo[i].indrelname = dupstr(PQgetvalue(res,i,i_indrelname)); - indinfo[i].indamname = dupstr(PQgetvalue(res,i,i_indamname)); - indinfo[i].indproc = dupstr(PQgetvalue(res,i,i_indproc)); - indinfo[i].indkey = dupstr(PQgetvalue(res,i,i_indkey)); - indinfo[i].indclassname = dupstr(PQgetvalue(res,i,i_indclassname)); + indinfo[i].indexrelname = strdup(PQgetvalue(res,i,i_indexrelname)); + indinfo[i].indrelname = strdup(PQgetvalue(res,i,i_indrelname)); + indinfo[i].indamname = strdup(PQgetvalue(res,i,i_indamname)); + indinfo[i].indproc = strdup(PQgetvalue(res,i,i_indproc)); + indinfo[i].indkey = strdup(PQgetvalue(res,i,i_indkey)); + indinfo[i].indclassname = strdup(PQgetvalue(res,i,i_indclassname)); } PQclear(res); res = PQexec(g_conn,"end"); @@ -1331,7 +1331,7 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices, "SELECT proname from pg_proc where pg_proc.oid = '%s'::oid", indinfo[i].indproc); res = PQexec(g_conn, q); - funcname = dupstr(PQgetvalue(res, 0, + funcname = strdup(PQgetvalue(res, 0, PQfnumber(res,"proname"))); PQclear(res); } @@ -1654,7 +1654,7 @@ checkForQuote(char* s) } r[j] = '\0'; - result = dupstr(r); + result = strdup(r); free(r); return result; diff --git a/src/bin/psql/psql.c b/src/bin/psql/psql.c index 8ad2dd45eb44f5cde4d6d682c51779f9982c0882..fedd9fb85bab3f2b1512c12be5bd9bb00b9114f3 100644 --- a/src/bin/psql/psql.c +++ b/src/bin/psql/psql.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.20 1996/08/21 00:22:41 julian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.21 1996/09/16 06:06:11 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -631,7 +631,7 @@ HandleSlashCmds(PsqlSettings *settings, if (!optarg) settings->opt.caption=NULL; else - if (!(settings->opt.caption=dupstr(optarg))) + if (!(settings->opt.caption=strdup(optarg))) { perror("malloc"); exit(1); @@ -787,7 +787,7 @@ HandleSlashCmds(PsqlSettings *settings, fs=optarg; if (settings->opt.fieldSep); free(settings->opt.fieldSep); - if (!(settings->opt.fieldSep=dupstr(fs))) + if (!(settings->opt.fieldSep=strdup(fs))) { perror("malloc"); exit(1); @@ -903,13 +903,13 @@ HandleSlashCmds(PsqlSettings *settings, settings->opt.html3 = settings->opt.expanded = 0; settings->opt.align = settings->opt.header = 1; free(settings->opt.fieldSep); - settings->opt.fieldSep=dupstr("|"); + settings->opt.fieldSep=strdup("|"); if (!settings->quiet) fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep); } else { free(settings->opt.fieldSep); - settings->opt.fieldSep=dupstr(DEFAULT_FIELD_SEP); + settings->opt.fieldSep=strdup(DEFAULT_FIELD_SEP); if (!settings->quiet) fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep); } @@ -923,7 +923,7 @@ HandleSlashCmds(PsqlSettings *settings, if (!optarg) settings->opt.tableOpt=NULL; else - if (!(settings->opt.tableOpt=dupstr(optarg))) + if (!(settings->opt.tableOpt=strdup(optarg))) { perror("malloc"); exit(1); @@ -1144,7 +1144,7 @@ main(int argc, char **argv) settings.opt.align = 1; settings.opt.header = 1; settings.queryFout = stdout; - settings.opt.fieldSep=dupstr(DEFAULT_FIELD_SEP); + settings.opt.fieldSep=strdup(DEFAULT_FIELD_SEP); settings.opt.pager = 1; if (!isatty(0) || !isatty(1)) settings.quiet = settings.notty = 1; diff --git a/src/bin/psql/stringutils.c b/src/bin/psql/stringutils.c index daeb120ef9aa84b4502d8a27760ce9ec6aaacd1a..42902e64384ac11c0e5235a960e0d47c62dc92ee 100644 --- a/src/bin/psql/stringutils.c +++ b/src/bin/psql/stringutils.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.3 1996/08/06 20:23:14 julian Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.4 1996/09/16 06:06:17 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -57,22 +57,6 @@ char *doubleTrim(char *s) return s; } -/* dupstr : copies a string, while allocating space for it. - the CALLER is responsible for freeing the space - returns NULL if the argument is NULL */ -char *dupstr(char *s) -{ - char *result; - - if (s == NULL) - return NULL; - - result = (char*)malloc(strlen(s)+1); - strcpy(result, s); - return result; -} - - #ifdef STRINGUTILS_TEST void testStringUtils() { @@ -87,13 +71,13 @@ void testStringUtils() while (tests[i]!=NULL_STR) { char *t; - t = dupstr(tests[i]); + t = strdup(tests[i]); printf("leftTrim(%s) = ",t); printf("%sEND\n", leftTrim(t)); - t = dupstr(tests[i]); + t = strdup(tests[i]); printf("rightTrim(%s) = ",t); printf("%sEND\n", rightTrim(t)); - t = dupstr(tests[i]); + t = strdup(tests[i]); printf("doubleTrim(%s) = ",t); printf("%sEND\n", doubleTrim(t)); i++;