mirror of
https://github.com/curl/curl.git
synced 2024-11-27 05:50:21 +08:00
altsvc: use Curl_fopen()
This commit is contained in:
parent
20f9dd6bae
commit
fab970a5d1
22
lib/altsvc.c
22
lib/altsvc.c
@ -36,7 +36,7 @@
|
||||
#include "parsedate.h"
|
||||
#include "sendf.h"
|
||||
#include "warnless.h"
|
||||
#include "rand.h"
|
||||
#include "fopen.h"
|
||||
#include "rename.h"
|
||||
|
||||
/* The last 3 #include files should be in this order */
|
||||
@ -337,8 +337,7 @@ CURLcode Curl_altsvc_save(struct Curl_easy *data,
|
||||
struct Curl_llist_element *n;
|
||||
CURLcode result = CURLE_OK;
|
||||
FILE *out;
|
||||
char *tempstore;
|
||||
unsigned char randsuffix[9];
|
||||
char *tempstore = NULL;
|
||||
|
||||
if(!altsvc)
|
||||
/* no cache activated */
|
||||
@ -352,17 +351,8 @@ CURLcode Curl_altsvc_save(struct Curl_easy *data,
|
||||
/* marked as read-only, no file or zero length file name */
|
||||
return CURLE_OK;
|
||||
|
||||
if(Curl_rand_hex(data, randsuffix, sizeof(randsuffix)))
|
||||
return CURLE_FAILED_INIT;
|
||||
|
||||
tempstore = aprintf("%s.%s.tmp", file, randsuffix);
|
||||
if(!tempstore)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
out = fopen(tempstore, FOPEN_WRITETEXT);
|
||||
if(!out)
|
||||
result = CURLE_WRITE_ERROR;
|
||||
else {
|
||||
result = Curl_fopen(data, file, &out, &tempstore);
|
||||
if(!result) {
|
||||
fputs("# Your alt-svc cache. https://curl.se/docs/alt-svc.html\n"
|
||||
"# This file was generated by libcurl! Edit at your own risk.\n",
|
||||
out);
|
||||
@ -374,10 +364,10 @@ CURLcode Curl_altsvc_save(struct Curl_easy *data,
|
||||
break;
|
||||
}
|
||||
fclose(out);
|
||||
if(!result && Curl_rename(tempstore, file))
|
||||
if(!result && tempstore && Curl_rename(tempstore, file))
|
||||
result = CURLE_WRITE_ERROR;
|
||||
|
||||
if(result)
|
||||
if(result && tempstore)
|
||||
unlink(tempstore);
|
||||
}
|
||||
free(tempstore);
|
||||
|
Loading…
Reference in New Issue
Block a user