Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit683be87

Browse files
committed
Add port/ replacement for strsep()
from OpenBSD, similar to strlcat, strlcpyThere are currently no uses, but some will be added soon.Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>Reviewed-by: David Steele <david@pgmasters.net>Discussion:https://www.postgresql.org/message-id/flat/79692bf9-17d3-41e6-b9c9-fc8c3944222a@eisentraut.org
1 parent7e187a7 commit683be87

File tree

7 files changed

+116
-1
lines changed

7 files changed

+116
-1
lines changed

‎configure

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15778,6 +15778,16 @@ fi
1577815778
cat >>confdefs.h <<_ACEOF
1577915779
#define HAVE_DECL_STRNLEN $ac_have_decl
1578015780
_ACEOF
15781+
ac_fn_c_check_decl "$LINENO" "strsep" "ac_cv_have_decl_strsep" "$ac_includes_default"
15782+
if test "x$ac_cv_have_decl_strsep" = xyes; then :
15783+
ac_have_decl=1
15784+
else
15785+
ac_have_decl=0
15786+
fi
15787+
15788+
cat >>confdefs.h <<_ACEOF
15789+
#define HAVE_DECL_STRSEP $ac_have_decl
15790+
_ACEOF
1578115791

1578215792

1578315793
# We can't use AC_CHECK_FUNCS to detect these functions, because it
@@ -15925,6 +15935,19 @@ esac
1592515935

1592615936
fi
1592715937

15938+
ac_fn_c_check_func "$LINENO" "strsep" "ac_cv_func_strsep"
15939+
if test "x$ac_cv_func_strsep" = xyes; then :
15940+
$as_echo "#define HAVE_STRSEP 1" >>confdefs.h
15941+
15942+
else
15943+
case " $LIBOBJS " in
15944+
*" strsep.$ac_objext "* ) ;;
15945+
*) LIBOBJS="$LIBOBJS strsep.$ac_objext"
15946+
;;
15947+
esac
15948+
15949+
fi
15950+
1592815951

1592915952

1593015953
ac_fn_c_check_func "$LINENO" "pthread_barrier_wait" "ac_cv_func_pthread_barrier_wait"

‎configure.ac

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
17951795
])# fi
17961796

17971797
AC_CHECK_DECLS(fdatasync,[],[],[#include <unistd.h>])
1798-
AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
1798+
AC_CHECK_DECLS([strlcat, strlcpy, strnlen, strsep])
17991799

18001800
# We can't use AC_CHECK_FUNCS to detect these functions, because it
18011801
# won't handle deployment target restrictions on macOS
@@ -1814,6 +1814,7 @@ AC_REPLACE_FUNCS(m4_normalize([
18141814
strlcat
18151815
strlcpy
18161816
strnlen
1817+
strsep
18171818
]))
18181819

18191820
AC_REPLACE_FUNCS(pthread_barrier_wait)

‎meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,7 @@ decl_checks = [
24172417
['strlcat','string.h'],
24182418
['strlcpy','string.h'],
24192419
['strnlen','string.h'],
2420+
['strsep','string.h'],
24202421
]
24212422

24222423
# Need to check for function declarations for these functions, because
@@ -2685,6 +2686,7 @@ func_checks = [
26852686
['strlcat'],
26862687
['strlcpy'],
26872688
['strnlen'],
2689+
['strsep'],
26882690
['strsignal'],
26892691
['sync_file_range'],
26902692
['syncfs'],

‎src/include/pg_config.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@
127127
don't. */
128128
#undef HAVE_DECL_STRNLEN
129129

130+
/* Define to 1 if you have the declaration of `strsep', and to 0 if you don't.
131+
*/
132+
#undef HAVE_DECL_STRSEP
133+
130134
/* Define to 1 if you have the <editline/history.h> header file. */
131135
#undef HAVE_EDITLINE_HISTORY_H
132136

@@ -414,6 +418,9 @@
414418
/* Define to 1 if you have the `strnlen' function. */
415419
#undef HAVE_STRNLEN
416420

421+
/* Define to 1 if you have the `strsep' function. */
422+
#undef HAVE_STRSEP
423+
417424
/* Define to 1 if you have the `strsignal' function. */
418425
#undef HAVE_STRSIGNAL
419426

‎src/include/port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ extern size_t strlcpy(char *dst, const char *src, size_t siz);
432432
externsize_tstrnlen(constchar*str,size_tmaxlen);
433433
#endif
434434

435+
#if !HAVE_DECL_STRSEP
436+
externchar*strsep(char**stringp,constchar*delim);
437+
#endif
438+
435439
/* port/user.c */
436440
#ifndefWIN32
437441
externboolpg_get_user_name(uid_tuser_id,char*buffer,size_tbuflen);

‎src/port/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ replace_funcs_neg = [
7070
['strlcat'],
7171
['strlcpy'],
7272
['strnlen'],
73+
['strsep'],
7374
]
7475

7576
if host_system!='windows'

‎src/port/strsep.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* src/port/strsep.c
3+
*
4+
*$OpenBSD: strsep.c,v 1.8 2015/08/31 02:53:57 guenther Exp $*/
5+
6+
/*-
7+
* Copyright (c) 1990, 1993
8+
*The Regents of the University of California. All rights reserved.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in the
17+
* documentation and/or other materials provided with the distribution.
18+
* 3. Neither the name of the University nor the names of its contributors
19+
* may be used to endorse or promote products derived from this software
20+
* without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32+
* SUCH DAMAGE.
33+
*/
34+
35+
#include"c.h"
36+
37+
/*
38+
* Get next token from string *stringp, where tokens are possibly-empty
39+
* strings separated by characters from delim.
40+
*
41+
* Writes NULs into the string at *stringp to end tokens.
42+
* delim need not remain constant from call to call.
43+
* On return, *stringp points past the last NUL written (if there might
44+
* be further tokens), or is NULL (if there are definitely no more tokens).
45+
*
46+
* If *stringp is NULL, strsep returns NULL.
47+
*/
48+
char*
49+
strsep(char**stringp,constchar*delim)
50+
{
51+
char*s;
52+
constchar*spanp;
53+
intc,
54+
sc;
55+
char*tok;
56+
57+
if ((s=*stringp)==NULL)
58+
return (NULL);
59+
for (tok=s;;)
60+
{
61+
c=*s++;
62+
spanp=delim;
63+
do
64+
{
65+
if ((sc=*spanp++)==c)
66+
{
67+
if (c==0)
68+
s=NULL;
69+
else
70+
s[-1]=0;
71+
*stringp=s;
72+
return (tok);
73+
}
74+
}while (sc!=0);
75+
}
76+
/* NOTREACHED */
77+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp