elsif($syn == 1) {
if(/^~~~/) {
$syn++;
- print O "/* !checksrc! disable UNUSEDIGNORE all */\n";
+ print O "/* !checksrc! disable BANNEDFUNC all */\n"; # for fopen()
print O "/* !checksrc! disable COPYRIGHT all */\n";
- print O "/* !checksrc! disable FOPENMODE all */\n";
+ print O "/* !checksrc! disable UNUSEDIGNORE all */\n";
printf O "#line %d \"$f\"\n", $iline+1;
}
}
+allowfunc fclose
+allowfunc fdopen
+allowfunc fopen
allowfunc gmtime
allowfunc localtime
allowfunc socket
- `EXCLAMATIONSPACE`: space found after exclamations mark
-- `FOPENMODE`: `fopen()` needs a macro for the mode string, use it
+- `FOPENMODE`: `curlx_fopen()` needs a macro for the mode string, use it
- `INDENTATION`: detected a wrong start column for code. Note that this
warning only checks some specific places and can certainly miss many bad
LIB_CURLX_CFILES = \
curlx/base64.c \
curlx/dynbuf.c \
+ curlx/fopen.c \
curlx/inet_ntop.c \
curlx/inet_pton.c \
curlx/multibyte.c \
curlx/base64.h \
curlx/curlx.h \
curlx/dynbuf.h \
+ curlx/fopen.h \
curlx/inet_ntop.h \
curlx/inet_pton.h \
curlx/multibyte.h \
curl_des.c \
curl_endian.c \
curl_fnmatch.c \
+ curl_fopen.c \
curl_get_line.c \
curl_gethostname.c \
curl_gssapi.c \
fake_addrinfo.c \
file.c \
fileinfo.c \
- fopen.c \
formdata.c \
ftp.c \
ftplistparser.c \
curl_des.h \
curl_endian.h \
curl_fnmatch.h \
+ curl_fopen.h \
curl_get_line.h \
curl_gethostname.h \
curl_gssapi.h \
fake_addrinfo.h \
file.h \
fileinfo.h \
- fopen.h \
formdata.h \
ftp.h \
ftplistparser.h \
#include <curl/curl.h>
#include "urldata.h"
#include "altsvc.h"
+#include "curl_fopen.h"
#include "curl_get_line.h"
#include "parsedate.h"
#include "sendf.h"
#include "curlx/warnless.h"
-#include "fopen.h"
#include "rename.h"
#include "strdup.h"
#include "curlx/inet_pton.h"
if(!asi->filename)
return CURLE_OUT_OF_MEMORY;
- fp = fopen(file, FOPEN_READTEXT);
+ fp = curlx_fopen(file, FOPEN_READTEXT);
if(fp) {
struct dynbuf buf;
curlx_dyn_init(&buf, MAX_ALTSVC_LINE);
altsvc_add(asi, lineptr);
}
curlx_dyn_free(&buf); /* free the line buffer */
- fclose(fp);
+ curlx_fclose(fp);
}
return result;
}
if(result)
break;
}
- fclose(out);
+ curlx_fclose(out);
if(!result && tempstore && Curl_rename(tempstore, file))
result = CURLE_WRITE_ERROR;
#include "slist.h"
#include "share.h"
#include "strcase.h"
+#include "curl_fopen.h"
#include "curl_get_line.h"
#include "curl_memrchr.h"
#include "parsedate.h"
#include "rename.h"
-#include "fopen.h"
#include "strdup.h"
#include "llist.h"
#include "curlx/strparse.h"
if(!strcmp(file, "-"))
fp = stdin;
else {
- fp = fopen(file, "rb");
+ fp = curlx_fopen(file, "rb");
if(!fp)
infof(data, "WARNING: failed to open cookie file \"%s\"", file);
else
remove_expired(ci);
if(handle)
- fclose(handle);
+ curlx_fclose(handle);
}
data->state.cookie_engine = TRUE;
}
}
if(!use_stdout) {
- fclose(out);
+ curlx_fclose(out);
out = NULL;
if(tempstore && Curl_rename(tempstore, filename)) {
unlink(tempstore);
error:
if(out && !use_stdout)
- fclose(out);
+ curlx_fclose(out);
free(tempstore);
return error;
}
#include "urldata.h"
#include "rand.h"
-#include "fopen.h"
+#include "curl_fopen.h"
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
#include "curl_memory.h"
char *dir = NULL;
*tempname = NULL;
- *fh = fopen(filename, FOPEN_WRITETEXT);
+ *fh = curlx_fopen(filename, FOPEN_WRITETEXT);
if(!*fh)
goto fail;
if(
|| !S_ISREG(sb.st_mode)) {
return CURLE_OK;
}
- fclose(*fh);
+ curlx_fclose(*fh);
*fh = NULL;
result = Curl_rand_alnum(data, randbuf, sizeof(randbuf));
if(fd == -1)
goto fail;
- *fh = fdopen(fd, FOPEN_WRITETEXT);
+ *fh = curlx_fdopen(fd, FOPEN_WRITETEXT);
if(!*fh)
goto fail;
*
***************************************************************************/
+#include "curlx/fopen.h"
+
CURLcode Curl_fopen(struct Curl_easy *data, const char *filename,
FILE **fh, char **tempname);
#undef Curl_tcsdup
#endif
-#ifdef CURLDEBUG
-
-#undef fopen
-#ifdef CURL_FOPEN
-#define fopen(fname, mode) CURL_FOPEN(fname, mode)
-#endif
-#undef fdopen
-#undef fclose
-
-#endif /* CURLDEBUG */
-
#undef HEADER_CURL_MEMORY_H
#undef HEADER_CURL_MEMDEBUG_H
# ifndef UNDER_CE
int curlx_win32_stat(const char *path, struct_stat *buffer);
int curlx_win32_open(const char *filename, int oflag, ...);
- FILE *curlx_win32_fopen(const char *filename, const char *mode);
# define stat(fname, stp) curlx_win32_stat(fname, stp)
# define open curlx_win32_open
-# define CURL_FOPEN(fname, mode) curlx_win32_fopen(fname, mode)
-# define fopen(fname, mode) CURL_FOPEN(fname, mode)
# endif
#elif defined(__DJGPP__)
/* Requires DJGPP 2.04 */
#include "dynbuf.h"
/* The curlx_dyn_* functions */
+#include "fopen.h"
+/* The curlx_f* functions */
+
#include "base64.h"
#include "timeval.h"
#include "timediff.h"
--- /dev/null
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 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
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+
+/*
+ * This file is 'mem-include-scan' clean, which means its memory allocations
+ * are not tracked by the curl memory tracker memdebug, so they must not use
+ * `CURLDEBUG` macro replacements in memdebug.h for free, malloc, etc. To avoid
+ * these macro replacements, wrap the names in parentheses to call the original
+ * versions: `ptr = (malloc)(123)`, `(free)(ptr)`, etc.
+ */
+
+#include "../curl_setup.h"
+
+#if defined(_WIN32) && !defined(UNDER_CE)
+
+#include "fopen.h"
+#include "multibyte.h"
+
+/* declare GetFullPathNameW for mingw-w64 UWP builds targeting old windows */
+#if defined(CURL_WINDOWS_UWP) && defined(__MINGW32__) && \
+ (_WIN32_WINNT < _WIN32_WINNT_WIN10)
+WINBASEAPI DWORD WINAPI GetFullPathNameW(LPCWSTR, DWORD, LPWSTR, LPWSTR *);
+#endif
+
+/* Fix excessive paths (paths that exceed MAX_PATH length of 260).
+ *
+ * This is a helper function to fix paths that would exceed the MAX_PATH
+ * limitation check done by Windows APIs. It does so by normalizing the passed
+ * in filename or path 'in' to its full canonical path, and if that path is
+ * longer than MAX_PATH then setting 'out' to "\\?\" prefix + that full path.
+ *
+ * For example 'in' filename255chars in current directory C:\foo\bar is
+ * fixed as \\?\C:\foo\bar\filename255chars for 'out' which will tell Windows
+ * it is ok to access that filename even though the actual full path is longer
+ * than 260 chars.
+ *
+ * For non-Unicode builds this function may fail sometimes because only the
+ * Unicode versions of some Windows API functions can access paths longer than
+ * MAX_PATH, for example GetFullPathNameW which is used in this function. When
+ * the full path is then converted from Unicode to multibyte that fails if any
+ * directories in the path contain characters not in the current codepage.
+ */
+static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
+{
+ size_t needed, count;
+ const wchar_t *in_w;
+ wchar_t *fbuf = NULL;
+
+ /* MS documented "approximate" limit for the maximum path length */
+ const size_t max_path_len = 32767;
+
+#ifndef _UNICODE
+ wchar_t *ibuf = NULL;
+ char *obuf = NULL;
+#endif
+
+ *out = NULL;
+
+ /* skip paths already normalized */
+ if(!_tcsncmp(in, _T("\\\\?\\"), 4))
+ goto cleanup;
+
+#ifndef _UNICODE
+ /* convert multibyte input to unicode */
+ needed = mbstowcs(NULL, in, 0);
+ if(needed == (size_t)-1 || needed >= max_path_len)
+ goto cleanup;
+ ++needed; /* for NUL */
+ ibuf = (malloc)(needed * sizeof(wchar_t));
+ if(!ibuf)
+ goto cleanup;
+ count = mbstowcs(ibuf, in, needed);
+ if(count == (size_t)-1 || count >= needed)
+ goto cleanup;
+ in_w = ibuf;
+#else
+ in_w = in;
+#endif
+
+ /* GetFullPathNameW returns the normalized full path in unicode. It converts
+ forward slashes to backslashes, processes .. to remove directory segments,
+ etc. Unlike GetFullPathNameA it can process paths that exceed MAX_PATH. */
+ needed = (size_t)GetFullPathNameW(in_w, 0, NULL, NULL);
+ if(!needed || needed > max_path_len)
+ goto cleanup;
+ /* skip paths that are not excessive and do not need modification */
+ if(needed <= MAX_PATH)
+ goto cleanup;
+ fbuf = (malloc)(needed * sizeof(wchar_t));
+ if(!fbuf)
+ goto cleanup;
+ count = (size_t)GetFullPathNameW(in_w, (DWORD)needed, fbuf, NULL);
+ if(!count || count >= needed)
+ goto cleanup;
+
+ /* prepend \\?\ or \\?\UNC\ to the excessively long path.
+ *
+ * c:\longpath ---> \\?\c:\longpath
+ * \\.\c:\longpath ---> \\?\c:\longpath
+ * \\?\c:\longpath ---> \\?\c:\longpath (unchanged)
+ * \\server\c$\longpath ---> \\?\UNC\server\c$\longpath
+ *
+ * https://learn.microsoft.com/dotnet/standard/io/file-path-formats
+ */
+ if(!wcsncmp(fbuf, L"\\\\?\\", 4))
+ ; /* do nothing */
+ else if(!wcsncmp(fbuf, L"\\\\.\\", 4))
+ fbuf[2] = '?';
+ else if(!wcsncmp(fbuf, L"\\\\.", 3) || !wcsncmp(fbuf, L"\\\\?", 3)) {
+ /* Unexpected, not UNC. The formatting doc doesn't allow this AFAICT. */
+ goto cleanup;
+ }
+ else {
+ wchar_t *temp;
+
+ if(!wcsncmp(fbuf, L"\\\\", 2)) {
+ /* "\\?\UNC\" + full path without "\\" + null */
+ needed = 8 + (count - 2) + 1;
+ if(needed > max_path_len)
+ goto cleanup;
+
+ temp = (malloc)(needed * sizeof(wchar_t));
+ if(!temp)
+ goto cleanup;
+
+ wcsncpy(temp, L"\\\\?\\UNC\\", 8);
+ wcscpy(temp + 8, fbuf + 2);
+ }
+ else {
+ /* "\\?\" + full path + null */
+ needed = 4 + count + 1;
+ if(needed > max_path_len)
+ goto cleanup;
+
+ temp = (malloc)(needed * sizeof(wchar_t));
+ if(!temp)
+ goto cleanup;
+
+ wcsncpy(temp, L"\\\\?\\", 4);
+ wcscpy(temp + 4, fbuf);
+ }
+
+ (free)(fbuf);
+ fbuf = temp;
+ }
+
+#ifndef _UNICODE
+ /* convert unicode full path to multibyte output */
+ needed = wcstombs(NULL, fbuf, 0);
+ if(needed == (size_t)-1 || needed >= max_path_len)
+ goto cleanup;
+ ++needed; /* for NUL */
+ obuf = (malloc)(needed);
+ if(!obuf)
+ goto cleanup;
+ count = wcstombs(obuf, fbuf, needed);
+ if(count == (size_t)-1 || count >= needed)
+ goto cleanup;
+ *out = obuf;
+ obuf = NULL;
+#else
+ *out = fbuf;
+ fbuf = NULL;
+#endif
+
+cleanup:
+ (free)(fbuf);
+#ifndef _UNICODE
+ (free)(ibuf);
+ (free)(obuf);
+#endif
+ return *out ? true : false;
+}
+
+int curlx_win32_open(const char *filename, int oflag, ...)
+{
+ int pmode = 0;
+ int result = -1;
+ TCHAR *fixed = NULL;
+ const TCHAR *target = NULL;
+
+#ifdef _UNICODE
+ wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
+#endif
+
+ va_list param;
+ va_start(param, oflag);
+ if(oflag & O_CREAT)
+ pmode = va_arg(param, int);
+ va_end(param);
+
+#ifdef _UNICODE
+ if(filename_w) {
+ if(fix_excessive_path(filename_w, &fixed))
+ target = fixed;
+ else
+ target = filename_w;
+ result = _wopen(target, oflag, pmode);
+ curlx_unicodefree(filename_w);
+ }
+ else
+ /* !checksrc! disable ERRNOVAR 1 */
+ CURL_SETERRNO(EINVAL);
+#else
+ if(fix_excessive_path(filename, &fixed))
+ target = fixed;
+ else
+ target = filename;
+ result = _open(target, oflag, pmode);
+#endif
+
+ (free)(fixed);
+ return result;
+}
+
+FILE *curlx_win32_fopen(const char *filename, const char *mode)
+{
+ FILE *result = NULL;
+ TCHAR *fixed = NULL;
+ const TCHAR *target = NULL;
+
+#ifdef _UNICODE
+ wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
+ wchar_t *mode_w = curlx_convert_UTF8_to_wchar(mode);
+ if(filename_w && mode_w) {
+ if(fix_excessive_path(filename_w, &fixed))
+ target = fixed;
+ else
+ target = filename_w;
+ result = _wfopen(target, mode_w);
+ }
+ else
+ /* !checksrc! disable ERRNOVAR 1 */
+ CURL_SETERRNO(EINVAL);
+ curlx_unicodefree(filename_w);
+ curlx_unicodefree(mode_w);
+#else
+ if(fix_excessive_path(filename, &fixed))
+ target = fixed;
+ else
+ target = filename;
+ /* !checksrc! disable BANNEDFUNC 1 */
+ result = fopen(target, mode);
+#endif
+
+ (free)(fixed);
+ return result;
+}
+
+int curlx_win32_stat(const char *path, struct_stat *buffer)
+{
+ int result = -1;
+ TCHAR *fixed = NULL;
+ const TCHAR *target = NULL;
+
+#ifdef _UNICODE
+ wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
+ if(path_w) {
+ if(fix_excessive_path(path_w, &fixed))
+ target = fixed;
+ else
+ target = path_w;
+#ifndef USE_WIN32_LARGE_FILES
+ result = _wstat(target, buffer);
+#else
+ result = _wstati64(target, buffer);
+#endif
+ curlx_unicodefree(path_w);
+ }
+ else
+ /* !checksrc! disable ERRNOVAR 1 */
+ CURL_SETERRNO(EINVAL);
+#else
+ if(fix_excessive_path(path, &fixed))
+ target = fixed;
+ else
+ target = path;
+#ifndef USE_WIN32_LARGE_FILES
+ result = _stat(target, buffer);
+#else
+ result = _stati64(target, buffer);
+#endif
+#endif
+
+ (free)(fixed);
+ return result;
+}
+
+#endif /* _WIN32 && !UNDER_CE */
--- /dev/null
+#ifndef HEADER_CURLX_FOPEN_H
+#define HEADER_CURLX_FOPEN_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 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
+ * are also available at https://curl.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * SPDX-License-Identifier: curl
+ *
+ ***************************************************************************/
+
+#include "../curl_setup.h"
+
+#include "multibyte.h"
+
+#if defined(_WIN32) && !defined(UNDER_CE)
+FILE *curlx_win32_fopen(const char *filename, const char *mode);
+#define CURLX_FOPEN_LOW(fname, mode) curlx_win32_fopen(fname, mode)
+#else
+#define CURLX_FOPEN_LOW fopen
+#endif
+
+#ifdef CURLDEBUG
+#define curlx_fopen(file,mode) curl_dbg_fopen(file,mode,__LINE__,__FILE__)
+#define curlx_fdopen(file,mode) curl_dbg_fdopen(file,mode,__LINE__,__FILE__)
+#define curlx_fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__)
+#else
+#define curlx_fopen CURLX_FOPEN_LOW
+#define curlx_fdopen fdopen
+#define curlx_fclose fclose
+#endif
+
+#endif /* HEADER_CURLX_FOPEN_H */
return str_utf8;
}
-#ifndef UNDER_CE
-
-/* declare GetFullPathNameW for mingw-w64 UWP builds targeting old windows */
-#if defined(CURL_WINDOWS_UWP) && defined(__MINGW32__) && \
- (_WIN32_WINNT < _WIN32_WINNT_WIN10)
-WINBASEAPI DWORD WINAPI GetFullPathNameW(LPCWSTR, DWORD, LPWSTR, LPWSTR *);
-#endif
-
-/* Fix excessive paths (paths that exceed MAX_PATH length of 260).
- *
- * This is a helper function to fix paths that would exceed the MAX_PATH
- * limitation check done by Windows APIs. It does so by normalizing the passed
- * in filename or path 'in' to its full canonical path, and if that path is
- * longer than MAX_PATH then setting 'out' to "\\?\" prefix + that full path.
- *
- * For example 'in' filename255chars in current directory C:\foo\bar is
- * fixed as \\?\C:\foo\bar\filename255chars for 'out' which will tell Windows
- * it is ok to access that filename even though the actual full path is longer
- * than 260 chars.
- *
- * For non-Unicode builds this function may fail sometimes because only the
- * Unicode versions of some Windows API functions can access paths longer than
- * MAX_PATH, for example GetFullPathNameW which is used in this function. When
- * the full path is then converted from Unicode to multibyte that fails if any
- * directories in the path contain characters not in the current codepage.
- */
-static bool fix_excessive_path(const TCHAR *in, TCHAR **out)
-{
- size_t needed, count;
- const wchar_t *in_w;
- wchar_t *fbuf = NULL;
-
- /* MS documented "approximate" limit for the maximum path length */
- const size_t max_path_len = 32767;
-
-#ifndef _UNICODE
- wchar_t *ibuf = NULL;
- char *obuf = NULL;
-#endif
-
- *out = NULL;
-
- /* skip paths already normalized */
- if(!_tcsncmp(in, _T("\\\\?\\"), 4))
- goto cleanup;
-
-#ifndef _UNICODE
- /* convert multibyte input to unicode */
- needed = mbstowcs(NULL, in, 0);
- if(needed == (size_t)-1 || needed >= max_path_len)
- goto cleanup;
- ++needed; /* for NUL */
- ibuf = (malloc)(needed * sizeof(wchar_t));
- if(!ibuf)
- goto cleanup;
- count = mbstowcs(ibuf, in, needed);
- if(count == (size_t)-1 || count >= needed)
- goto cleanup;
- in_w = ibuf;
-#else
- in_w = in;
-#endif
-
- /* GetFullPathNameW returns the normalized full path in unicode. It converts
- forward slashes to backslashes, processes .. to remove directory segments,
- etc. Unlike GetFullPathNameA it can process paths that exceed MAX_PATH. */
- needed = (size_t)GetFullPathNameW(in_w, 0, NULL, NULL);
- if(!needed || needed > max_path_len)
- goto cleanup;
- /* skip paths that are not excessive and do not need modification */
- if(needed <= MAX_PATH)
- goto cleanup;
- fbuf = (malloc)(needed * sizeof(wchar_t));
- if(!fbuf)
- goto cleanup;
- count = (size_t)GetFullPathNameW(in_w, (DWORD)needed, fbuf, NULL);
- if(!count || count >= needed)
- goto cleanup;
-
- /* prepend \\?\ or \\?\UNC\ to the excessively long path.
- *
- * c:\longpath ---> \\?\c:\longpath
- * \\.\c:\longpath ---> \\?\c:\longpath
- * \\?\c:\longpath ---> \\?\c:\longpath (unchanged)
- * \\server\c$\longpath ---> \\?\UNC\server\c$\longpath
- *
- * https://learn.microsoft.com/dotnet/standard/io/file-path-formats
- */
- if(!wcsncmp(fbuf, L"\\\\?\\", 4))
- ; /* do nothing */
- else if(!wcsncmp(fbuf, L"\\\\.\\", 4))
- fbuf[2] = '?';
- else if(!wcsncmp(fbuf, L"\\\\.", 3) || !wcsncmp(fbuf, L"\\\\?", 3)) {
- /* Unexpected, not UNC. The formatting doc doesn't allow this AFAICT. */
- goto cleanup;
- }
- else {
- wchar_t *temp;
-
- if(!wcsncmp(fbuf, L"\\\\", 2)) {
- /* "\\?\UNC\" + full path without "\\" + null */
- needed = 8 + (count - 2) + 1;
- if(needed > max_path_len)
- goto cleanup;
-
- temp = (malloc)(needed * sizeof(wchar_t));
- if(!temp)
- goto cleanup;
-
- wcsncpy(temp, L"\\\\?\\UNC\\", 8);
- wcscpy(temp + 8, fbuf + 2);
- }
- else {
- /* "\\?\" + full path + null */
- needed = 4 + count + 1;
- if(needed > max_path_len)
- goto cleanup;
-
- temp = (malloc)(needed * sizeof(wchar_t));
- if(!temp)
- goto cleanup;
-
- wcsncpy(temp, L"\\\\?\\", 4);
- wcscpy(temp + 4, fbuf);
- }
-
- (free)(fbuf);
- fbuf = temp;
- }
-
-#ifndef _UNICODE
- /* convert unicode full path to multibyte output */
- needed = wcstombs(NULL, fbuf, 0);
- if(needed == (size_t)-1 || needed >= max_path_len)
- goto cleanup;
- ++needed; /* for NUL */
- obuf = (malloc)(needed);
- if(!obuf)
- goto cleanup;
- count = wcstombs(obuf, fbuf, needed);
- if(count == (size_t)-1 || count >= needed)
- goto cleanup;
- *out = obuf;
- obuf = NULL;
-#else
- *out = fbuf;
- fbuf = NULL;
-#endif
-
-cleanup:
- (free)(fbuf);
-#ifndef _UNICODE
- (free)(ibuf);
- (free)(obuf);
-#endif
- return *out ? true : false;
-}
-
-int curlx_win32_open(const char *filename, int oflag, ...)
-{
- int pmode = 0;
- int result = -1;
- TCHAR *fixed = NULL;
- const TCHAR *target = NULL;
-
-#ifdef _UNICODE
- wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
-#endif
-
- va_list param;
- va_start(param, oflag);
- if(oflag & O_CREAT)
- pmode = va_arg(param, int);
- va_end(param);
-
-#ifdef _UNICODE
- if(filename_w) {
- if(fix_excessive_path(filename_w, &fixed))
- target = fixed;
- else
- target = filename_w;
- result = _wopen(target, oflag, pmode);
- curlx_unicodefree(filename_w);
- }
- else
- /* !checksrc! disable ERRNOVAR 1 */
- CURL_SETERRNO(EINVAL);
-#else
- if(fix_excessive_path(filename, &fixed))
- target = fixed;
- else
- target = filename;
- result = _open(target, oflag, pmode);
-#endif
-
- (free)(fixed);
- return result;
-}
-
-FILE *curlx_win32_fopen(const char *filename, const char *mode)
-{
- FILE *result = NULL;
- TCHAR *fixed = NULL;
- const TCHAR *target = NULL;
-
-#ifdef _UNICODE
- wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
- wchar_t *mode_w = curlx_convert_UTF8_to_wchar(mode);
- if(filename_w && mode_w) {
- if(fix_excessive_path(filename_w, &fixed))
- target = fixed;
- else
- target = filename_w;
- result = _wfopen(target, mode_w);
- }
- else
- /* !checksrc! disable ERRNOVAR 1 */
- CURL_SETERRNO(EINVAL);
- curlx_unicodefree(filename_w);
- curlx_unicodefree(mode_w);
-#else
- if(fix_excessive_path(filename, &fixed))
- target = fixed;
- else
- target = filename;
- result = (fopen)(target, mode);
-#endif
-
- (free)(fixed);
- return result;
-}
-
-int curlx_win32_stat(const char *path, struct_stat *buffer)
-{
- int result = -1;
- TCHAR *fixed = NULL;
- const TCHAR *target = NULL;
-
-#ifdef _UNICODE
- wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
- if(path_w) {
- if(fix_excessive_path(path_w, &fixed))
- target = fixed;
- else
- target = path_w;
-#ifndef USE_WIN32_LARGE_FILES
- result = _wstat(target, buffer);
-#else
- result = _wstati64(target, buffer);
-#endif
- curlx_unicodefree(path_w);
- }
- else
- /* !checksrc! disable ERRNOVAR 1 */
- CURL_SETERRNO(EINVAL);
-#else
- if(fix_excessive_path(path, &fixed))
- target = fixed;
- else
- target = path;
-#ifndef USE_WIN32_LARGE_FILES
- result = _stat(target, buffer);
-#else
- result = _stati64(target, buffer);
-#endif
-#endif
-
- (free)(fixed);
- return result;
-}
-
-#endif /* UNDER_CE */
-
#endif /* _WIN32 */
#include "urldata.h"
#include "llist.h"
#include "hsts.h"
+#include "curl_fopen.h"
#include "curl_get_line.h"
#include "sendf.h"
#include "parsedate.h"
-#include "fopen.h"
#include "rename.h"
#include "share.h"
#include "strdup.h"
if(result)
break;
}
- fclose(out);
+ curlx_fclose(out);
if(!result && tempstore && Curl_rename(tempstore, file))
result = CURLE_WRITE_ERROR;
if(!h->filename)
return CURLE_OUT_OF_MEMORY;
- fp = fopen(file, FOPEN_READTEXT);
+ fp = curlx_fopen(file, FOPEN_READTEXT);
if(fp) {
struct dynbuf buf;
curlx_dyn_init(&buf, MAX_HSTS_LINE);
hsts_add(h, lineptr);
}
curlx_dyn_free(&buf); /* free the line buffer */
- fclose(fp);
+ curlx_fclose(fp);
}
return result;
}
#include <curl/curl.h>
#include "urldata.h"
+#include "curlx/fopen.h" /* for CURLX_FOPEN_LOW() */
/* The last 3 #include files should be in this order */
#include "curl_printf.h"
if(curl_dbg_logfile &&
curl_dbg_logfile != stderr &&
curl_dbg_logfile != stdout) {
- (fclose)(curl_dbg_logfile);
+ /* !checksrc! disable BANNEDFUNC 1 */
+ fclose(curl_dbg_logfile);
}
curl_dbg_logfile = NULL;
}
{
if(!curl_dbg_logfile) {
if(logname && *logname)
-#ifdef CURL_FOPEN
- curl_dbg_logfile = CURL_FOPEN(logname, FOPEN_WRITETEXT);
-#else
- curl_dbg_logfile = (fopen)(logname, FOPEN_WRITETEXT);
-#endif
+ curl_dbg_logfile = CURLX_FOPEN_LOW(logname, FOPEN_WRITETEXT);
else
curl_dbg_logfile = stderr;
#ifdef MEMDEBUG_LOG_SYNC
FILE *curl_dbg_fopen(const char *file, const char *mode,
int line, const char *source)
{
- FILE *res;
-#ifdef CURL_FOPEN
- res = CURL_FOPEN(file, mode);
-#else
- res = (fopen)(file, mode);
-#endif
-
+ FILE *res = CURLX_FOPEN_LOW(file, mode);
if(source)
curl_dbg_log("FILE %s:%d fopen(\"%s\",\"%s\") = %p\n",
source, line, file, mode, (void *)res);
FILE *curl_dbg_fdopen(int filedes, const char *mode,
int line, const char *source)
{
- FILE *res = (fdopen)(filedes, mode);
+ /* !checksrc! disable BANNEDFUNC 1 */
+ FILE *res = fdopen(filedes, mode);
if(source)
curl_dbg_log("FILE %s:%d fdopen(\"%d\",\"%s\") = %p\n",
source, line, filedes, mode, (void *)res);
curl_dbg_log("FILE %s:%d fclose(%p)\n",
source, line, (void *)file);
- res = (fclose)(file);
+ /* !checksrc! disable BANNEDFUNC 1 */
+ res = fclose(file);
return res;
}
#endif
#endif /* _WIN32 */
-#undef fopen
-#define fopen(file,mode) curl_dbg_fopen(file,mode,__LINE__,__FILE__)
-#undef fdopen
-#define fdopen(file,mode) curl_dbg_fdopen(file,mode,__LINE__,__FILE__)
-#undef fclose
-#define fclose(file) curl_dbg_fclose(file,__LINE__,__FILE__)
-
#endif /* CURLDEBUG */
#endif /* HEADER_CURL_MEMDEBUG_H */
#include "sendf.h"
#include "transfer.h"
#include "strdup.h"
+#include "curlx/fopen.h"
#include "curlx/base64.h"
#if !defined(CURL_DISABLE_MIME) && \
#ifndef __VMS
#define filesize(name, stat_data) (stat_data.st_size)
-#define fopen_read fopen
+#define fopen_read curlx_fopen
#else
int ret_stat;
FILE * file;
- file = fopen(name, FOPEN_READTEXT); /* VMS */
+ file = curlx_fopen(name, FOPEN_READTEXT); /* VMS */
if(!file)
return 0;
if(ret_stat)
count += ret_stat;
}
- fclose(file);
+ curlx_fclose(file);
return count;
}
case FAB$C_VAR:
case FAB$C_VFC:
case FAB$C_STMCR:
- return fopen(file, FOPEN_READTEXT); /* VMS */
+ return curlx_fopen(file, FOPEN_READTEXT); /* VMS */
break;
default:
- return fopen(file, FOPEN_READTEXT, "rfm=stmlf", "ctx=stm");
+ return curlx_fopen(file, FOPEN_READTEXT, "rfm=stmlf", "ctx=stm");
}
}
curl_mimepart *part = (curl_mimepart *) ptr;
if(part->fp) {
- fclose(part->fp);
+ curlx_fclose(part->fp);
part->fp = NULL;
}
Curl_safefree(part->data);
mimesetstate(&part->state, MIMESTATE_END, NULL);
/* Try sparing open file descriptors. */
if(part->kind == MIMEKIND_FILE && part->fp) {
- fclose(part->fp);
+ curlx_fclose(part->fp);
part->fp = NULL;
}
FALLTHROUGH();
#include "netrc.h"
#include "strcase.h"
#include "curl_get_line.h"
+#include "curlx/fopen.h"
#include "curlx/strparse.h"
/* The last 3 #include files should be in this order */
static NETRCcode file2memory(const char *filename, struct dynbuf *filebuf)
{
NETRCcode ret = NETRC_FILE_MISSING; /* if it cannot open the file */
- FILE *file = fopen(filename, FOPEN_READTEXT);
+ FILE *file = curlx_fopen(filename, FOPEN_READTEXT);
struct dynbuf linebuf;
curlx_dyn_init(&linebuf, MAX_NETRC_LINE);
done:
curlx_dyn_free(&linebuf);
if(file)
- fclose(file);
+ curlx_fclose(file);
return ret;
}
#include "../progress.h"
#include "../select.h"
#include "../strdup.h"
+#include "../curlx/fopen.h"
#include "../curlx/warnless.h"
#include "x509asn1.h"
#include "../multiif.h"
long filelen;
void *ptr;
- f = fopen(file, "rb");
+ f = curlx_fopen(file, "rb");
if(!f)
return loaded_file;
if(fseek(f, 0, SEEK_END) != 0
loaded_file.data = ptr;
loaded_file.size = (unsigned int)filelen;
out:
- fclose(f);
+ curlx_fclose(f);
return loaded_file;
}
#include "keylog.h"
#include <curl/curl.h>
#include "../escape.h"
+#include "../curlx/fopen.h"
/* The last #include files should be: */
#include "../curl_memory.h"
if(!keylog_file_fp) {
keylog_file_name = curl_getenv("SSLKEYLOGFILE");
if(keylog_file_name) {
- keylog_file_fp = fopen(keylog_file_name, FOPEN_APPENDTEXT);
+ keylog_file_fp = curlx_fopen(keylog_file_name, FOPEN_APPENDTEXT);
if(keylog_file_fp) {
#ifdef _WIN32
if(setvbuf(keylog_file_fp, NULL, _IONBF, 0))
if(setvbuf(keylog_file_fp, NULL, _IOLBF, 4096))
#endif
{
- fclose(keylog_file_fp);
+ curlx_fclose(keylog_file_fp);
keylog_file_fp = NULL;
}
}
Curl_tls_keylog_close(void)
{
if(keylog_file_fp) {
- fclose(keylog_file_fp);
+ curlx_fclose(keylog_file_fp);
keylog_file_fp = NULL;
}
}
#include <rustls.h>
+#include "../curlx/fopen.h"
#include "../curlx/inet_pton.h"
#include "../urldata.h"
#include "../sendf.h"
read_file_into(const char *filename,
struct dynbuf *out)
{
- FILE *f = fopen(filename, FOPEN_READTEXT);
+ FILE *f = curlx_fopen(filename, FOPEN_READTEXT);
if(!f) {
return 0;
}
const size_t rr = fread(buf, 1, sizeof(buf), f);
if(rr == 0 ||
CURLE_OK != curlx_dyn_addn(out, buf, rr)) {
- fclose(f);
+ curlx_fclose(f);
return 0;
}
if(rr < sizeof(buf))
break;
}
- return fclose(f) == 0;
+ return curlx_fclose(f) == 0;
}
static void
#include "../strdup.h"
#include "../strerror.h"
#include "../select.h" /* for the socket readiness */
+#include "../curlx/fopen.h"
#include "../curlx/inet_pton.h" /* for IP addr SNI check */
#include "../curlx/multibyte.h"
#include "../curlx/warnless.h"
&cert_store_path, &cert_thumbprint_str);
if(result && (data->set.ssl.primary.clientcert[0]!='\0'))
- fInCert = fopen(data->set.ssl.primary.clientcert, "rb");
+ fInCert = curlx_fopen(data->set.ssl.primary.clientcert, "rb");
if(result && !fInCert) {
failf(data, "schannel: Failed to get certificate location"
if((!certdata) ||
((int) fread(certdata, certsize, 1, fInCert) != 1))
continue_reading = FALSE;
- fclose(fInCert);
+ curlx_fclose(fInCert);
if(!continue_reading) {
failf(data, "schannel: Failed to read cert file %s",
data->set.ssl.primary.clientcert);
#include "../progress.h"
#include "../share.h"
#include "../multiif.h"
+#include "../curlx/fopen.h"
#include "../curlx/timeval.h"
#include "../curl_md5.h"
#include "../curl_sha256.h"
struct dynbuf buf;
char unsigned *pem_ptr = NULL;
size_t left;
- FILE *fp = fopen(pinnedpubkey, "rb");
+ FILE *fp = curlx_fopen(pinnedpubkey, "rb");
if(!fp)
return result;
end:
curlx_dyn_free(&buf);
Curl_safefree(pem_ptr);
- fclose(fp);
+ curlx_fclose(fp);
}
return result;
"send" => 1,
"socket" => 1,
"socketpair" => 1,
+ "fclose" => 1,
+ "fdopen" => 1,
+ "fopen" => 1,
);
my %warnings_extended = (
}
# scan for use of non-binary fopen without the macro
- if($l =~ /^(.*\W)fopen\s*\([^,]*, *\"([^"]*)/) {
- my $mode = $2;
+ if($l =~ /^(.*\W)(curlx_fopen|CURLX_FOPEN_LOW)\s*\([^,]*, *\"([^"]*)/) {
+ my $mode = $3;
if($mode !~ /b/) {
checkwarn("FOPENMODE",
$line, length($1), $file, $ol,
../lib/curlx/base64.c \
../lib/curlx/multibyte.c \
../lib/curlx/dynbuf.c \
+ ../lib/curlx/fopen.c \
../lib/curlx/nonblock.c \
../lib/curlx/strparse.c \
../lib/curlx/timediff.c \
../lib/curlx/multibyte.h \
../lib/curl_setup.h \
../lib/curlx/dynbuf.h \
+ ../lib/curlx/fopen.h \
../lib/curlx/nonblock.h \
../lib/curlx/strparse.h \
../lib/curlx/timediff.h \
/* Ok, this is somewhat hackish but we do it undocumented for now */
global->trace_stream = tool_stderr;
else {
- global->trace_stream = fopen(global->trace_dump, FOPEN_WRITETEXT);
+ global->trace_stream = curlx_fopen(global->trace_dump, FOPEN_WRITETEXT);
global->trace_fopened = TRUE;
}
}
(config->file_clobber_mode == CLOBBER_DEFAULT &&
!outs->is_cd_filename)) {
/* open file for writing */
- file = fopen(fname, "wb");
+ file = curlx_fopen(fname, "wb");
}
else {
int fd;
is not needed because we would have failed earlier, in the while loop
and `fd` would now be -1 */
if(fd != -1) {
- file = fdopen(fd, "wb");
+ file = curlx_fdopen(fd, "wb");
if(!file)
close(fd);
}
tool_safefree(global->trace_dump);
if(global->trace_fopened && global->trace_stream)
- fclose(global->trace_stream);
+ curlx_fclose(global->trace_stream);
global->trace_stream = NULL;
tool_safefree(global->libcurl);
FILE *out;
bool fopened = FALSE;
if(strcmp(o, "-")) {
- out = fopen(o, FOPEN_WRITETEXT);
+ out = curlx_fopen(o, FOPEN_WRITETEXT);
fopened = TRUE;
}
else
fprintf(out, "%s\n", c);
if(fopened)
- fclose(out);
+ curlx_fclose(out);
}
easysrc_free();
endpos--;
sep = *p;
*endpos = '\0';
- fp = fopen(hdrfile, FOPEN_READTEXT);
+ fp = curlx_fopen(hdrfile, FOPEN_READTEXT);
if(!fp)
warnf("Cannot read from %s: %s", hdrfile,
strerror(errno));
else {
int i = read_field_headers(hdrfile, fp, &headers);
- fclose(fp);
+ curlx_fclose(fp);
if(i) {
curl_slist_free_all(headers);
return -1;
CURLX_SET_BINMODE(stdin);
}
else {
- file = fopen(p, "rb");
+ file = curlx_fopen(p, "rb");
if(!file) {
errorf("Failed to open %s", p);
return PARAM_READ_ERROR;
err = file2memory(&postdata, &size, file);
if(file && (file != stdin))
- fclose(file);
+ curlx_fclose(file);
if(err)
return err;
}
CURLX_SET_BINMODE(stdin);
}
else {
- file = fopen(nextarg, "rb");
+ file = curlx_fopen(nextarg, "rb");
if(!file) {
errorf("Failed to open %s", nextarg);
return PARAM_READ_ERROR;
}
if(file && (file != stdin))
- fclose(file);
+ curlx_fclose(file);
if(err)
return err;
if(fromstdin)
f = stdin;
else
- f = fopen(&nextarg[1], FOPEN_READTEXT);
+ f = curlx_fopen(&nextarg[1], FOPEN_READTEXT);
if(f) {
curlx_dyn_init(&line, 8092);
while(my_get_line(f, &line, &error)) {
break;
}
if(!fromstdin)
- fclose(f);
+ curlx_fclose(f);
curlx_dyn_free(&line);
if(error || err)
return PARAM_READ_ERROR;
file = stdin;
}
else {
- file = fopen(nextarg, FOPEN_READTEXT);
+ file = curlx_fopen(nextarg, FOPEN_READTEXT);
}
if(!file) {
warnf("Couldn't read file \"%s\" "
}
err = file2string(&tmpcfg, file);
if(file != stdin)
- fclose(file);
+ curlx_fclose(file);
if(err)
return err;
config->ech_config = aprintf("ecl:%s",tmpcfg);
if(nextarg[0] == '@') {
/* read many headers from a file or stdin */
bool use_stdin = !strcmp(&nextarg[1], "-");
- FILE *file = use_stdin ? stdin : fopen(&nextarg[1], FOPEN_READTEXT);
+ FILE *file = use_stdin ? stdin : curlx_fopen(&nextarg[1], FOPEN_READTEXT);
if(!file) {
errorf("Failed to open %s", &nextarg[1]);
err = PARAM_READ_ERROR;
err = PARAM_READ_ERROR;
curlx_dyn_free(&line);
if(!use_stdin)
- fclose(file);
+ curlx_fclose(file);
}
}
else {
}
else {
fname = nextarg;
- file = fopen(fname, FOPEN_READTEXT);
+ file = curlx_fopen(fname, FOPEN_READTEXT);
if(!file) {
errorf("Failed to open %s", fname);
return PARAM_READ_ERROR;
tool_safefree(config->writeout);
err = file2string(&config->writeout, file);
if(file && (file != stdin))
- fclose(file);
+ curlx_fclose(file);
if(err)
return err;
if(!config->writeout)
if(!gateway_composed_file_path)
goto fail;
- gateway_file = fopen(gateway_composed_file_path, FOPEN_READTEXT);
+ gateway_file = curlx_fopen(gateway_composed_file_path, FOPEN_READTEXT);
tool_safefree(gateway_composed_file_path);
if(gateway_file) {
goto fail;
}
- fclose(gateway_file);
+ curlx_fclose(gateway_file);
gateway_file = NULL;
if(curlx_dyn_len(&dyn))
}
fail:
if(gateway_file)
- fclose(gateway_file);
+ curlx_fclose(gateway_file);
tool_safefree(gateway);
tool_safefree(ipfs_path);
return NULL;
FILE * file;
/* !checksrc! disable FOPENMODE 1 */
- file = fopen(name, "r"); /* VMS */
+ file = curlx_fopen(name, "r"); /* VMS */
if(!file) {
return 0;
}
if(ret_stat)
count += ret_stat;
}
- fclose(file);
+ curlx_fclose(file);
return count;
}
/* Close the outs file */
if(outs->fopened && outs->stream) {
- rc = fclose(outs->stream);
+ rc = curlx_fclose(outs->stream);
if(!result && rc) {
/* something went wrong in the writing process */
result = CURLE_WRITE_ERROR;
/* Close function-local opened file descriptors */
if(per->heads.fopened && per->heads.stream)
- fclose(per->heads.stream);
+ curlx_fclose(per->heads.stream);
if(per->heads.alloc_filename)
tool_safefree(per->heads.filename);
if(per->etag_save.fopened && per->etag_save.stream)
- fclose(per->etag_save.stream);
+ curlx_fclose(per->etag_save.stream);
if(per->etag_save.alloc_filename)
tool_safefree(per->etag_save.filename);
ParameterError pe;
/* open file for reading: */
- FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
+ FILE *file = curlx_fopen(config->etag_compare_file, FOPEN_READTEXT);
if(!file)
warnf("Failed to open %s: %s", config->etag_compare_file,
strerror(errno));
if(!header) {
if(file)
- fclose(file);
+ curlx_fclose(file);
errorf("Failed to allocate memory for custom etag header");
return CURLE_OUT_OF_MEMORY;
}
tool_safefree(header);
if(file)
- fclose(file);
+ curlx_fclose(file);
if(pe != PARAM_OK)
result = CURLE_OUT_OF_MEMORY;
return result;
/* open file for output: */
if(strcmp(config->etag_save_file, "-")) {
- FILE *newfile = fopen(config->etag_save_file, "ab");
+ FILE *newfile = curlx_fopen(config->etag_save_file, "ab");
if(!newfile) {
warnf("Failed creating file for saving etags: \"%s\". "
"Skip this transfer", config->etag_save_file);
return result;
}
if(!per->prev || per->prev->config != config) {
- newfile = fopen(config->headerfile, "wb");
+ newfile = curlx_fopen(config->headerfile, "wb");
if(newfile)
- fclose(newfile);
+ curlx_fclose(newfile);
}
- newfile = fopen(config->headerfile, "ab");
+ newfile = curlx_fopen(config->headerfile, "ab");
if(!newfile) {
errorf("Failed to open %s", config->headerfile);
#ifdef __VMS
/* open file for output, forcing VMS output format into stream
mode which is needed for stat() call above to always work. */
- FILE *file = fopen(outfile, "ab",
- "ctx=stm", "rfm=stmlf", "rat=cr", "mrs=0");
+ FILE *file = curlx_fopen(outfile, "ab",
+ "ctx=stm", "rfm=stmlf", "rat=cr", "mrs=0");
#else
/* open file for output: */
- FILE *file = fopen(per->outfile, "ab");
+ FILE *file = curlx_fopen(per->outfile, "ab");
#endif
if(!file) {
errorf("cannot open '%s'", per->outfile);
if(result) {
curl_easy_cleanup(curl);
if(etag_first.fopened)
- fclose(etag_first.stream);
+ curlx_fclose(etag_first.stream);
return result;
}
per->etag_save = etag_first; /* copy the whole struct */
char *cacert = NULL;
FILE *cafile = tool_execpath("curl-ca-bundle.crt", &cacert);
if(cafile) {
- fclose(cafile);
+ curlx_fclose(cafile);
config->cacert = strdup(cacert);
}
#elif !defined(CURL_WINDOWS_UWP) && !defined(UNDER_CE) && \
/* NULL means load .curlrc from homedir! */
char *curlrc = findfile(".curlrc", CURLRC_DOTSCORE);
if(curlrc) {
- file = fopen(curlrc, FOPEN_READTEXT);
+ file = curlx_fopen(curlrc, FOPEN_READTEXT);
if(!file) {
free(curlrc);
return 1;
}
else {
if(strcmp(filename, "-"))
- file = fopen(filename, FOPEN_READTEXT);
+ file = curlx_fopen(filename, FOPEN_READTEXT);
else
file = stdin;
}
curlx_dyn_free(&buf);
curlx_dyn_free(&pbuf);
if(file != stdin)
- fclose(file);
+ curlx_fclose(file);
if(fileerror)
rc = 1;
}
bool error = FALSE;
curlx_dyn_init(&buf, MAX_SSLS_LINE);
- fp = fopen(filename, FOPEN_READTEXT);
+ fp = curlx_fopen(filename, FOPEN_READTEXT);
if(!fp) { /* ok if it does not exist */
notef("SSL session file does not exist (yet?): %s", filename);
goto out;
if(easy)
curl_easy_cleanup(easy);
if(fp)
- fclose(fp);
+ curlx_fclose(fp);
curlx_dyn_free(&buf);
curl_free(shmac);
curl_free(sdata);
CURLcode r = CURLE_OK;
ctx.exported = 0;
- ctx.fp = fopen(filename, FOPEN_WRITETEXT);
+ ctx.fp = curlx_fopen(filename, FOPEN_WRITETEXT);
if(!ctx.fp) {
warnf("Warning: Failed to create SSL session file %s",
filename);
if(easy)
curl_easy_cleanup(easy);
if(ctx.fp)
- fclose(ctx.fp);
+ curlx_fclose(ctx.fp);
return r;
}
/* precheck that filename is accessible to lessen the chance that the
subsequent freopen will fail. */
- fp = fopen(filename, FOPEN_WRITETEXT);
+ fp = curlx_fopen(filename, FOPEN_WRITETEXT);
if(!fp) {
warnf("Warning: Failed to open %s", filename);
return;
}
- fclose(fp);
+ curlx_fclose(fp);
/* freopen the actual stderr (stdio.h stderr) instead of tool_stderr since
the latter may be set to stdout. */
if(strlen(filename) < remaining - 1) {
curl_msnprintf(lastdirchar, remaining, "%s%s", DIR_CHAR, filename);
*pathp = filebuffer;
- return fopen(filebuffer, FOPEN_READTEXT);
+ return curlx_fopen(filebuffer, FOPEN_READTEXT);
}
}
}
break;
case VAR_STDOUT:
if(fclose_stream)
- fclose(stream);
+ curlx_fclose(stream);
fclose_stream = FALSE;
stream = stdout;
break;
case VAR_STDERR:
if(fclose_stream)
- fclose(stream);
+ curlx_fclose(stream);
fclose_stream = FALSE;
stream = tool_stderr;
break;
FILE *stream2;
memcpy(fname, ptr, flen);
fname[flen] = 0;
- stream2 = fopen(fname, append ? FOPEN_APPENDTEXT :
- FOPEN_WRITETEXT);
+ stream2 = curlx_fopen(fname, append ? FOPEN_APPENDTEXT :
+ FOPEN_WRITETEXT);
if(stream2) {
/* only change if the open worked */
if(fclose_stream)
- fclose(stream);
+ curlx_fclose(stream);
stream = stream2;
fclose_stream = TRUE;
}
}
}
if(fclose_stream)
- fclose(stream);
+ curlx_fclose(stream);
curlx_dyn_free(&name);
}
if(use_stdin)
file = stdin;
else {
- file = fopen(line, "rb");
+ file = curlx_fopen(line, "rb");
if(!file) {
errorf("Failed to open %s: %s", line, strerror(errno));
err = PARAM_READ_ERROR;
}
curlx_dyn_free(&fname);
if(!use_stdin && file)
- fclose(file);
+ curlx_fclose(file);
if(err)
return err;
}
a = sprintf(buffer, "%s", moo);
-FILE *f = fopen("filename", "r");
+FILE *f = curlx_fopen("filename", "r");
void startfunc(int a, int b) {
func();
a = sprintf(buffer, "%s", moo);
^
./%LOGDIR/code1185.c:32:11: warning: use of non-binary fopen without FOPEN_* macro: r (FOPENMODE)
- FILE *f = fopen("filename", "r");
+ FILE *f = curlx_fopen("filename", "r");
^
./%LOGDIR/code1185.c:34:30: warning: wrongly placed open brace (BRACEPOS)
void startfunc(int a, int b) {
UTILS_H = testutil.h testtrace.h unitcheck.h
CURLX_C = \
+ ../../lib/curlx/fopen.c \
../../lib/curlx/warnless.c \
../../lib/curlx/multibyte.c \
../../lib/curlx/timediff.c \
static int setup_h2_serverpush(CURL *hnd, const char *url)
{
- out_download = fopen("download_0.data", "wb");
+ out_download = curlx_fopen("download_0.data", "wb");
if(!out_download)
return 1; /* failed */
curl_msnprintf(filename, sizeof(filename) - 1, "push%u", count++);
/* here's a new stream, save it in a new file for each new push */
- out_push = fopen(filename, "wb");
+ out_push = curlx_fopen(filename, "wb");
if(!out_push) {
/* if we cannot save it, deny it */
curl_mfprintf(stderr, "Failed to create output file for push\n");
easy = curl_easy_init();
if(setup_h2_serverpush(easy, URL)) {
- fclose(out_download);
+ curlx_fclose(out_download);
curl_mfprintf(stderr, "failed\n");
return (CURLcode)1;
}
curl_multi_cleanup(multi_handle);
- fclose(out_download);
+ curlx_fclose(out_download);
if(out_push)
- fclose(out_push);
+ curlx_fclose(out_push);
return CURLE_OK;
}
if(!t->out) {
curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%zu.data",
t->idx);
- t->out = fopen(t->filename, "wb");
+ t->out = curlx_fopen(t->filename, "wb");
if(!t->out)
return 0;
}
for(i = 0; i < transfer_count_d; ++i) {
t = &transfer_d[i];
if(t->out) {
- fclose(t->out);
+ curlx_fclose(t->out);
t->out = NULL;
}
if(t->easy) {
if(!t->out) {
curl_msnprintf(t->filename, sizeof(t->filename)-1, "download_%zu.data",
t->idx);
- t->out = fopen(t->filename, "wb");
+ t->out = curlx_fopen(t->filename, "wb");
if(!t->out)
return 0;
}
for(i = 0; i < transfer_count_u; ++i) {
t = &transfer_u[i];
if(t->out) {
- fclose(t->out);
+ curlx_fclose(t->out);
t->out = NULL;
}
if(t->easy) {
if(!res) {
res = curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, &ipstr);
if(libtest_arg2) {
- FILE *moo = fopen(libtest_arg2, "wb");
+ FILE *moo = curlx_fopen(libtest_arg2, "wb");
if(moo) {
curl_off_t time_namelookup;
curl_off_t time_connect;
(long)(time_total % 1000000));
}
- fclose(moo);
+ curlx_fclose(moo);
}
}
}
return TEST_ERR_USAGE;
}
- hd_src = fopen(libtest_arg2, "rb");
+ hd_src = curlx_fopen(libtest_arg2, "rb");
if(!hd_src) {
curl_mfprintf(stderr, "fopen failed with error (%d) %s\n",
errno, strerror(errno));
curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n",
errno, strerror(errno));
curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2);
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
if(!file_info.st_size) {
curl_mfprintf(stderr, "File %s has zero size!\n", libtest_arg2);
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
curl_mfprintf(stderr, "curl_slist_append() failed\n");
curl_easy_cleanup(curl);
curl_global_cleanup();
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
headerlist = curl_slist_append(hl, buf_2);
curl_slist_free_all(hl);
curl_easy_cleanup(curl);
curl_global_cleanup();
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
headerlist = hl;
curl_slist_free_all(headerlist);
/* close the local file */
- fclose(hd_src);
+ curlx_fclose(hd_src);
curl_easy_cleanup(curl);
curl_global_cleanup();
fpa[i] = NULL;
}
for(i = 0; i < 3; i++) {
- fpa[i] = fopen(DEV_NULL, FOPEN_READTEXT);
+ fpa[i] = curlx_fopen(DEV_NULL, FOPEN_READTEXT);
if(!fpa[i]) {
t518_store_errmsg("fopen failed", errno);
curl_mfprintf(stderr, "%s\n", t518_msgbuff);
}
for(i = 0; i < 3; i++) {
if(fpa[i])
- fclose(fpa[i]);
+ curlx_fclose(fpa[i]);
}
return ret;
}
return TEST_ERR_USAGE;
}
- hd_src = fopen(libtest_arg2, "rb");
+ hd_src = curlx_fopen(libtest_arg2, "rb");
if(!hd_src) {
curl_mfprintf(stderr, "fopen failed with error (%d) %s\n",
errno, strerror(errno));
curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n",
errno, strerror(errno));
curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2);
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_FSTAT;
}
res_global_init(CURL_GLOBAL_ALL);
if(res) {
- fclose(hd_src);
+ curlx_fclose(hd_src);
return res;
}
}
/* close the local file */
- fclose(hd_src);
+ curlx_fclose(hd_src);
return res;
}
fpa[i] = NULL;
}
for(i = 0; i < 3; i++) {
- fpa[i] = fopen(DEV_NULL, FOPEN_READTEXT);
+ fpa[i] = curlx_fopen(DEV_NULL, FOPEN_READTEXT);
if(!fpa[i]) {
t537_store_errmsg("fopen failed", errno);
curl_mfprintf(stderr, "%s\n", t537_msgbuff);
}
for(i = 0; i < 3; i++) {
if(fpa[i])
- fclose(fpa[i]);
+ curlx_fclose(fpa[i]);
}
return ret;
}
return TEST_ERR_USAGE;
}
- hd_src = fopen(libtest_arg2, "rb");
+ hd_src = curlx_fopen(libtest_arg2, "rb");
if(!hd_src) {
curl_mfprintf(stderr, "fopen failed with error (%d) %s\n",
errno, strerror(errno));
curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n",
errno, strerror(errno));
curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2);
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
if(!file_info.st_size) {
curl_mfprintf(stderr, "File %s has zero size!\n", libtest_arg2);
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_MAJOR_BAD;
}
test_cleanup:
/* close the local file */
- fclose(hd_src);
+ curlx_fclose(hd_src);
curl_easy_cleanup(curl);
curl_global_cleanup();
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
&content_length);
- moo = fopen(libtest_arg2, "wb");
+ moo = curlx_fopen(libtest_arg2, "wb");
if(moo) {
curl_mfprintf(moo, "CL %.0f\n", content_length);
- fclose(moo);
+ curlx_fclose(moo);
}
}
fstat(sdp, &file_info);
close(sdp);
- sdpf = fopen(libtest_arg2, "rb");
+ sdpf = curlx_fopen(libtest_arg2, "rb");
if(!sdpf) {
curl_mfprintf(stderr, "can't fopen %s\n", libtest_arg2);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
test_setopt(curl, CURLOPT_UPLOAD, 0L);
- fclose(sdpf);
+ curlx_fclose(sdpf);
sdpf = NULL;
/* Make sure we can do a normal request now */
test_cleanup:
if(sdpf)
- fclose(sdpf);
+ curlx_fclose(sdpf);
curl_free(stream_uri);
int request = 1;
int i;
- FILE *idfile = fopen(libtest_arg2, "wb");
+ FILE *idfile = curlx_fopen(libtest_arg2, "wb");
if(!idfile) {
curl_mfprintf(stderr, "couldn't open the Session ID File\n");
return TEST_ERR_MAJOR_BAD;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
- fclose(idfile);
+ curlx_fclose(idfile);
return TEST_ERR_MAJOR_BAD;
}
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
curl_global_cleanup();
- fclose(idfile);
+ curlx_fclose(idfile);
return TEST_ERR_MAJOR_BAD;
}
test_cleanup:
if(idfile)
- fclose(idfile);
+ curlx_fclose(idfile);
curl_free(stream_uri);
curl_easy_cleanup(curl);
char *stream_uri = NULL;
int request = 1;
- FILE *protofile = fopen(libtest_arg2, "wb");
+ FILE *protofile = curlx_fopen(libtest_arg2, "wb");
if(!protofile) {
curl_mfprintf(stderr, "Couldn't open the protocol dump file\n");
return TEST_ERR_MAJOR_BAD;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
- fclose(protofile);
+ curlx_fclose(protofile);
return TEST_ERR_MAJOR_BAD;
}
curl = curl_easy_init();
if(!curl) {
curl_mfprintf(stderr, "curl_easy_init() failed\n");
- fclose(protofile);
+ curlx_fclose(protofile);
curl_global_cleanup();
return TEST_ERR_MAJOR_BAD;
}
curl_free(stream_uri);
if(protofile)
- fclose(protofile);
+ curlx_fclose(protofile);
curl_easy_cleanup(curl);
curl_global_cleanup();
fstat(params, &file_info);
close(params);
- paramsf = fopen(libtest_arg2, "rb");
+ paramsf = curlx_fopen(libtest_arg2, "rb");
if(!paramsf) {
curl_mfprintf(stderr, "can't fopen %s\n", libtest_arg2);
res = TEST_ERR_MAJOR_BAD;
goto test_cleanup;
test_setopt(curl, CURLOPT_UPLOAD, 0L);
- fclose(paramsf);
+ curlx_fclose(paramsf);
paramsf = NULL;
/* Heartbeat GET_PARAMETERS */
test_cleanup:
if(paramsf)
- fclose(paramsf);
+ curlx_fclose(paramsf);
curl_free(stream_uri);
static int t578_progress_callback(void *clientp, double dltotal, double dlnow,
double ultotal, double ulnow)
{
- FILE *moo = fopen(libtest_arg2, "wb");
+ FILE *moo = curlx_fopen(libtest_arg2, "wb");
(void)clientp;
(void)dltotal;
else
curl_mfprintf(moo, "Progress callback called with UL %f out of %f\n",
ulnow, ultotal);
- fclose(moo);
+ curlx_fclose(moo);
}
return 0;
}
static void progress_final_report(void)
{
- FILE *moo = fopen(libtest_arg2, "ab");
+ FILE *moo = curlx_fopen(libtest_arg2, "ab");
curl_mfprintf(moo ? moo : stderr, "Progress: end UL %zu/%zu\n",
last_ul, last_ul_total);
if(moo)
- fclose(moo);
+ curlx_fclose(moo);
else
curl_mfprintf(stderr, "Progress: end UL, can't open %s\n", libtest_arg2);
started = FALSE;
last_ul = (size_t)ulnow;
last_ul_total = (size_t)ultotal;
if(!started) {
- FILE *moo = fopen(libtest_arg2, "ab");
+ FILE *moo = curlx_fopen(libtest_arg2, "ab");
curl_mfprintf(moo ? moo : stderr, "Progress: start UL %zu/%zu\n",
last_ul, last_ul_total);
if(moo)
- fclose(moo);
+ curlx_fclose(moo);
else
curl_mfprintf(stderr, "Progress: start UL, can't open %s\n",
libtest_arg2);
return TEST_ERR_USAGE;
}
- hd_src = fopen(libtest_arg2, "rb");
+ hd_src = curlx_fopen(libtest_arg2, "rb");
if(!hd_src) {
curl_mfprintf(stderr, "fopen() failed with error (%d) %s\n",
errno, strerror(errno));
curl_mfprintf(stderr, "fstat() failed with error (%d) %s\n",
errno, strerror(errno));
curl_mfprintf(stderr, "Error opening file '%s'\n", libtest_arg2);
- fclose(hd_src);
+ curlx_fclose(hd_src);
return TEST_ERR_FSTAT;
}
curl_mfprintf(stderr, "Set to upload %" CURL_FORMAT_CURL_OFF_T " bytes\n",
res_global_init(CURL_GLOBAL_ALL);
if(res != CURLE_OK) {
- fclose(hd_src);
+ curlx_fclose(hd_src);
return res;
}
curl_global_cleanup();
/* close the local file */
- fclose(hd_src);
+ curlx_fclose(hd_src);
/* free local memory */
free(sockets.read.sockets);
start_test_timing();
- upload = fopen(libtest_arg3, "rb");
+ upload = curlx_fopen(libtest_arg3, "rb");
if(!upload) {
curl_mfprintf(stderr, "fopen() failed with error (%d) %s\n",
errno, strerror(errno));
res_global_init(CURL_GLOBAL_ALL);
if(res) {
- fclose(upload);
+ curlx_fclose(upload);
return res;
}
curl_global_cleanup();
/* close the local file */
- fclose(upload);
+ curlx_fclose(upload);
return res;
}
FILE *moo;
res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
&content_length);
- moo = fopen(libtest_arg2, "wb");
+ moo = curlx_fopen(libtest_arg2, "wb");
if(moo) {
curl_mfprintf(moo, "CL %.0f\n", content_length);
- fclose(moo);
+ curlx_fclose(moo);
}
}
size_t datasize = 0;
void *data = NULL;
if(filename) {
- FILE *fInCert = fopen(filename, "rb");
+ FILE *fInCert = curlx_fopen(filename, "rb");
if(fInCert) {
long cert_tell = 0;
if((!data) ||
((int)fread(data, datasize, 1, fInCert) != 1))
continue_reading = FALSE;
- fclose(fInCert);
+ curlx_fclose(fInCert);
if(!continue_reading) {
free(data);
datasize = 0;
allowfunc accept
+allowfunc fclose
+allowfunc fopen
allowfunc freeaddrinfo
allowfunc getaddrinfo
allowfunc recv
CURLX_C = \
../../lib/curlx/base64.c \
+ ../../lib/curlx/fopen.c \
../../lib/curlx/inet_pton.c \
../../lib/curlx/inet_ntop.c \
../../lib/curlx/multibyte.c \
char *line;
curlx_dyn_init(&buf, len);
- fp = fopen(arg, "wb");
+ fp = curlx_fopen(arg, "wb");
abort_unless(fp != NULL, "Cannot open testfile");
fwrite(filecontents[i], 1, strlen(filecontents[i]), fp);
- fclose(fp);
+ curlx_fclose(fp);
- fp = fopen(arg, "rb");
+ fp = curlx_fopen(arg, "rb");
abort_unless(fp != NULL, "Cannot open testfile");
curl_mfprintf(stderr, "Test %zd...", i);
break;
}
curlx_dyn_free(&buf);
- fclose(fp);
+ curlx_fclose(fp);
curl_mfprintf(stderr, "OK\n");
}
return (CURLcode)rc;