mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 08:56:34 +03:00
Added psycopg_strdup utility function.
This commit is contained in:
parent
a50a91fc7b
commit
ae06fb03e7
|
@ -1,3 +1,7 @@
|
|||
2010-12-15 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||
|
||||
* psycopg/utils.c: Added psycopg_strdup function.
|
||||
|
||||
2010-12-14 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||
|
||||
* psycopg/connection_type.c: No need to put connection fields to zero.
|
||||
|
|
|
@ -120,6 +120,8 @@ HIDDEN void psyco_set_error(PyObject *exc, PyObject *curs, const char *msg,
|
|||
HIDDEN char *psycopg_escape_string(PyObject *conn,
|
||||
const char *from, Py_ssize_t len, char *to, Py_ssize_t *tolen);
|
||||
|
||||
HIDDEN char *psycopg_strdup(const char *from, Py_ssize_t len);
|
||||
|
||||
/* Exceptions docstrings */
|
||||
#define Error_doc \
|
||||
"Base class for error exceptions."
|
||||
|
|
|
@ -70,3 +70,25 @@ psycopg_escape_string(PyObject *obj, const char *from, Py_ssize_t len,
|
|||
|
||||
return to;
|
||||
}
|
||||
|
||||
/* Duplicate a string.
|
||||
*
|
||||
* Allocate a new buffer on the Python heap containing the new string.
|
||||
* 'len' is optional: if 0 the length is calculated.
|
||||
*
|
||||
* Return NULL and set an exception in case of error.
|
||||
*/
|
||||
char *
|
||||
psycopg_strdup(const char *from, Py_ssize_t len)
|
||||
{
|
||||
char *rv;
|
||||
|
||||
if (!len) { len = strlen(from); }
|
||||
if (!(rv = PyMem_Malloc(len + 1))) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
strcpy(rv, from);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user