mirror of
https://github.com/curl/curl.git
synced 2026-07-30 20:58:06 +03:00
curlx: dedupe basename copies into curlx_basename()
Also stop redefining system `basename()` symbol. Call `curlx_basename()` instead, and map that to `basename()` if available. Closes #20424
This commit is contained in:
parent
0e2507a3c6
commit
6974bd7cc8
7 changed files with 54 additions and 79 deletions
|
|
@ -34,6 +34,7 @@
|
|||
# the official API, but we reuse the code here to avoid duplication.
|
||||
CURLX_CFILES = \
|
||||
../lib/curlx/base64.c \
|
||||
../lib/curlx/basename.c \
|
||||
../lib/curlx/dynbuf.c \
|
||||
../lib/curlx/fopen.c \
|
||||
../lib/curlx/multibyte.c \
|
||||
|
|
@ -76,7 +77,6 @@ CURL_CFILES = \
|
|||
config2setopts.c \
|
||||
slist_wc.c \
|
||||
terminal.c \
|
||||
tool_bname.c \
|
||||
tool_cb_dbg.c \
|
||||
tool_cb_hdr.c \
|
||||
tool_cb_prg.c \
|
||||
|
|
@ -122,7 +122,6 @@ CURL_HFILES = \
|
|||
config2setopts.h \
|
||||
slist_wc.h \
|
||||
terminal.h \
|
||||
tool_bname.h \
|
||||
tool_cb_dbg.h \
|
||||
tool_cb_hdr.h \
|
||||
tool_cb_prg.h \
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* 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 "tool_setup.h"
|
||||
|
||||
#ifndef HAVE_BASENAME
|
||||
|
||||
#include "tool_bname.h"
|
||||
|
||||
char *tool_basename(char *path)
|
||||
{
|
||||
char *s1;
|
||||
char *s2;
|
||||
|
||||
s1 = strrchr(path, '/');
|
||||
s2 = strrchr(path, '\\');
|
||||
|
||||
if(s1 && s2) {
|
||||
path = (s1 > s2) ? s1 + 1 : s2 + 1;
|
||||
}
|
||||
else if(s1)
|
||||
path = s1 + 1;
|
||||
else if(s2)
|
||||
path = s2 + 1;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif /* HAVE_BASENAME */
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#ifndef HEADER_CURL_TOOL_BNAME_H
|
||||
#define HEADER_CURL_TOOL_BNAME_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 "tool_setup.h"
|
||||
|
||||
#ifndef HAVE_BASENAME
|
||||
|
||||
char *tool_basename(char *path);
|
||||
|
||||
#define basename(x) tool_basename(x)
|
||||
|
||||
#endif /* HAVE_BASENAME */
|
||||
|
||||
#endif /* HEADER_CURL_TOOL_BNAME_H */
|
||||
|
|
@ -25,10 +25,6 @@
|
|||
|
||||
#if defined(_WIN32) || defined(MSDOS)
|
||||
|
||||
#if defined(HAVE_LIBGEN_H) && defined(HAVE_BASENAME)
|
||||
# include <libgen.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <tlhelp32.h>
|
||||
# undef PATH_MAX
|
||||
|
|
@ -41,7 +37,6 @@
|
|||
#endif
|
||||
|
||||
#include "tool_cfgable.h"
|
||||
#include "tool_bname.h"
|
||||
#include "tool_doswin.h"
|
||||
#include "tool_msgs.h"
|
||||
|
||||
|
|
@ -327,7 +322,7 @@ static SANITIZEcode rename_if_reserved_dos(char ** const sanitized,
|
|||
|
||||
memcpy(buffer, file_name, len + 1);
|
||||
|
||||
base = basename(buffer);
|
||||
base = curlx_basename(buffer);
|
||||
|
||||
/* Rename reserved device names that are known to be accessible without \\.\
|
||||
Examples: CON => _CON, CON.EXT => CON_EXT, CON:ADS => CON_ADS
|
||||
|
|
@ -378,7 +373,7 @@ static SANITIZEcode rename_if_reserved_dos(char ** const sanitized,
|
|||
|
||||
/* the basename pointer must be updated since the path has expanded */
|
||||
if(p == buffer)
|
||||
base = basename(buffer);
|
||||
base = curlx_basename(buffer);
|
||||
}
|
||||
|
||||
/* This is the legacy portion from rename_if_dos_device_name that checks for
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue