8000 Fix potentially-unportable code in contrib/adminpack. · MSPawanRanjith/postgres@9ed1c8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ed1c8c

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 bbec33c commit 9ed1c8c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

contrib/adminpack/adminpack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pg_file_rename(PG_FUNCTION_ARGS)
178178
fn1 = convert_and_check_filename(PG_GETARG_TEXT_P(0), false);
179179
fn2 = convert_and_check_filename(PG_GETARG_TEXT_P(1), false);
180180
if (PG_ARGISNULL(2))
181-
fn3 = 0;
181+
fn3 = NULL;
182182
else
183183
fn3 = convert_and_check_filename(PG_GETARG_TEXT_P(2), false);
184184

@@ -200,7 +200,7 @@ pg_file_rename(PG_FUNCTION_ARGS)
200200
PG_RETURN_BOOL(false);
201201
}
202202

203-
rc = access(fn3 ? fn3 : fn2, 2);
203+
rc = access(fn3 ? fn3 : fn2, W_OK);
204204
if (rc >= 0 || errno != ENOENT)
205205
{
206206
ereport(ERROR,

0 commit comments

Comments
 (0)
0