Skip to content

Commit ac98fef

Browse files
committed
change mode for fopen w->PG_BINARY_W, r->PG_BINARY_R
1 parent 83d64c5 commit ac98fef

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

src/backup.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static void remote_copy_file(PGconn *conn, pgFile* file)
287287
DATABASE_DIR);
288288
join_path_components(to_path, database_path, file->path);
289289

290-
out = fopen(to_path, "w");
290+
out = fopen(to_path, PG_BINARY_W);
291291
if (out == NULL)
292292
{
293293
int errno_tmp = errno;
@@ -562,6 +562,7 @@ do_backup_instance(void)
562562
#ifdef WIN32
563563
sleep(10);
564564
#endif
565+
565566
if (conn == NULL)
566567
elog(ERROR, "Cannot continue backup because stream connect has failed.");
567568

@@ -1715,7 +1716,7 @@ pg_stop_backup(pgBackup *backup)
17151716

17161717
/* Write backup_label */
17171718
join_path_components(backup_label, path, PG_BACKUP_LABEL_FILE);
1718-
fp = fopen(backup_label, "w");
1719+
fp = fopen(backup_label, PG_BINARY_W);
17191720
if (fp == NULL)
17201721
elog(ERROR, "can't open backup label file \"%s\": %s",
17211722
backup_label, strerror(errno));
@@ -1763,7 +1764,7 @@ pg_stop_backup(pgBackup *backup)
17631764
char tablespace_map[MAXPGPATH];
17641765

17651766
join_path_components(tablespace_map, path, PG_TABLESPACE_MAP_FILE);
1766-
fp = fopen(tablespace_map, "w");
1767+
fp = fopen(tablespace_map, PG_BINARY_W);
17671768
if (fp == NULL)
17681769
elog(ERROR, "can't open tablespace map file \"%s\": %s",
17691770
tablespace_map, strerror(errno));

src/data.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ backup_data_file(backup_files_args* arguments,
421421
INIT_CRC32C(file->crc);
422422

423423
/* open backup mode file for read */
424-
in = fopen(file->path, "r");
424+
in = fopen(file->path, PG_BINARY_R);
425425
if (in == NULL)
426426
{
427427
FIN_CRC32C(file->crc);
@@ -455,7 +455,7 @@ backup_data_file(backup_files_args* arguments,
455455

456456
/* open backup file for write */
457457
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
458-
out = fopen(to_path, "w");
458+
out = fopen(to_path, PG_BINARY_W);
459459
if (out == NULL)
460460
{
461461
int errno_tmp = errno;
@@ -547,7 +547,7 @@ restore_data_file(const char *from_root,
547547
BlockNumber blknum;
548548

549549
/* open backup mode file for read */
550-
in = fopen(file->path, "r");
550+
in = fopen(file->path, PG_BINARY_R);
551551
if (in == NULL)
552552
{
553553
elog(ERROR, "cannot open backup file \"%s\": %s", file->path,
@@ -562,7 +562,7 @@ restore_data_file(const char *from_root,
562562
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
563563
out = fopen(to_path, "r+");
564564
if (out == NULL && errno == ENOENT)
565-
out = fopen(to_path, "w");
565+
out = fopen(to_path, PG_BINARY_W);
566566
if (out == NULL)
567567
{
568568
int errno_tmp = errno;
@@ -694,7 +694,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
694694
file->write_size = 0;
695695

696696
/* open backup mode file for read */
697-
in = fopen(file->path, "r");
697+
in = fopen(file->path, PG_BINARY_R);
698698
if (in == NULL)
699699
{
700700
FIN_CRC32C(crc);
@@ -710,7 +710,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file)
710710

711711
/* open backup file for write */
712712
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
713-
out = fopen(to_path, "w");
713+
out = fopen(to_path, PG_BINARY_W);
714714
if (out == NULL)
715715
{
716716
int errno_tmp = errno;
@@ -1189,7 +1189,7 @@ calc_file_checksum(pgFile *file)
11891189
file->write_size = 0;
11901190

11911191
/* open backup mode file for read */
1192-
in = fopen(file->path, "r");
1192+
in = fopen(file->path, PG_BINARY_R);
11931193
if (in == NULL)
11941194
{
11951195
FIN_CRC32C(crc);

src/dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pgFileGetCRC(pgFile *file)
216216
int errno_tmp;
217217

218218
/* open file in binary read mode */
219-
fp = fopen(file->path, "r");
219+
fp = fopen(file->path, PG_BINARY_R);
220220
if (fp == NULL)
221221
elog(ERROR, "cannot open file \"%s\": %s",
222222
file->path, strerror(errno));
@@ -333,7 +333,7 @@ dir_list_file(parray *files, const char *root, bool exclude, bool omit_symlink,
333333
char black_item[MAXPGPATH * 2];
334334

335335
black_list = parray_new();
336-
black_list_file = fopen(path, "r");
336+
black_list_file = fopen(path, PG_BINARY_R);
337337

338338
if (black_list_file == NULL)
339339
elog(ERROR, "cannot open black_list: %s", strerror(errno));

src/pg_probackup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ main(int argc, char *argv[])
181181
/* Check if backup_path is directory. */
182182
struct stat stat_buf;
183183
int rc;
184-
185184
/* initialize configuration */
186185
pgBackup_init(&current);
187186

188187
PROGRAM_NAME = get_progname(argv[0]);
189188
set_pglocale_pgservice(argv[0], "pgscripts");
190189

190+
191191
/* Parse subcommands and non-subcommand options */
192192
if (argc > 1)
193193
{

src/status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ get_pgpid(void)
3838

3939
snprintf(pid_file, lengthof(pid_file), "%s/postmaster.pid", pgdata);
4040

41-
pidf = fopen(pid_file, "r");
41+
pidf = fopen(pid_file, PG_BINARY_R);
4242
if (pidf == NULL)
4343
{
4444
/* No pid file, not an error on startup */

src/utils/logger.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ open_logfile(FILE **file, const char *filename_format)
515515
{
516516
char buf[1024];
517517

518-
control_file = fopen(control, "r");
518+
control_file = fopen(control, PG_BINARY_R);
519519
if (control_file == NULL)
520520
elog(ERROR, "cannot open rotation file \"%s\": %s",
521521
control, strerror(errno));
@@ -561,7 +561,7 @@ open_logfile(FILE **file, const char *filename_format)
561561
{
562562
time_t timestamp = time(NULL);
563563

564-
control_file = fopen(control, "w");
564+
control_file = fopen(control, PG_BINARY_W);
565565
if (control_file == NULL)
566566
elog(ERROR, "cannot open rotation file \"%s\": %s",
567567
control, strerror(errno));

0 commit comments

Comments
 (0)