1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* common.c
|
2011-11-25 21:40:51 +01:00
|
|
|
* common routines between pg_dump and pg_restore (but not pg_dumpall
|
|
|
|
* because there is no failure location to report).
|
2002-05-11 00:36:27 +02:00
|
|
|
*
|
2011-01-01 19:18:15 +01:00
|
|
|
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/bin/pg_dump/common.c
|
2000-09-15 06:35:16 +02:00
|
|
|
*
|
1996-07-09 08:22:35 +02:00
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2001-06-27 23:21:37 +02:00
|
|
|
#include "postgres_fe.h"
|
2011-11-25 21:40:51 +01:00
|
|
|
#include "pg_backup.h"
|
|
|
|
#include "common.h"
|
2003-12-08 17:39:05 +01:00
|
|
|
|
2008-03-27 04:57:34 +01:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2006-10-10 01:36:59 +02:00
|
|
|
/*
|
|
|
|
* Safer versions of some standard C library functions. If an
|
|
|
|
* out-of-memory condition occurs, these functions will bail out
|
|
|
|
* safely; therefore, their return value is guaranteed to be non-NULL.
|
2011-11-25 21:40:51 +01:00
|
|
|
* We also report the program name and close the database connection.
|
2006-10-10 01:36:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
char *
|
|
|
|
pg_strdup(const char *string)
|
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (!string)
|
|
|
|
exit_horribly(NULL, NULL, "cannot duplicate null pointer\n");
|
|
|
|
tmp = strdup(string);
|
|
|
|
if (!tmp)
|
|
|
|
exit_horribly(NULL, NULL, "out of memory\n");
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pg_malloc(size_t size)
|
|
|
|
{
|
|
|
|
void *tmp;
|
|
|
|
|
|
|
|
tmp = malloc(size);
|
|
|
|
if (!tmp)
|
|
|
|
exit_horribly(NULL, NULL, "out of memory\n");
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pg_calloc(size_t nmemb, size_t size)
|
|
|
|
{
|
|
|
|
void *tmp;
|
|
|
|
|
|
|
|
tmp = calloc(nmemb, size);
|
|
|
|
if (!tmp)
|
2011-11-25 21:40:51 +01:00
|
|
|
exit_horribly(NULL, NULL, _("out of memory\n"));
|
2006-10-10 01:36:59 +02:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
pg_realloc(void *ptr, size_t size)
|
|
|
|
{
|
|
|
|
void *tmp;
|
|
|
|
|
|
|
|
tmp = realloc(ptr, size);
|
|
|
|
if (!tmp)
|
2011-11-25 21:40:51 +01:00
|
|
|
exit_horribly(NULL, NULL, _("out of memory\n"));
|
2006-10-10 01:36:59 +02:00
|
|
|
return tmp;
|
|
|
|
}
|