1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

libcurl private function Curl_memrchr() now in curl_memrchr.c and curl_memrchr.h

This commit is contained in:
Yang Tse 2009-09-28 16:05:20 +00:00
parent b64dd3c63d
commit 7d22ce5573
10 changed files with 134 additions and 24 deletions

View File

@ -70,7 +70,7 @@ OBJS = $(OBJ_DIR)\base64.obj $(OBJ_DIR)\connect.obj &
$(OBJ_DIR)\timeval.obj $(OBJ_DIR)\transfer.obj & $(OBJ_DIR)\timeval.obj $(OBJ_DIR)\transfer.obj &
$(OBJ_DIR)\url.obj $(OBJ_DIR)\version.obj & $(OBJ_DIR)\url.obj $(OBJ_DIR)\version.obj &
$(OBJ_DIR)\slist.obj $(OBJ_DIR)\nonblock.obj & $(OBJ_DIR)\slist.obj $(OBJ_DIR)\nonblock.obj &
$(OBJ_DIR)\curl_rand.obj $(OBJ_DIR)\curl_rand.obj $(OBJ_DIR)\curl_memrchr.obj
# #
# Use $(OBJS) as a template to generate $(OBJS_STAT) and $(OBJS_DYN). # Use $(OBJS) as a template to generate $(OBJS_STAT) and $(OBJS_DYN).
@ -194,7 +194,7 @@ $(OBJ_DIR)\cookie.obj: cookie.c setup.h config-win32.h ..\include\curl\curlbuild
..\include\curl\multi.h urldata.h cookie.h ..\include\curl\curl.h & ..\include\curl\multi.h urldata.h cookie.h ..\include\curl\curl.h &
formdata.h timeval.h http_chunks.h hostip.h hash.h llist.h & formdata.h timeval.h http_chunks.h hostip.h hash.h llist.h &
curl_addrinfo.h splay.h strequal.h strtok.h sendf.h curl_memory.h share.h & curl_addrinfo.h splay.h strequal.h strtok.h sendf.h curl_memory.h share.h &
strtoofft.h rawstr.h memdebug.h strtoofft.h rawstr.h memdebug.h curl_memrchr.h
$(OBJ_DIR)\http.obj: http.c setup.h config-win32.h ..\include\curl\curlbuild.h & $(OBJ_DIR)\http.obj: http.c setup.h config-win32.h ..\include\curl\curlbuild.h &
..\include\curl\curlrules.h setup_once.h urldata.h cookie.h & ..\include\curl\curlrules.h setup_once.h urldata.h cookie.h &
..\include\curl\curl.h ..\include\curl\curlver.h & ..\include\curl\curl.h ..\include\curl\curlver.h &
@ -548,3 +548,9 @@ $(OBJ_DIR)\curl_rand.obj: curl_rand.c setup.h config-win32.h &
..\include\curl\curlrules.h ..\include\curl\easy.h & ..\include\curl\curlrules.h ..\include\curl\easy.h &
..\include\curl\multi.h ..\include\curl\curl.h curl_rand.h & ..\include\curl\multi.h ..\include\curl\curl.h curl_rand.h &
..\include\curl\mprintf.h curl_memory.h memdebug.h ..\include\curl\mprintf.h curl_memory.h memdebug.h
$(OBJ_DIR)\curl_memrchr.obj: curl_memrchr.c setup.h config-win32.h &
..\include\curl\curlbuild.h ..\include\curl\curlrules.h setup_once.h &
..\include\curl\curl.h ..\include\curl\curlver.h &
..\include\curl\curlrules.h ..\include\curl\easy.h &
..\include\curl\multi.h ..\include\curl\curl.h curl_memrchr.h &
..\include\curl\mprintf.h curl_memory.h memdebug.h

View File

@ -10,7 +10,8 @@ CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
hostares.c hostasyn.c hostip4.c hostip6.c hostsyn.c hostthre.c \ hostares.c hostasyn.c hostip4.c hostip6.c hostsyn.c hostthre.c \
inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c \ inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c \
strdup.c socks.c ssh.c nss.c qssl.c rawstr.c curl_addrinfo.c \ strdup.c socks.c ssh.c nss.c qssl.c rawstr.c curl_addrinfo.c \
socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c \
curl_memrchr.c
HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h \ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h \
progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h \ progress.h formdata.h cookie.h http.h sendf.h ftp.h url.h dict.h \
@ -21,4 +22,6 @@ HHEADERS = arpa_telnet.h netrc.h file.h timeval.h qssl.h hostip.h \
strtoofft.h strerror.h inet_ntop.h curlx.h curl_memory.h setup.h \ strtoofft.h strerror.h inet_ntop.h curlx.h curl_memory.h setup.h \
transfer.h select.h easyif.h multiif.h parsedate.h sslgen.h gtls.h \ transfer.h select.h easyif.h multiif.h parsedate.h sslgen.h gtls.h \
tftp.h sockaddr.h splay.h strdup.h setup_once.h socks.h ssh.h nssg.h \ tftp.h sockaddr.h splay.h strdup.h setup_once.h socks.h ssh.h nssg.h \
curl_base64.h rawstr.h curl_addrinfo.h curl_sspi.h slist.h nonblock.h curl_base64.h rawstr.h curl_addrinfo.h curl_sspi.h slist.h nonblock.h \
curl_memrchr.h

View File

@ -13,7 +13,9 @@ objs = o.base64 o.connect o.cookie o.dict \
o.security o.select o.sendf o.speedcheck o.ssluse \ o.security o.select o.sendf o.speedcheck o.ssluse \
o.strequal o.strtok o.telnet o.timeval \ o.strequal o.strtok o.telnet o.timeval \
o.transfer o.url o.version o.strtoofft o.sslgen o.gtls \ o.transfer o.url o.version o.strtoofft o.sslgen o.gtls \
o.rawstr o.curl_addrinfo o.slist o.nonblock o.curl_rand o.rawstr o.curl_addrinfo o.slist o.nonblock o.curl_rand \
o.curl_memrchr
# Compile options: # Compile options:
linkopts = -o libcurl linkopts = -o libcurl
@ -36,6 +38,9 @@ o.cookie: c.cookie
o.curl_addrinfo: c.curl_addrinfo o.curl_addrinfo: c.curl_addrinfo
gcc $(compileropts) -c -o curl_addrinfo.o c.curl_addrinfo gcc $(compileropts) -c -o curl_addrinfo.o c.curl_addrinfo
o.curl_memrchr: c.curl_memrchr
gcc $(compileropts) -c -o curl_memrchr.o c.curl_memrchr
o.curl_rand: c.curl_rand o.curl_rand: c.curl_rand
gcc $(compileropts) -c -o curl_rand.o c.curl_rand gcc $(compileropts) -c -o curl_rand.o c.curl_rand

View File

@ -450,6 +450,7 @@ X_OBJS= \
$(DIROBJ)\content_encoding.obj \ $(DIROBJ)\content_encoding.obj \
$(DIROBJ)\cookie.obj \ $(DIROBJ)\cookie.obj \
$(DIROBJ)\curl_addrinfo.obj \ $(DIROBJ)\curl_addrinfo.obj \
$(DIROBJ)\curl_memrchr.obj \
$(DIROBJ)\curl_rand.obj \ $(DIROBJ)\curl_rand.obj \
$(DIROBJ)\curl_sspi.obj \ $(DIROBJ)\curl_sspi.obj \
$(DIROBJ)\dict.obj \ $(DIROBJ)\dict.obj \

View File

@ -97,6 +97,7 @@ Example set of cookies:
#include "share.h" #include "share.h"
#include "strtoofft.h" #include "strtoofft.h"
#include "rawstr.h" #include "rawstr.h"
#include "curl_memrchr.h"
/* The last #include file should be: */ /* The last #include file should be: */
#include "memdebug.h" #include "memdebug.h"
@ -168,23 +169,6 @@ static void strstore(char **str, const char *newstr)
} }
/*
* The memrchr() function is like the memchr() function, except that it
* searches backwards from the end of the n bytes pointed to by s instead of
* forwards from the front.
*
* Exists in glibc but is not widely available on other systems.
*/
static void *memrchr(const char *s, int c, size_t n)
{
while(n--) {
if(s[n] == c)
return &s[n];
}
return NULL;
}
/**************************************************************************** /****************************************************************************
* *
* Curl_cookie_add() * Curl_cookie_add()

63
lib/curl_memrchr.c Normal file
View File

@ -0,0 +1,63 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2009, 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 http://curl.haxx.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.
*
* $Id$
***************************************************************************/
#include "setup.h"
#include "curl_memrchr.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
#ifndef HAVE_MEMRCHR
/*
* Curl_memrchr()
*
* Our memrchr() function clone for systems which lack this function. The
* memrchr() function is like the memchr() function, except that it searches
* backwards from the end of the n bytes pointed to by s instead of forward
* from the beginning.
*/
void *
Curl_memrchr(const void *s, int c, size_t n)
{
const unsigned char *p = s;
const unsigned char *q = s;
p += n - 1;
while (p >= q) {
if (*p == (unsigned char)c)
return (void *)p;
p--;
}
return NULL;
}
#endif /* HAVE_MEMRCHR */

45
lib/curl_memrchr.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef HEADER_CURL_MEMRCHR_H
#define HEADER_CURL_MEMRCHR_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2009, 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 http://curl.haxx.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.
*
* $Id$
***************************************************************************/
#include "setup.h"
#ifdef HAVE_MEMRCHR
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#else /* HAVE_MEMRCHR */
void *Curl_memrchr(const void *s, int c, size_t n);
#define memrchr(x,y,z) Curl_memrchr((x),(y),(z))
#endif /* HAVE_MEMRCHR */
#endif /* HEADER_CURL_MEMRCHR_H */

View File

@ -18,7 +18,9 @@ OBJS = amigaos.c base64.c connect.c content_encoding.c cookie.c dict.c easy.c \
progress.c security.c select.c sendf.c share.c speedcheck.c ssluse.c \ progress.c security.c select.c sendf.c share.c speedcheck.c ssluse.c \
strequal.c strtok.c telnet.c timeval.c transfer.c url.c version.c \ strequal.c strtok.c telnet.c timeval.c transfer.c url.c version.c \
sslgen.c gtls.c strerror.c rawstr.c curl_addrinfo.c curl_rand.c \ sslgen.c gtls.c strerror.c rawstr.c curl_addrinfo.c curl_rand.c \
socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c \
curl_memrchr.c
all: $(OBJS:.c=.o) all: $(OBJS:.c=.o)
ar cru libcurl.a $(OBJS:.c=.o) ar cru libcurl.a $(OBJS:.c=.o)

View File

@ -32,7 +32,7 @@ SOURCE \
inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c \ inet_ntop.c parsedate.c select.c gtls.c sslgen.c tftp.c splay.c \
strdup.c socks.c ssh.c nss.c qssl.c rawstr.c curl_addrinfo.c \ strdup.c socks.c ssh.c nss.c qssl.c rawstr.c curl_addrinfo.c \
socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c \ socks_gssapi.c socks_sspi.c curl_sspi.c slist.c nonblock.c \
curl_rand.c curl_rand.c curl_memrchr.c
USERINCLUDE ../../../lib ../../../include/curl USERINCLUDE ../../../lib ../../../include/curl
#ifdef ENABLE_SSL #ifdef ENABLE_SSL

View File

@ -35,6 +35,7 @@ C_SRC += connect.c
C_SRC += content_encoding.c C_SRC += content_encoding.c
C_SRC += cookie.c C_SRC += cookie.c
C_SRC += curl_addrinfo.c C_SRC += curl_addrinfo.c
C_SRC += curl_memrchr.c
C_SRC += curl_rand.c C_SRC += curl_rand.c
C_SRC += curl_sspi.c C_SRC += curl_sspi.c
C_SRC += dict.c C_SRC += dict.c