mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Get rid of perror(), substitute some better phrased error messages.
malloc() doesn't set errno, so most uses were buggy anyway.
This commit is contained in:
@ -39,7 +39,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
* Portions taken from FreeBSD.
|
* Portions taken from FreeBSD.
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.65 2004/10/24 15:55:29 tgl Exp $
|
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.66 2004/11/09 15:57:52 petere Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2472,7 +2472,8 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (chmod(pg_data, 0700) != 0)
|
if (chmod(pg_data, 0700) != 0)
|
||||||
{
|
{
|
||||||
perror(pg_data);
|
fprintf(stderr, _("%s: could not change permissions of directory <20>%s<>: %s\n"),
|
||||||
|
progname, pg_data, strerror(errno));
|
||||||
exit_nicely();
|
exit_nicely();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2493,7 +2494,8 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
/* Trouble accessing directory */
|
/* Trouble accessing directory */
|
||||||
perror(pg_data);
|
fprintf(stderr, _("%s: could not access directory <20>%s<>: %s\n"),
|
||||||
|
progname, pg_data, strerror(errno));
|
||||||
exit_nicely();
|
exit_nicely();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
|
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.52 2004/09/27 23:24:35 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.53 2004/11/09 15:57:53 petere Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -227,14 +227,14 @@ print_aligned_text(const char *title, const char *const * headers,
|
|||||||
widths = calloc(col_count, sizeof(*widths));
|
widths = calloc(col_count, sizeof(*widths));
|
||||||
if (!widths)
|
if (!widths)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
head_w = calloc(col_count, sizeof(*head_w));
|
head_w = calloc(col_count, sizeof(*head_w));
|
||||||
if (!head_w)
|
if (!head_w)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,7 +253,7 @@ print_aligned_text(const char *title, const char *const * headers,
|
|||||||
cell_w = calloc(cell_count, sizeof(*cell_w));
|
cell_w = calloc(cell_count, sizeof(*cell_w));
|
||||||
if (!cell_w)
|
if (!cell_w)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -437,7 +437,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
|
|||||||
head_w = calloc(col_count, sizeof(*head_w));
|
head_w = calloc(col_count, sizeof(*head_w));
|
||||||
if (!head_w)
|
if (!head_w)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,7 +461,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
|
|||||||
cell_w = calloc(cell_count, sizeof(*cell_w));
|
cell_w = calloc(cell_count, sizeof(*cell_w));
|
||||||
if (!cell_w)
|
if (!cell_w)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -485,7 +485,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
|
|||||||
divider = malloc(hwidth + dwidth + 10);
|
divider = malloc(hwidth + dwidth + 10);
|
||||||
if (!divider)
|
if (!divider)
|
||||||
{
|
{
|
||||||
perror("malloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
divider[0] = '\0';
|
divider[0] = '\0';
|
||||||
@ -514,7 +514,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
|
|||||||
|
|
||||||
if (!record_str)
|
if (!record_str)
|
||||||
{
|
{
|
||||||
perror("malloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -532,7 +532,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
|
|||||||
|
|
||||||
if (!div_copy)
|
if (!div_copy)
|
||||||
{
|
{
|
||||||
perror("malloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1153,7 +1153,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
|
|||||||
headers = calloc(nfields + 1, sizeof(*headers));
|
headers = calloc(nfields + 1, sizeof(*headers));
|
||||||
if (!headers)
|
if (!headers)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1165,7 +1165,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
|
|||||||
cells = calloc(ncells + 1, sizeof(*cells));
|
cells = calloc(ncells + 1, sizeof(*cells));
|
||||||
if (!cells)
|
if (!cells)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1186,14 +1186,14 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
|
|||||||
footers = calloc(2, sizeof(*footers));
|
footers = calloc(2, sizeof(*footers));
|
||||||
if (!footers)
|
if (!footers)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
footers[0] = malloc(100);
|
footers[0] = malloc(100);
|
||||||
if (!footers[0])
|
if (!footers[0])
|
||||||
{
|
{
|
||||||
perror("malloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (PQntuples(result) == 1)
|
if (PQntuples(result) == 1)
|
||||||
@ -1208,7 +1208,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
|
|||||||
align = calloc(nfields + 1, sizeof(*align));
|
align = calloc(nfields + 1, sizeof(*align));
|
||||||
if (!align)
|
if (!align)
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, gettext("out of memory\n"));
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.12 2004/10/16 03:10:16 momjian Exp $
|
* $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.13 2004/11/09 15:57:54 petere Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -30,7 +30,8 @@ get_user_name(const char *progname)
|
|||||||
pw = getpwuid(getuid());
|
pw = getpwuid(getuid());
|
||||||
if (!pw)
|
if (!pw)
|
||||||
{
|
{
|
||||||
perror(progname);
|
fprintf(stderr, _("%s: could not obtain information about current user: %s"),
|
||||||
|
progname, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return pw->pw_name;
|
return pw->pw_name;
|
||||||
@ -40,7 +41,8 @@ get_user_name(const char *progname)
|
|||||||
|
|
||||||
if (!GetUserName(username, &len))
|
if (!GetUserName(username, &len))
|
||||||
{
|
{
|
||||||
perror(progname);
|
fprintf(stderr, _("%s: could not get current user name: %s"),
|
||||||
|
progname, strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return username;
|
return username;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.90 2004/08/29 05:07:00 momjian Exp $ */
|
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.91 2004/11/09 15:57:55 petere Exp $ */
|
||||||
|
|
||||||
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
|
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
|
||||||
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
|
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
|
||||||
@ -154,7 +154,8 @@ main(int argc, char *const argv[])
|
|||||||
yyout = fopen(optarg, PG_BINARY_W);
|
yyout = fopen(optarg, PG_BINARY_W);
|
||||||
|
|
||||||
if (yyout == NULL)
|
if (yyout == NULL)
|
||||||
perror(optarg);
|
fprintf(stderr, "%s: could not open file \"%s\": %s\n",
|
||||||
|
progname, optarg, strerror(errno));
|
||||||
else
|
else
|
||||||
out_option = 1;
|
out_option = 1;
|
||||||
break;
|
break;
|
||||||
@ -304,7 +305,8 @@ main(int argc, char *const argv[])
|
|||||||
yyout = fopen(output_filename, PG_BINARY_W);
|
yyout = fopen(output_filename, PG_BINARY_W);
|
||||||
if (yyout == NULL)
|
if (yyout == NULL)
|
||||||
{
|
{
|
||||||
perror(output_filename);
|
fprintf(stderr, "%s: could not open file \"%s\": %s\n",
|
||||||
|
progname, output_filename, strerror(errno));
|
||||||
free(output_filename);
|
free(output_filename);
|
||||||
free(input_filename);
|
free(input_filename);
|
||||||
continue;
|
continue;
|
||||||
@ -313,7 +315,8 @@ main(int argc, char *const argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (yyin == NULL)
|
if (yyin == NULL)
|
||||||
perror(argv[fnr]);
|
fprintf(stderr, "%s: could not open file \"%s\": %s\n",
|
||||||
|
progname, argv[fnr], strerror(errno));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct cursor *ptr;
|
struct cursor *ptr;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
|
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.94 2004/10/16 03:10:17 momjian Exp $
|
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.95 2004/11/09 15:57:57 petere Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -527,7 +527,7 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
|
|||||||
if (!(crypt_pwd = malloc(MD5_PASSWD_LEN + 1)) ||
|
if (!(crypt_pwd = malloc(MD5_PASSWD_LEN + 1)) ||
|
||||||
!(crypt_pwd2 = malloc(MD5_PASSWD_LEN + 1)))
|
!(crypt_pwd2 = malloc(MD5_PASSWD_LEN + 1)))
|
||||||
{
|
{
|
||||||
perror("malloc");
|
fprintf(stderr, libpq_gettext("out of memory\n"));
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
}
|
}
|
||||||
if (!EncryptMD5(password, conn->pguser,
|
if (!EncryptMD5(password, conn->pguser,
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* didn't really belong there.
|
* didn't really belong there.
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.54 2004/08/29 05:07:00 momjian Exp $
|
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.55 2004/11/09 15:57:57 petere Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -110,17 +110,17 @@ PQprint(FILE *fout,
|
|||||||
nTups = PQntuples(res);
|
nTups = PQntuples(res);
|
||||||
if (!(fieldNames = (const char **) calloc(nFields, sizeof(char *))))
|
if (!(fieldNames = (const char **) calloc(nFields, sizeof(char *))))
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, libpq_gettext("out of memory\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!(fieldNotNum = (unsigned char *) calloc(nFields, 1)))
|
if (!(fieldNotNum = (unsigned char *) calloc(nFields, 1)))
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, libpq_gettext("out of memory\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (!(fieldMax = (int *) calloc(nFields, sizeof(int))))
|
if (!(fieldMax = (int *) calloc(nFields, sizeof(int))))
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, libpq_gettext("out of memory\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
for (numFieldName = 0;
|
for (numFieldName = 0;
|
||||||
@ -205,7 +205,7 @@ PQprint(FILE *fout,
|
|||||||
{
|
{
|
||||||
if (!(fields = (char **) calloc(nFields * (nTups + 1), sizeof(char *))))
|
if (!(fields = (char **) calloc(nFields * (nTups + 1), sizeof(char *))))
|
||||||
{
|
{
|
||||||
perror("calloc");
|
fprintf(stderr, libpq_gettext("out of memory\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -392,7 +392,7 @@ do_field(const PQprintOpt *po, const PGresult *res,
|
|||||||
fieldMax[j] = plen;
|
fieldMax[j] = plen;
|
||||||
if (!(fields[i * nFields + j] = (char *) malloc(plen + 1)))
|
if (!(fields[i * nFields + j] = (char *) malloc(plen + 1)))
|
||||||
{
|
{
|
||||||
perror("malloc");
|
fprintf(stderr, libpq_gettext("out of memory\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
strcpy(fields[i * nFields + j], pval);
|
strcpy(fields[i * nFields + j], pval);
|
||||||
@ -463,7 +463,7 @@ do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax,
|
|||||||
border = malloc(tot + 1);
|
border = malloc(tot + 1);
|
||||||
if (!border)
|
if (!border)
|
||||||
{
|
{
|
||||||
perror("malloc");
|
fprintf(stderr, libpq_gettext("out of memory\n"));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
p = border;
|
p = border;
|
||||||
|
Reference in New Issue
Block a user