]> git.sur5r.net Git - bacula/bacula/commitdiff
use bstrncpy instead of strcpy. Simlarly for bstrncat.
authorDan Langille <dan@langille.org>
Thu, 18 Dec 2003 17:04:33 +0000 (17:04 +0000)
committerDan Langille <dan@langille.org>
Thu, 18 Dec 2003 17:04:33 +0000 (17:04 +0000)
Alter my_postgresql_currval to take a table name.

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@893 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/cats/postgresql.c

index 41f7b635729243311e95c15efdf9dce82742b009..375be429fc1c52fe7f2030c5c20b49f1c44c22e3 100644 (file)
@@ -524,7 +524,7 @@ void my_postgresql_free_result (B_DB *mdb) {
        }
 }
 
-int my_postgresql_currval(B_DB *mdb) {
+int my_postgresql_currval(B_DB *mdb, char *table_name) {
        // Obtain the current value of the sequence that
        // provides the serial value for primary key of the table.
 
@@ -547,16 +547,16 @@ int my_postgresql_currval(B_DB *mdb) {
        PGresult *result;
        int       id = 0;
 
-       if (strcasecmp(mdb->table_name, "basefiles") == 0) {
-               strcpy(sequence, "basefiles_baseid");
+       if (strcasecmp(table_name, "basefiles") == 0) {
+               bstrncpy(sequence, "basefiles_baseid", sizeof(sequence));
        } else {
-               strcpy(sequence, mdb->table_name);
-               strcat(sequence, "_");
-               strcat(sequence, mdb->table_name);
-               strcat(sequence, "id");
+               bstrncpy(sequence, table_name, sizeof(sequence));
+               bstrncat(sequence, "_",        sizeof(sequence));
+               bstrncat(sequence, table_name, sizeof(sequence));
+               bstrncat(sequence, "id",       sizeof(sequence));
        }
 
-       strcat(sequence, "_seq");
+       bstrncat(sequence, "_seq", sizeof(sequence));
        bsnprintf(query, sizeof(query), "SELECT currval('%s')", sequence);
 
 //     Mmsg(&query, "SELECT currval('%s')", sequence);