Remove a couple of strerror() calls

Change to using %m in the error message string.  We need to be a bit
careful here to preserve errno until we need to print it.

This change avoids the use of not-thread-safe strerror() and unifies
some error message strings, and maybe makes the code appear more
consistent.

Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/daa87d79-c044-46c4-8458-8d77241ed7b0%40eisentraut.org
This commit is contained in:
Peter Eisentraut 2024-09-04 14:45:31 +02:00
parent a68159ff2b
commit 82b07eba9e
1 changed files with 8 additions and 4 deletions

View File

@ -624,8 +624,11 @@ open_auth_file(const char *filename, int elevel, int depth,
errmsg("could not open file \"%s\": %m", errmsg("could not open file \"%s\": %m",
filename))); filename)));
if (err_msg) if (err_msg)
*err_msg = psprintf("could not open file \"%s\": %s", {
filename, strerror(save_errno)); errno = save_errno;
*err_msg = psprintf("could not open file \"%s\": %m",
filename);
}
/* the caller may care about some specific errno */ /* the caller may care about some specific errno */
errno = save_errno; errno = save_errno;
return NULL; return NULL;
@ -762,8 +765,9 @@ tokenize_auth_file(const char *filename, FILE *file, List **tok_lines,
ereport(elevel, ereport(elevel,
(errcode_for_file_access(), (errcode_for_file_access(),
errmsg("could not read file \"%s\": %m", filename))); errmsg("could not read file \"%s\": %m", filename)));
err_msg = psprintf("could not read file \"%s\": %s", errno = save_errno;
filename, strerror(save_errno)); err_msg = psprintf("could not read file \"%s\": %m",
filename);
break; break;
} }