Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3a2d636

Browse files
committed
Fix potentially-unportable code in contrib/adminpack.
Spelling access(2)'s second argument as "2" is just horrid. POSIX makes no promises as to the numeric values of W_OK and related macros. Even if it accidentally works as intended on every supported platform, it's still unreadable and inconsistent with adjacent code. In passing, don't spell "NULL" as "0" either. Yes, that's legal C; no, it's not project style. Back-patch, just in case the unportability is real and not theoretical. (Most likely, even if a platform had different bit assignments for access()'s modes, there'd not be an observable behavior difference here; but I'm being paranoid today.)
1 parent f8a187b commit 3a2d636

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

contrib/adminpack/adminpack.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ pg_file_rename_internal(text *file1, text *file2, text *file3)
298298
fn2 = convert_and_check_filename(file2, false);
299299

300300
if (file3 == NULL)
301-
fn3 = 0;
301+
fn3 = NULL;
302302
else
303303
fn3 = convert_and_check_filename(file3, false);
304304

@@ -320,7 +320,7 @@ pg_file_rename_internal(text *file1, text *file2, text *file3)
320320
return false;
321321
}
322322

323-
rc = access(fn3 ? fn3 : fn2, 2);
323+
rc = access(fn3 ? fn3 : fn2, W_OK);
324324
if (rc >= 0 || errno != ENOENT)
325325
{
326326
ereport(ERROR,

0 commit comments

Comments
 (0)