return res;
}
+FILE *curl_dbg_fdopen(int filedes, const char *mode,
+ int line, const char *source)
+{
+ FILE *res = fdopen(filedes, mode);
+ if(source)
+ curl_dbg_log("FILE %s:%d fdopen(\"%d\",\"%s\") = %p\n",
+ source, line, filedes, mode, (void *)res);
+ return res;
+}
+
int curl_dbg_fclose(FILE *file, int line, const char *source)
{
int res;
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
/* FILE functions */
CURL_EXTERN FILE *curl_dbg_fopen(const char *file, const char *mode, int line,
const char *source);
+CURL_EXTERN FILE *curl_dbg_fdopen(int filedes, const char *mode,
+ int line, const char *source);
+
CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
#ifndef MEMDEBUG_NODEFINES
***************************************************************************/
#include "tool_setup.h"
+#ifdef HAVE_FCNTL_H
+/* for open() */
+#include <fcntl.h>
+#endif
+
#define ENABLE_CURLX_PRINTF
/* use our own printf() functions */
#include "curlx.h"
struct OperationConfig *config)
{
struct GlobalConfig *global;
- FILE *file;
+ FILE *file = NULL;
DEBUGASSERT(outs);
DEBUGASSERT(config);
global = config->global;
if(outs->is_cd_filename) {
/* don't overwrite existing files */
- file = fopen(outs->filename, "rb");
- if(file) {
- fclose(file);
- warnf(global, "Refusing to overwrite %s: %s\n", outs->filename,
- strerror(EEXIST));
- return FALSE;
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+ int fd = open(outs->filename, O_CREAT | O_WRONLY | O_EXCL | O_BINARY,
+ S_IRUSR | S_IWUSR
+#ifdef S_IRGRP
+ | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
+#endif
+ );
+ if(fd != -1) {
+ file = fdopen(fd, "wb");
+ if(!file)
+ close(fd);
}
}
+ else
+ /* open file for writing */
+ file = fopen(outs->filename, "wb");
- /* open file for writing */
- file = fopen(outs->filename, "wb");
if(!file) {
warnf(global, "Failed to create the file %s: %s\n", outs->filename,
strerror(errno));