This commit is contained in:
Tess Gauthier 2024-11-18 11:14:16 -05:00
parent f6981a5dbd
commit a7b6aff348

View File

@ -513,13 +513,15 @@ sshkey_save_public(const struct sshkey *key, const char *path,
FILE *f = NULL;
int r = SSH_ERR_INTERNAL_ERROR;
#ifdef WINDOWS
/* Windows POSIX adapter does not support fdopen() on open(file)*/
if ((f = fopen(path, "w")) == NULL)
return SSH_ERR_SYSTEM_ERROR;
#else /* !WINDOWS */
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1)
return SSH_ERR_SYSTEM_ERROR;
#ifdef WINDOWS
/* Windows POSIX adapter does not support fdopen() on open(file)
but still want to create file with 0644 permissions */
close(fd);
if ((f = fopen(path, "w")) == NULL)
return SSH_ERR_SYSTEM_ERROR;
#else /* WINDOWS */
if ((f = fdopen(fd, "w")) == NULL) {
r = SSH_ERR_SYSTEM_ERROR;
close(fd);