Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite9c0528

Browse files
committed
Get rid of perror(), substitute some better phrased error messages.
malloc() doesn't set errno, so most uses were buggy anyway.
1 parent960f545 commite9c0528

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1994, Regents of the University of California
4040
* Portions taken from FreeBSD.
4141
*
42-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.65 2004/10/24 15:55:29 tgl Exp $
42+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.66 2004/11/09 15:57:52 petere Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -2472,7 +2472,8 @@ main(int argc, char *argv[])
24722472

24732473
if (chmod(pg_data,0700)!=0)
24742474
{
2475-
perror(pg_data);
2475+
fprintf(stderr,_("%s: could not change permissions of directory »%s«: %s\n"),
2476+
progname,pg_data,strerror(errno));
24762477
exit_nicely();
24772478
}
24782479
else
@@ -2493,7 +2494,8 @@ main(int argc, char *argv[])
24932494

24942495
default:
24952496
/* Trouble accessing directory */
2496-
perror(pg_data);
2497+
fprintf(stderr,_("%s: could not access directory »%s«: %s\n"),
2498+
progname,pg_data,strerror(errno));
24972499
exit_nicely();
24982500
}
24992501

‎src/bin/psql/print.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2004, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.52 2004/09/27 23:24:35 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.53 2004/11/09 15:57:53 petere Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"common.h"
@@ -227,14 +227,14 @@ print_aligned_text(const char *title, const char *const * headers,
227227
widths=calloc(col_count,sizeof(*widths));
228228
if (!widths)
229229
{
230-
perror("calloc");
230+
fprintf(stderr,gettext("out of memory\n"));
231231
exit(EXIT_FAILURE);
232232
}
233233

234234
head_w=calloc(col_count,sizeof(*head_w));
235235
if (!head_w)
236236
{
237-
perror("calloc");
237+
fprintf(stderr,gettext("out of memory\n"));
238238
exit(EXIT_FAILURE);
239239
}
240240
}
@@ -253,7 +253,7 @@ print_aligned_text(const char *title, const char *const * headers,
253253
cell_w=calloc(cell_count,sizeof(*cell_w));
254254
if (!cell_w)
255255
{
256-
perror("calloc");
256+
fprintf(stderr,gettext("out of memory\n"));
257257
exit(EXIT_FAILURE);
258258
}
259259
}
@@ -437,7 +437,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
437437
head_w=calloc(col_count,sizeof(*head_w));
438438
if (!head_w)
439439
{
440-
perror("calloc");
440+
fprintf(stderr,gettext("out of memory\n"));
441441
exit(EXIT_FAILURE);
442442
}
443443
}
@@ -461,7 +461,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
461461
cell_w=calloc(cell_count,sizeof(*cell_w));
462462
if (!cell_w)
463463
{
464-
perror("calloc");
464+
fprintf(stderr,gettext("out of memory\n"));
465465
exit(EXIT_FAILURE);
466466
}
467467
}
@@ -485,7 +485,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
485485
divider=malloc(hwidth+dwidth+10);
486486
if (!divider)
487487
{
488-
perror("malloc");
488+
fprintf(stderr,gettext("out of memory\n"));
489489
exit(EXIT_FAILURE);
490490
}
491491
divider[0]='\0';
@@ -514,7 +514,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
514514

515515
if (!record_str)
516516
{
517-
perror("malloc");
517+
fprintf(stderr,gettext("out of memory\n"));
518518
exit(EXIT_FAILURE);
519519
}
520520

@@ -532,7 +532,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
532532

533533
if (!div_copy)
534534
{
535-
perror("malloc");
535+
fprintf(stderr,gettext("out of memory\n"));
536536
exit(EXIT_FAILURE);
537537
}
538538

@@ -1153,7 +1153,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11531153
headers=calloc(nfields+1,sizeof(*headers));
11541154
if (!headers)
11551155
{
1156-
perror("calloc");
1156+
fprintf(stderr,gettext("out of memory\n"));
11571157
exit(EXIT_FAILURE);
11581158
}
11591159

@@ -1165,7 +1165,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11651165
cells=calloc(ncells+1,sizeof(*cells));
11661166
if (!cells)
11671167
{
1168-
perror("calloc");
1168+
fprintf(stderr,gettext("out of memory\n"));
11691169
exit(EXIT_FAILURE);
11701170
}
11711171

@@ -1186,14 +1186,14 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11861186
footers=calloc(2,sizeof(*footers));
11871187
if (!footers)
11881188
{
1189-
perror("calloc");
1189+
fprintf(stderr,gettext("out of memory\n"));
11901190
exit(EXIT_FAILURE);
11911191
}
11921192

11931193
footers[0]=malloc(100);
11941194
if (!footers[0])
11951195
{
1196-
perror("malloc");
1196+
fprintf(stderr,gettext("out of memory\n"));
11971197
exit(EXIT_FAILURE);
11981198
}
11991199
if (PQntuples(result)==1)
@@ -1208,7 +1208,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
12081208
align=calloc(nfields+1,sizeof(*align));
12091209
if (!align)
12101210
{
1211-
perror("calloc");
1211+
fprintf(stderr,gettext("out of memory\n"));
12121212
exit(EXIT_FAILURE);
12131213
}
12141214

‎src/bin/scripts/common.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.12 2004/10/16 03:10:16 momjian Exp $
8+
* $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.13 2004/11/09 15:57:54 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -30,7 +30,8 @@ get_user_name(const char *progname)
3030
pw=getpwuid(getuid());
3131
if (!pw)
3232
{
33-
perror(progname);
33+
fprintf(stderr,_("%s: could not obtain information about current user: %s"),
34+
progname,strerror(errno));
3435
exit(1);
3536
}
3637
returnpw->pw_name;
@@ -40,7 +41,8 @@ get_user_name(const char *progname)
4041

4142
if (!GetUserName(username,&len))
4243
{
43-
perror(progname);
44+
fprintf(stderr,_("%s: could not get current user name: %s"),
45+
progname,strerror(errno));
4446
exit(1);
4547
}
4648
returnusername;

‎src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.90 2004/08/29 05:07:00 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.91 2004/11/09 15:57:55 petere Exp $ */
22

33
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
44
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -154,7 +154,8 @@ main(int argc, char *const argv[])
154154
yyout=fopen(optarg,PG_BINARY_W);
155155

156156
if (yyout==NULL)
157-
perror(optarg);
157+
fprintf(stderr,"%s: could not open file \"%s\": %s\n",
158+
progname,optarg,strerror(errno));
158159
else
159160
out_option=1;
160161
break;
@@ -304,7 +305,8 @@ main(int argc, char *const argv[])
304305
yyout=fopen(output_filename,PG_BINARY_W);
305306
if (yyout==NULL)
306307
{
307-
perror(output_filename);
308+
fprintf(stderr,"%s: could not open file \"%s\": %s\n",
309+
progname,output_filename,strerror(errno));
308310
free(output_filename);
309311
free(input_filename);
310312
continue;
@@ -313,7 +315,8 @@ main(int argc, char *const argv[])
313315
}
314316

315317
if (yyin==NULL)
316-
perror(argv[fnr]);
318+
fprintf(stderr,"%s: could not open file \"%s\": %s\n",
319+
progname,argv[fnr],strerror(errno));
317320
else
318321
{
319322
structcursor*ptr;

‎src/interfaces/libpq/fe-auth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.94 2004/10/16 03:10:17 momjian Exp $
13+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.95 2004/11/09 15:57:57 petere Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -527,7 +527,7 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
527527
if (!(crypt_pwd=malloc(MD5_PASSWD_LEN+1))||
528528
!(crypt_pwd2=malloc(MD5_PASSWD_LEN+1)))
529529
{
530-
perror("malloc");
530+
fprintf(stderr,libpq_gettext("out of memory\n"));
531531
returnSTATUS_ERROR;
532532
}
533533
if (!EncryptMD5(password,conn->pguser,

‎src/interfaces/libpq/fe-print.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* didn't really belong there.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.54 2004/08/29 05:07:00 momjian Exp $
13+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-print.c,v 1.55 2004/11/09 15:57:57 petere Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -110,17 +110,17 @@ PQprint(FILE *fout,
110110
nTups=PQntuples(res);
111111
if (!(fieldNames= (constchar**)calloc(nFields,sizeof(char*))))
112112
{
113-
perror("calloc");
113+
fprintf(stderr,libpq_gettext("out of memory\n"));
114114
exit(1);
115115
}
116116
if (!(fieldNotNum= (unsignedchar*)calloc(nFields,1)))
117117
{
118-
perror("calloc");
118+
fprintf(stderr,libpq_gettext("out of memory\n"));
119119
exit(1);
120120
}
121121
if (!(fieldMax= (int*)calloc(nFields,sizeof(int))))
122122
{
123-
perror("calloc");
123+
fprintf(stderr,libpq_gettext("out of memory\n"));
124124
exit(1);
125125
}
126126
for (numFieldName=0;
@@ -205,7 +205,7 @@ PQprint(FILE *fout,
205205
{
206206
if (!(fields= (char**)calloc(nFields* (nTups+1),sizeof(char*))))
207207
{
208-
perror("calloc");
208+
fprintf(stderr,libpq_gettext("out of memory\n"));
209209
exit(1);
210210
}
211211
}
@@ -392,7 +392,7 @@ do_field(const PQprintOpt *po, const PGresult *res,
392392
fieldMax[j]=plen;
393393
if (!(fields[i*nFields+j]= (char*)malloc(plen+1)))
394394
{
395-
perror("malloc");
395+
fprintf(stderr,libpq_gettext("out of memory\n"));
396396
exit(1);
397397
}
398398
strcpy(fields[i*nFields+j],pval);
@@ -463,7 +463,7 @@ do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax,
463463
border=malloc(tot+1);
464464
if (!border)
465465
{
466-
perror("malloc");
466+
fprintf(stderr,libpq_gettext("out of memory\n"));
467467
exit(1);
468468
}
469469
p=border;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp