Commit f589ca68 authored by Marc G. Fournier's avatar Marc G. Fournier

The following diffs remove the various definitions of dupstr() and replace

all the calls with strdup.

Submitted by: darcy@druid.druid.com (D'Arcy J.M. Cain)
parent 24f00122
...@@ -43,23 +43,6 @@ check_conn_and_db() ...@@ -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 * findTypeByOid
* given an oid of a type, return its typename * given an oid of a type, return its typename
...@@ -173,7 +156,7 @@ parseArgTypes(char **argtypes, char* str) ...@@ -173,7 +156,7 @@ parseArgTypes(char **argtypes, char* str)
while ( (s = *str) != '\0') { while ( (s = *str) != '\0') {
if (s == ' ') { if (s == ' ') {
temp[j] = '\0'; temp[j] = '\0';
argtypes[argNum] = dupstr(temp); argtypes[argNum] = strdup(temp);
argNum++; argNum++;
j = 0; j = 0;
} else { } else {
...@@ -184,7 +167,7 @@ parseArgTypes(char **argtypes, char* str) ...@@ -184,7 +167,7 @@ parseArgTypes(char **argtypes, char* str)
} }
if (j != 0) { if (j != 0) {
temp[j] = '\0'; temp[j] = '\0';
argtypes[argNum] = dupstr(temp); argtypes[argNum] = strdup(temp);
} }
} }
......
...@@ -289,19 +289,19 @@ getTypes(int *numTypes) ...@@ -289,19 +289,19 @@ getTypes(int *numTypes)
i_typbyval = PQfnumberGroup(pbuf,0,"typbyval"); i_typbyval = PQfnumberGroup(pbuf,0,"typbyval");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
tinfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); tinfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid));
tinfo[i].typowner = dupstr(PQgetvalue(pbuf,i,i_typowner)); tinfo[i].typowner = strdup(PQgetvalue(pbuf,i,i_typowner));
tinfo[i].typname = dupstr(PQgetvalue(pbuf,i,i_typname)); tinfo[i].typname = strdup(PQgetvalue(pbuf,i,i_typname));
tinfo[i].typlen = dupstr(PQgetvalue(pbuf,i,i_typlen)); tinfo[i].typlen = strdup(PQgetvalue(pbuf,i,i_typlen));
tinfo[i].typprtlen = dupstr(PQgetvalue(pbuf,i,i_typprtlen)); tinfo[i].typprtlen = strdup(PQgetvalue(pbuf,i,i_typprtlen));
tinfo[i].typinput = dupstr(PQgetvalue(pbuf,i,i_typinput)); tinfo[i].typinput = strdup(PQgetvalue(pbuf,i,i_typinput));
tinfo[i].typoutput = dupstr(PQgetvalue(pbuf,i,i_typoutput)); tinfo[i].typoutput = strdup(PQgetvalue(pbuf,i,i_typoutput));
tinfo[i].typreceive = dupstr(PQgetvalue(pbuf,i,i_typreceive)); tinfo[i].typreceive = strdup(PQgetvalue(pbuf,i,i_typreceive));
tinfo[i].typsend = dupstr(PQgetvalue(pbuf,i,i_typsend)); tinfo[i].typsend = strdup(PQgetvalue(pbuf,i,i_typsend));
tinfo[i].typelem = dupstr(PQgetvalue(pbuf,i,i_typelem)); tinfo[i].typelem = strdup(PQgetvalue(pbuf,i,i_typelem));
tinfo[i].typdelim = dupstr(PQgetvalue(pbuf,i,i_typdelim)); tinfo[i].typdelim = strdup(PQgetvalue(pbuf,i,i_typdelim));
tinfo[i].typdefault = dupstr(PQgetvalue(pbuf,i,i_typdefault)); tinfo[i].typdefault = strdup(PQgetvalue(pbuf,i,i_typdefault));
tinfo[i].typrelid = dupstr(PQgetvalue(pbuf,i,i_typrelid)); tinfo[i].typrelid = strdup(PQgetvalue(pbuf,i,i_typrelid));
if (strcmp(PQgetvalue(pbuf,i,i_typbyval), "f") == 0) if (strcmp(PQgetvalue(pbuf,i,i_typbyval), "f") == 0)
tinfo[i].passedbyvalue = 0; tinfo[i].passedbyvalue = 0;
...@@ -390,19 +390,19 @@ getOperators(int *numOprs) ...@@ -390,19 +390,19 @@ getOperators(int *numOprs)
i_oprrsortop = PQfnumberGroup(pbuf,0,"oprrsortop"); i_oprrsortop = PQfnumberGroup(pbuf,0,"oprrsortop");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
oprinfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); oprinfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid));
oprinfo[i].oprname = dupstr(PQgetvalue(pbuf,i,i_oprname)); oprinfo[i].oprname = strdup(PQgetvalue(pbuf,i,i_oprname));
oprinfo[i].oprkind = dupstr(PQgetvalue(pbuf,i,i_oprkind)); oprinfo[i].oprkind = strdup(PQgetvalue(pbuf,i,i_oprkind));
oprinfo[i].oprcode = dupstr(PQgetvalue(pbuf,i,i_oprcode)); oprinfo[i].oprcode = strdup(PQgetvalue(pbuf,i,i_oprcode));
oprinfo[i].oprleft = dupstr(PQgetvalue(pbuf,i,i_oprleft)); oprinfo[i].oprleft = strdup(PQgetvalue(pbuf,i,i_oprleft));
oprinfo[i].oprright = dupstr(PQgetvalue(pbuf,i,i_oprright)); oprinfo[i].oprright = strdup(PQgetvalue(pbuf,i,i_oprright));
oprinfo[i].oprcom = dupstr(PQgetvalue(pbuf,i,i_oprcom)); oprinfo[i].oprcom = strdup(PQgetvalue(pbuf,i,i_oprcom));
oprinfo[i].oprnegate = dupstr(PQgetvalue(pbuf,i,i_oprnegate)); oprinfo[i].oprnegate = strdup(PQgetvalue(pbuf,i,i_oprnegate));
oprinfo[i].oprrest = dupstr(PQgetvalue(pbuf,i,i_oprrest)); oprinfo[i].oprrest = strdup(PQgetvalue(pbuf,i,i_oprrest));
oprinfo[i].oprjoin = dupstr(PQgetvalue(pbuf,i,i_oprjoin)); oprinfo[i].oprjoin = strdup(PQgetvalue(pbuf,i,i_oprjoin));
oprinfo[i].oprcanhash = dupstr(PQgetvalue(pbuf,i,i_oprcanhash)); oprinfo[i].oprcanhash = strdup(PQgetvalue(pbuf,i,i_oprcanhash));
oprinfo[i].oprlsortop = dupstr(PQgetvalue(pbuf,i,i_oprlsortop)); oprinfo[i].oprlsortop = strdup(PQgetvalue(pbuf,i,i_oprlsortop));
oprinfo[i].oprrsortop = dupstr(PQgetvalue(pbuf,i,i_oprrsortop)); oprinfo[i].oprrsortop = strdup(PQgetvalue(pbuf,i,i_oprrsortop));
} }
PQclear(res+1); PQclear(res+1);
...@@ -471,16 +471,16 @@ getAggregates(int *numAggs) ...@@ -471,16 +471,16 @@ getAggregates(int *numAggs)
i_agginitval2 = PQfnumberGroup(pbuf,0,"agginitval2"); i_agginitval2 = PQfnumberGroup(pbuf,0,"agginitval2");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
agginfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); agginfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid));
agginfo[i].aggname = dupstr(PQgetvalue(pbuf,i,i_aggname)); agginfo[i].aggname = strdup(PQgetvalue(pbuf,i,i_aggname));
agginfo[i].aggtransfn1 = dupstr(PQgetvalue(pbuf,i,i_aggtransfn1)); agginfo[i].aggtransfn1 = strdup(PQgetvalue(pbuf,i,i_aggtransfn1));
agginfo[i].aggtransfn2 = dupstr(PQgetvalue(pbuf,i,i_aggtransfn2)); agginfo[i].aggtransfn2 = strdup(PQgetvalue(pbuf,i,i_aggtransfn2));
agginfo[i].aggfinalfn = dupstr(PQgetvalue(pbuf,i,i_aggfinalfn)); agginfo[i].aggfinalfn = strdup(PQgetvalue(pbuf,i,i_aggfinalfn));
agginfo[i].aggtranstype1 = dupstr(PQgetvalue(pbuf,i,i_aggtranstype1)); agginfo[i].aggtranstype1 = strdup(PQgetvalue(pbuf,i,i_aggtranstype1));
agginfo[i].aggbasetype = dupstr(PQgetvalue(pbuf,i,i_aggbasetype)); agginfo[i].aggbasetype = strdup(PQgetvalue(pbuf,i,i_aggbasetype));
agginfo[i].aggtranstype2 = dupstr(PQgetvalue(pbuf,i,i_aggtranstype2)); agginfo[i].aggtranstype2 = strdup(PQgetvalue(pbuf,i,i_aggtranstype2));
agginfo[i].agginitval1 = dupstr(PQgetvalue(pbuf,i,i_agginitval1)); agginfo[i].agginitval1 = strdup(PQgetvalue(pbuf,i,i_agginitval1));
agginfo[i].agginitval2 = dupstr(PQgetvalue(pbuf,i,i_agginitval2)); agginfo[i].agginitval2 = strdup(PQgetvalue(pbuf,i,i_agginitval2));
} }
PQclear(res+1); PQclear(res+1);
...@@ -553,14 +553,14 @@ getFuncs(int *numFuncs) ...@@ -553,14 +553,14 @@ getFuncs(int *numFuncs)
i_probin = PQfnumberGroup(pbuf,0,"probin"); i_probin = PQfnumberGroup(pbuf,0,"probin");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
finfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); finfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid));
finfo[i].proname = dupstr(PQgetvalue(pbuf,i,i_proname)); finfo[i].proname = strdup(PQgetvalue(pbuf,i,i_proname));
finfo[i].proowner = dupstr(PQgetvalue(pbuf,i,i_proowner)); finfo[i].proowner = strdup(PQgetvalue(pbuf,i,i_proowner));
finfo[i].prosrc = checkForQuote(PQgetvalue(pbuf,i,i_prosrc)); 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].retset = (strcmp(PQgetvalue(pbuf,i,i_proretset),"t") == 0);
finfo[i].nargs = atoi(PQgetvalue(pbuf,i,i_pronargs)); finfo[i].nargs = atoi(PQgetvalue(pbuf,i,i_pronargs));
finfo[i].lang = (atoi(PQgetvalue(pbuf,i,i_prolang)) == C_PROLANG_OID); finfo[i].lang = (atoi(PQgetvalue(pbuf,i,i_prolang)) == C_PROLANG_OID);
...@@ -624,9 +624,9 @@ getTables(int *numTables) ...@@ -624,9 +624,9 @@ getTables(int *numTables)
i_relarch = PQfnumberGroup(pbuf,0,"relarch"); i_relarch = PQfnumberGroup(pbuf,0,"relarch");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
tblinfo[i].oid = dupstr(PQgetvalue(pbuf,i,i_oid)); tblinfo[i].oid = strdup(PQgetvalue(pbuf,i,i_oid));
tblinfo[i].relname = dupstr(PQgetvalue(pbuf,i,i_relname)); tblinfo[i].relname = strdup(PQgetvalue(pbuf,i,i_relname));
tblinfo[i].relarch = dupstr(PQgetvalue(pbuf,i,i_relarch)); tblinfo[i].relarch = strdup(PQgetvalue(pbuf,i,i_relarch));
} }
PQclear(res+1); PQclear(res+1);
...@@ -677,8 +677,8 @@ getInherits(int *numInherits) ...@@ -677,8 +677,8 @@ getInherits(int *numInherits)
i_inhparent = PQfnumberGroup(pbuf,0,"inhparent"); i_inhparent = PQfnumberGroup(pbuf,0,"inhparent");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
inhinfo[i].inhrel = dupstr(PQgetvalue(pbuf,i,i_inhrel)); inhinfo[i].inhrel = strdup(PQgetvalue(pbuf,i,i_inhrel));
inhinfo[i].inhparent = dupstr(PQgetvalue(pbuf,i,i_inhparent)); inhinfo[i].inhparent = strdup(PQgetvalue(pbuf,i,i_inhparent));
} }
PQclear(res+1); PQclear(res+1);
...@@ -740,8 +740,8 @@ if (g_verbose) ...@@ -740,8 +740,8 @@ if (g_verbose)
tblinfo[i].parentRels = NULL; tblinfo[i].parentRels = NULL;
tblinfo[i].numParents = 0; tblinfo[i].numParents = 0;
for (j=0;j<ntups;j++) { for (j=0;j<ntups;j++) {
tblinfo[i].attnames[j] = dupstr(PQgetvalue(pbuf,j,i_attname)); tblinfo[i].attnames[j] = strdup(PQgetvalue(pbuf,j,i_attname));
tblinfo[i].typnames[j] = dupstr(PQgetvalue(pbuf,j,i_typname)); tblinfo[i].typnames[j] = strdup(PQgetvalue(pbuf,j,i_typname));
tblinfo[i].inhAttrs[j] = 0; /* this flag is set in flagInhAttrs()*/ tblinfo[i].inhAttrs[j] = 0; /* this flag is set in flagInhAttrs()*/
} }
PQclear(res+1); PQclear(res+1);
...@@ -809,12 +809,12 @@ getIndices(int *numIndices) ...@@ -809,12 +809,12 @@ getIndices(int *numIndices)
i_indclassname = PQfnumberGroup(pbuf,0,"indclassname"); i_indclassname = PQfnumberGroup(pbuf,0,"indclassname");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
indinfo[i].indexrelname = dupstr(PQgetvalue(pbuf,i,i_indexrelname)); indinfo[i].indexrelname = strdup(PQgetvalue(pbuf,i,i_indexrelname));
indinfo[i].indrelname = dupstr(PQgetvalue(pbuf,i,i_indrelname)); indinfo[i].indrelname = strdup(PQgetvalue(pbuf,i,i_indrelname));
indinfo[i].indamname = dupstr(PQgetvalue(pbuf,i,i_indamname)); indinfo[i].indamname = strdup(PQgetvalue(pbuf,i,i_indamname));
indinfo[i].indproc = dupstr(PQgetvalue(pbuf,i,i_indproc)); indinfo[i].indproc = strdup(PQgetvalue(pbuf,i,i_indproc));
indinfo[i].indkey = dupstr(PQgetvalue(pbuf,i,i_indkey)); indinfo[i].indkey = strdup(PQgetvalue(pbuf,i,i_indkey));
indinfo[i].indclassname = dupstr(PQgetvalue(pbuf,i,i_indclassname)); indinfo[i].indclassname = strdup(PQgetvalue(pbuf,i,i_indclassname));
} }
PQclear(res+1); PQclear(res+1);
PQexec("end"); PQexec("end");
...@@ -1368,7 +1368,7 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices, ...@@ -1368,7 +1368,7 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices,
indinfo[i].indproc); indinfo[i].indproc);
res = PQexec(q); res = PQexec(q);
pbuf = PQparray(res+1); pbuf = PQparray(res+1);
funcname = dupstr(PQgetvalue(pbuf,0, funcname = strdup(PQgetvalue(pbuf,0,
PQfnumberGroup(pbuf,0,"proname"))); PQfnumberGroup(pbuf,0,"proname")));
PQclear(res+1); PQclear(res+1);
} }
...@@ -1594,7 +1594,7 @@ checkForQuote(char* s) ...@@ -1594,7 +1594,7 @@ checkForQuote(char* s)
} }
r[j] = '\0'; r[j] = '\0';
result = dupstr(r); result = strdup(r);
free(r); free(r);
return result; return result;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
* *
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <sys/param.h> /* for MAXHOSTNAMELEN on most */ #include <sys/param.h> /* for MAXHOSTNAMELEN on most */
#ifdef PORTNAME_sparc_solaris #ifdef PORTNAME_sparc_solaris
#include <netdb.h> /* for MAXHOSTNAMELEN on some */ #include <netdb.h> /* for MAXHOSTNAMELEN on some */
...@@ -31,22 +32,6 @@ ...@@ -31,22 +32,6 @@
#include "pg_dump.h" #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 * findTypeByOid
* given an oid of a type, return its typename * given an oid of a type, return its typename
...@@ -160,7 +145,7 @@ parseArgTypes(char **argtypes, char* str) ...@@ -160,7 +145,7 @@ parseArgTypes(char **argtypes, char* str)
while ( (s = *str) != '\0') { while ( (s = *str) != '\0') {
if (s == ' ') { if (s == ' ') {
temp[j] = '\0'; temp[j] = '\0';
argtypes[argNum] = dupstr(temp); argtypes[argNum] = strdup(temp);
argNum++; argNum++;
j = 0; j = 0;
} else { } else {
...@@ -171,7 +156,7 @@ parseArgTypes(char **argtypes, char* str) ...@@ -171,7 +156,7 @@ parseArgTypes(char **argtypes, char* str)
} }
if (j != 0) { if (j != 0) {
temp[j] = '\0'; temp[j] = '\0';
argtypes[argNum] = dupstr(temp); argtypes[argNum] = strdup(temp);
} }
} }
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* *
* *
* IDENTIFICATION * 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 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
...@@ -305,19 +305,19 @@ getTypes(int *numTypes) ...@@ -305,19 +305,19 @@ getTypes(int *numTypes)
i_typbyval = PQfnumber(res,"typbyval"); i_typbyval = PQfnumber(res,"typbyval");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
tinfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); tinfo[i].oid = strdup(PQgetvalue(res,i,i_oid));
tinfo[i].typowner = dupstr(PQgetvalue(res,i,i_typowner)); tinfo[i].typowner = strdup(PQgetvalue(res,i,i_typowner));
tinfo[i].typname = dupstr(PQgetvalue(res,i,i_typname)); tinfo[i].typname = strdup(PQgetvalue(res,i,i_typname));
tinfo[i].typlen = dupstr(PQgetvalue(res,i,i_typlen)); tinfo[i].typlen = strdup(PQgetvalue(res,i,i_typlen));
tinfo[i].typprtlen = dupstr(PQgetvalue(res,i,i_typprtlen)); tinfo[i].typprtlen = strdup(PQgetvalue(res,i,i_typprtlen));
tinfo[i].typinput = dupstr(PQgetvalue(res,i,i_typinput)); tinfo[i].typinput = strdup(PQgetvalue(res,i,i_typinput));
tinfo[i].typoutput = dupstr(PQgetvalue(res,i,i_typoutput)); tinfo[i].typoutput = strdup(PQgetvalue(res,i,i_typoutput));
tinfo[i].typreceive = dupstr(PQgetvalue(res,i,i_typreceive)); tinfo[i].typreceive = strdup(PQgetvalue(res,i,i_typreceive));
tinfo[i].typsend = dupstr(PQgetvalue(res,i,i_typsend)); tinfo[i].typsend = strdup(PQgetvalue(res,i,i_typsend));
tinfo[i].typelem = dupstr(PQgetvalue(res,i,i_typelem)); tinfo[i].typelem = strdup(PQgetvalue(res,i,i_typelem));
tinfo[i].typdelim = dupstr(PQgetvalue(res,i,i_typdelim)); tinfo[i].typdelim = strdup(PQgetvalue(res,i,i_typdelim));
tinfo[i].typdefault = dupstr(PQgetvalue(res,i,i_typdefault)); tinfo[i].typdefault = strdup(PQgetvalue(res,i,i_typdefault));
tinfo[i].typrelid = dupstr(PQgetvalue(res,i,i_typrelid)); tinfo[i].typrelid = strdup(PQgetvalue(res,i,i_typrelid));
if (strcmp(PQgetvalue(res,i,i_typbyval), "f") == 0) if (strcmp(PQgetvalue(res,i,i_typbyval), "f") == 0)
tinfo[i].passedbyvalue = 0; tinfo[i].passedbyvalue = 0;
...@@ -415,19 +415,19 @@ getOperators(int *numOprs) ...@@ -415,19 +415,19 @@ getOperators(int *numOprs)
i_oprrsortop = PQfnumber(res,"oprrsortop"); i_oprrsortop = PQfnumber(res,"oprrsortop");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
oprinfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); oprinfo[i].oid = strdup(PQgetvalue(res,i,i_oid));
oprinfo[i].oprname = dupstr(PQgetvalue(res,i,i_oprname)); oprinfo[i].oprname = strdup(PQgetvalue(res,i,i_oprname));
oprinfo[i].oprkind = dupstr(PQgetvalue(res,i,i_oprkind)); oprinfo[i].oprkind = strdup(PQgetvalue(res,i,i_oprkind));
oprinfo[i].oprcode = dupstr(PQgetvalue(res,i,i_oprcode)); oprinfo[i].oprcode = strdup(PQgetvalue(res,i,i_oprcode));
oprinfo[i].oprleft = dupstr(PQgetvalue(res,i,i_oprleft)); oprinfo[i].oprleft = strdup(PQgetvalue(res,i,i_oprleft));
oprinfo[i].oprright = dupstr(PQgetvalue(res,i,i_oprright)); oprinfo[i].oprright = strdup(PQgetvalue(res,i,i_oprright));
oprinfo[i].oprcom = dupstr(PQgetvalue(res,i,i_oprcom)); oprinfo[i].oprcom = strdup(PQgetvalue(res,i,i_oprcom));
oprinfo[i].oprnegate = dupstr(PQgetvalue(res,i,i_oprnegate)); oprinfo[i].oprnegate = strdup(PQgetvalue(res,i,i_oprnegate));
oprinfo[i].oprrest = dupstr(PQgetvalue(res,i,i_oprrest)); oprinfo[i].oprrest = strdup(PQgetvalue(res,i,i_oprrest));
oprinfo[i].oprjoin = dupstr(PQgetvalue(res,i,i_oprjoin)); oprinfo[i].oprjoin = strdup(PQgetvalue(res,i,i_oprjoin));
oprinfo[i].oprcanhash = dupstr(PQgetvalue(res,i,i_oprcanhash)); oprinfo[i].oprcanhash = strdup(PQgetvalue(res,i,i_oprcanhash));
oprinfo[i].oprlsortop = dupstr(PQgetvalue(res,i,i_oprlsortop)); oprinfo[i].oprlsortop = strdup(PQgetvalue(res,i,i_oprlsortop));
oprinfo[i].oprrsortop = dupstr(PQgetvalue(res,i,i_oprrsortop)); oprinfo[i].oprrsortop = strdup(PQgetvalue(res,i,i_oprrsortop));
} }
PQclear(res); PQclear(res);
...@@ -504,16 +504,16 @@ getAggregates(int *numAggs) ...@@ -504,16 +504,16 @@ getAggregates(int *numAggs)
i_agginitval2 = PQfnumber(res,"agginitval2"); i_agginitval2 = PQfnumber(res,"agginitval2");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
agginfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); agginfo[i].oid = strdup(PQgetvalue(res,i,i_oid));
agginfo[i].aggname = dupstr(PQgetvalue(res,i,i_aggname)); agginfo[i].aggname = strdup(PQgetvalue(res,i,i_aggname));
agginfo[i].aggtransfn1 = dupstr(PQgetvalue(res,i,i_aggtransfn1)); agginfo[i].aggtransfn1 = strdup(PQgetvalue(res,i,i_aggtransfn1));
agginfo[i].aggtransfn2 = dupstr(PQgetvalue(res,i,i_aggtransfn2)); agginfo[i].aggtransfn2 = strdup(PQgetvalue(res,i,i_aggtransfn2));
agginfo[i].aggfinalfn = dupstr(PQgetvalue(res,i,i_aggfinalfn)); agginfo[i].aggfinalfn = strdup(PQgetvalue(res,i,i_aggfinalfn));
agginfo[i].aggtranstype1 = dupstr(PQgetvalue(res,i,i_aggtranstype1)); agginfo[i].aggtranstype1 = strdup(PQgetvalue(res,i,i_aggtranstype1));
agginfo[i].aggbasetype = dupstr(PQgetvalue(res,i,i_aggbasetype)); agginfo[i].aggbasetype = strdup(PQgetvalue(res,i,i_aggbasetype));
agginfo[i].aggtranstype2 = dupstr(PQgetvalue(res,i,i_aggtranstype2)); agginfo[i].aggtranstype2 = strdup(PQgetvalue(res,i,i_aggtranstype2));
agginfo[i].agginitval1 = dupstr(PQgetvalue(res,i,i_agginitval1)); agginfo[i].agginitval1 = strdup(PQgetvalue(res,i,i_agginitval1));
agginfo[i].agginitval2 = dupstr(PQgetvalue(res,i,i_agginitval2)); agginfo[i].agginitval2 = strdup(PQgetvalue(res,i,i_agginitval2));
} }
PQclear(res); PQclear(res);
...@@ -591,14 +591,14 @@ getFuncs(int *numFuncs) ...@@ -591,14 +591,14 @@ getFuncs(int *numFuncs)
i_probin = PQfnumber(res,"probin"); i_probin = PQfnumber(res,"probin");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
finfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); finfo[i].oid = strdup(PQgetvalue(res,i,i_oid));
finfo[i].proname = dupstr(PQgetvalue(res,i,i_proname)); finfo[i].proname = strdup(PQgetvalue(res,i,i_proname));
finfo[i].proowner = dupstr(PQgetvalue(res,i,i_proowner)); finfo[i].proowner = strdup(PQgetvalue(res,i,i_proowner));
finfo[i].prosrc = checkForQuote(PQgetvalue(res,i,i_prosrc)); 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].retset = (strcmp(PQgetvalue(res,i,i_proretset),"t") == 0);
finfo[i].nargs = atoi(PQgetvalue(res,i,i_pronargs)); finfo[i].nargs = atoi(PQgetvalue(res,i,i_pronargs));
finfo[i].lang = (atoi(PQgetvalue(res,i,i_prolang)) == C_PROLANG_OID); finfo[i].lang = (atoi(PQgetvalue(res,i,i_prolang)) == C_PROLANG_OID);
...@@ -673,9 +673,9 @@ getTables(int *numTables) ...@@ -673,9 +673,9 @@ getTables(int *numTables)
i_relarch = PQfnumber(res,"relarch"); i_relarch = PQfnumber(res,"relarch");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
tblinfo[i].oid = dupstr(PQgetvalue(res,i,i_oid)); tblinfo[i].oid = strdup(PQgetvalue(res,i,i_oid));
tblinfo[i].relname = dupstr(PQgetvalue(res,i,i_relname)); tblinfo[i].relname = strdup(PQgetvalue(res,i,i_relname));
tblinfo[i].relarch = dupstr(PQgetvalue(res,i,i_relarch)); tblinfo[i].relarch = strdup(PQgetvalue(res,i,i_relarch));
} }
PQclear(res); PQclear(res);
...@@ -735,8 +735,8 @@ getInherits(int *numInherits) ...@@ -735,8 +735,8 @@ getInherits(int *numInherits)
i_inhparent = PQfnumber(res,"inhparent"); i_inhparent = PQfnumber(res,"inhparent");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
inhinfo[i].inhrel = dupstr(PQgetvalue(res,i,i_inhrel)); inhinfo[i].inhrel = strdup(PQgetvalue(res,i,i_inhrel));
inhinfo[i].inhparent = dupstr(PQgetvalue(res,i,i_inhparent)); inhinfo[i].inhparent = strdup(PQgetvalue(res,i,i_inhparent));
} }
PQclear(res); PQclear(res);
...@@ -804,8 +804,8 @@ getTableAttrs(TableInfo* tblinfo, int numTables) ...@@ -804,8 +804,8 @@ getTableAttrs(TableInfo* tblinfo, int numTables)
tblinfo[i].parentRels = NULL; tblinfo[i].parentRels = NULL;
tblinfo[i].numParents = 0; tblinfo[i].numParents = 0;
for (j=0;j<ntups;j++) { for (j=0;j<ntups;j++) {
tblinfo[i].attnames[j] = dupstr(PQgetvalue(res,j,i_attname)); tblinfo[i].attnames[j] = strdup(PQgetvalue(res,j,i_attname));
tblinfo[i].typnames[j] = dupstr(PQgetvalue(res,j,i_typname)); tblinfo[i].typnames[j] = strdup(PQgetvalue(res,j,i_typname));
tblinfo[i].attlen[j] = atoi(PQgetvalue(res,j,i_attlen)); tblinfo[i].attlen[j] = atoi(PQgetvalue(res,j,i_attlen));
if (tblinfo[i].attlen[j] > 0) if (tblinfo[i].attlen[j] > 0)
tblinfo[i].attlen[j] = tblinfo[i].attlen[j] - 4; tblinfo[i].attlen[j] = tblinfo[i].attlen[j] - 4;
...@@ -883,12 +883,12 @@ getIndices(int *numIndices) ...@@ -883,12 +883,12 @@ getIndices(int *numIndices)
i_indclassname = PQfnumber(res,"indclassname"); i_indclassname = PQfnumber(res,"indclassname");
for (i=0;i<ntups;i++) { for (i=0;i<ntups;i++) {
indinfo[i].indexrelname = dupstr(PQgetvalue(res,i,i_indexrelname)); indinfo[i].indexrelname = strdup(PQgetvalue(res,i,i_indexrelname));
indinfo[i].indrelname = dupstr(PQgetvalue(res,i,i_indrelname)); indinfo[i].indrelname = strdup(PQgetvalue(res,i,i_indrelname));
indinfo[i].indamname = dupstr(PQgetvalue(res,i,i_indamname)); indinfo[i].indamname = strdup(PQgetvalue(res,i,i_indamname));
indinfo[i].indproc = dupstr(PQgetvalue(res,i,i_indproc)); indinfo[i].indproc = strdup(PQgetvalue(res,i,i_indproc));
indinfo[i].indkey = dupstr(PQgetvalue(res,i,i_indkey)); indinfo[i].indkey = strdup(PQgetvalue(res,i,i_indkey));
indinfo[i].indclassname = dupstr(PQgetvalue(res,i,i_indclassname)); indinfo[i].indclassname = strdup(PQgetvalue(res,i,i_indclassname));
} }
PQclear(res); PQclear(res);
res = PQexec(g_conn,"end"); res = PQexec(g_conn,"end");
...@@ -1331,7 +1331,7 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices, ...@@ -1331,7 +1331,7 @@ dumpIndices(FILE* fout, IndInfo* indinfo, int numIndices,
"SELECT proname from pg_proc where pg_proc.oid = '%s'::oid", "SELECT proname from pg_proc where pg_proc.oid = '%s'::oid",
indinfo[i].indproc); indinfo[i].indproc);
res = PQexec(g_conn, q); res = PQexec(g_conn, q);
funcname = dupstr(PQgetvalue(res, 0, funcname = strdup(PQgetvalue(res, 0,
PQfnumber(res,"proname"))); PQfnumber(res,"proname")));
PQclear(res); PQclear(res);
} }
...@@ -1654,7 +1654,7 @@ checkForQuote(char* s) ...@@ -1654,7 +1654,7 @@ checkForQuote(char* s)
} }
r[j] = '\0'; r[j] = '\0';
result = dupstr(r); result = strdup(r);
free(r); free(r);
return result; return result;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -631,7 +631,7 @@ HandleSlashCmds(PsqlSettings *settings,
if (!optarg) if (!optarg)
settings->opt.caption=NULL; settings->opt.caption=NULL;
else else
if (!(settings->opt.caption=dupstr(optarg))) if (!(settings->opt.caption=strdup(optarg)))
{ {
perror("malloc"); perror("malloc");
exit(1); exit(1);
...@@ -787,7 +787,7 @@ HandleSlashCmds(PsqlSettings *settings, ...@@ -787,7 +787,7 @@ HandleSlashCmds(PsqlSettings *settings,
fs=optarg; fs=optarg;
if (settings->opt.fieldSep); if (settings->opt.fieldSep);
free(settings->opt.fieldSep); free(settings->opt.fieldSep);
if (!(settings->opt.fieldSep=dupstr(fs))) if (!(settings->opt.fieldSep=strdup(fs)))
{ {
perror("malloc"); perror("malloc");
exit(1); exit(1);
...@@ -903,13 +903,13 @@ HandleSlashCmds(PsqlSettings *settings, ...@@ -903,13 +903,13 @@ HandleSlashCmds(PsqlSettings *settings,
settings->opt.html3 = settings->opt.expanded = 0; settings->opt.html3 = settings->opt.expanded = 0;
settings->opt.align = settings->opt.header = 1; settings->opt.align = settings->opt.header = 1;
free(settings->opt.fieldSep); free(settings->opt.fieldSep);
settings->opt.fieldSep=dupstr("|"); settings->opt.fieldSep=strdup("|");
if (!settings->quiet) if (!settings->quiet)
fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep); fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep);
} else } else
{ {
free(settings->opt.fieldSep); free(settings->opt.fieldSep);
settings->opt.fieldSep=dupstr(DEFAULT_FIELD_SEP); settings->opt.fieldSep=strdup(DEFAULT_FIELD_SEP);
if (!settings->quiet) if (!settings->quiet)
fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep); fprintf(stderr, "field separater changed to '%s'\n", settings->opt.fieldSep);
} }
...@@ -923,7 +923,7 @@ HandleSlashCmds(PsqlSettings *settings, ...@@ -923,7 +923,7 @@ HandleSlashCmds(PsqlSettings *settings,
if (!optarg) if (!optarg)
settings->opt.tableOpt=NULL; settings->opt.tableOpt=NULL;
else else
if (!(settings->opt.tableOpt=dupstr(optarg))) if (!(settings->opt.tableOpt=strdup(optarg)))
{ {
perror("malloc"); perror("malloc");
exit(1); exit(1);
...@@ -1144,7 +1144,7 @@ main(int argc, char **argv) ...@@ -1144,7 +1144,7 @@ main(int argc, char **argv)
settings.opt.align = 1; settings.opt.align = 1;
settings.opt.header = 1; settings.opt.header = 1;
settings.queryFout = stdout; settings.queryFout = stdout;
settings.opt.fieldSep=dupstr(DEFAULT_FIELD_SEP); settings.opt.fieldSep=strdup(DEFAULT_FIELD_SEP);
settings.opt.pager = 1; settings.opt.pager = 1;
if (!isatty(0) || !isatty(1)) if (!isatty(0) || !isatty(1))
settings.quiet = settings.notty = 1; settings.quiet = settings.notty = 1;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -57,22 +57,6 @@ char *doubleTrim(char *s)
return 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 #ifdef STRINGUTILS_TEST
void testStringUtils() void testStringUtils()
{ {
...@@ -87,13 +71,13 @@ void testStringUtils() ...@@ -87,13 +71,13 @@ void testStringUtils()
while (tests[i]!=NULL_STR) while (tests[i]!=NULL_STR)
{ {
char *t; char *t;
t = dupstr(tests[i]); t = strdup(tests[i]);
printf("leftTrim(%s) = ",t); printf("leftTrim(%s) = ",t);
printf("%sEND\n", leftTrim(t)); printf("%sEND\n", leftTrim(t));
t = dupstr(tests[i]); t = strdup(tests[i]);
printf("rightTrim(%s) = ",t); printf("rightTrim(%s) = ",t);
printf("%sEND\n", rightTrim(t)); printf("%sEND\n", rightTrim(t));
t = dupstr(tests[i]); t = strdup(tests[i]);
printf("doubleTrim(%s) = ",t); printf("doubleTrim(%s) = ",t);
printf("%sEND\n", doubleTrim(t)); printf("%sEND\n", doubleTrim(t));
i++; i++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment