fopen: optimize

Closes #11419
This commit is contained in:
SaltyMilk 2023-07-10 21:43:28 +02:00 committed by Daniel Stenberg
parent 3b0eb3cd5c
commit 0c667188e0
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -56,13 +56,13 @@ CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,
int fd = -1;
*tempname = NULL;
if(stat(filename, &sb) == -1 || !S_ISREG(sb.st_mode)) {
/* a non-regular file, fallback to direct fopen() */
*fh = fopen(filename, FOPEN_WRITETEXT);
if(*fh)
return CURLE_OK;
*fh = fopen(filename, FOPEN_WRITETEXT);
if(!*fh)
goto fail;
}
if(fstat(fileno(*fh), &sb) == -1 || !S_ISREG(sb.st_mode))
return CURLE_OK;
fclose(*fh);
*fh = NULL;
result = Curl_rand_hex(data, randsuffix, sizeof(randsuffix));
if(result)