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

Commit4f64a07

Browse files
committed
Add strlcat() from OpenBSD, to be used for replacing strncat and other
strange coding practices.
1 parent5b706ba commit4f64a07

File tree

6 files changed

+144
-7
lines changed

6 files changed

+144
-7
lines changed

‎configure

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13973,6 +13973,76 @@ _ACEOF
1397313973
fi
1397413974

1397513975

13976+
echo "$as_me:$LINENO: checking whether strlcat is declared" >&5
13977+
echo $ECHO_N "checking whether strlcat is declared... $ECHO_C" >&6
13978+
if test "${ac_cv_have_decl_strlcat+set}" = set; then
13979+
echo $ECHO_N "(cached) $ECHO_C" >&6
13980+
else
13981+
cat >conftest.$ac_ext <<_ACEOF
13982+
/* confdefs.h. */
13983+
_ACEOF
13984+
cat confdefs.h >>conftest.$ac_ext
13985+
cat >>conftest.$ac_ext <<_ACEOF
13986+
/* end confdefs.h. */
13987+
$ac_includes_default
13988+
int
13989+
main ()
13990+
{
13991+
#ifndef strlcat
13992+
char *p = (char *) strlcat;
13993+
#endif
13994+
13995+
;
13996+
return 0;
13997+
}
13998+
_ACEOF
13999+
rm -f conftest.$ac_objext
14000+
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
14001+
(eval $ac_compile) 2>conftest.er1
14002+
ac_status=$?
14003+
grep -v '^ *+' conftest.er1 >conftest.err
14004+
rm -f conftest.er1
14005+
cat conftest.err >&5
14006+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
14007+
(exit $ac_status); } &&
14008+
{ ac_try='test -z "$ac_c_werror_flag"
14009+
|| test ! -s conftest.err'
14010+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
14011+
(eval $ac_try) 2>&5
14012+
ac_status=$?
14013+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
14014+
(exit $ac_status); }; } &&
14015+
{ ac_try='test -s conftest.$ac_objext'
14016+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
14017+
(eval $ac_try) 2>&5
14018+
ac_status=$?
14019+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
14020+
(exit $ac_status); }; }; then
14021+
ac_cv_have_decl_strlcat=yes
14022+
else
14023+
echo "$as_me: failed program was:" >&5
14024+
sed 's/^/| /' conftest.$ac_ext >&5
14025+
14026+
ac_cv_have_decl_strlcat=no
14027+
fi
14028+
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
14029+
fi
14030+
echo "$as_me:$LINENO: result: $ac_cv_have_decl_strlcat" >&5
14031+
echo "${ECHO_T}$ac_cv_have_decl_strlcat" >&6
14032+
if test $ac_cv_have_decl_strlcat = yes; then
14033+
14034+
cat >>confdefs.h <<_ACEOF
14035+
#define HAVE_DECL_STRLCAT 1
14036+
_ACEOF
14037+
14038+
14039+
else
14040+
cat >>confdefs.h <<_ACEOF
14041+
#define HAVE_DECL_STRLCAT 0
14042+
_ACEOF
14043+
14044+
14045+
fi
1397614046
echo "$as_me:$LINENO: checking whether strlcpy is declared" >&5
1397714047
echo $ECHO_N "checking whether strlcpy is declared... $ECHO_C" >&6
1397814048
if test "${ac_cv_have_decl_strlcpy+set}" = set; then
@@ -14850,7 +14920,8 @@ LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
1485014920

1485114921

1485214922

14853-
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strdup strerror strlcpy strtol strtoul unsetenv
14923+
14924+
for ac_func in crypt fseeko getopt getrusage inet_aton random rint srandom strdup strerror strlcat strlcpy strtol strtoul unsetenv
1485414925
do
1485514926
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
1485614927
echo "$as_me:$LINENO: checking for $ac_func" >&5

‎configure.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.500 2007/02/03 02:43:38 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.501 2007/02/07 00:28:54 petere Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -905,7 +905,7 @@ AC_CHECK_FUNCS([cbrt dlopen fcvt fdatasync getpeereid getrlimit memmove poll pst
905905

906906
AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
907907
AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
908-
AC_CHECK_DECLS(strlcpy)
908+
AC_CHECK_DECLS([strlcat,strlcpy])
909909
# This is probably only present on Darwin, but may as well check always
910910
AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
911911

@@ -1002,7 +1002,7 @@ fi
10021002
pgac_save_LIBS="$LIBS"
10031003
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
10041004

1005-
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strdup strerror strlcpy strtol strtoul unsetenv])
1005+
AC_REPLACE_FUNCS([crypt fseeko getopt getrusage inet_aton random rint srandom strdup strerrorstrlcatstrlcpy strtol strtoul unsetenv])
10061006

10071007
LIBS="$pgac_save_LIBS"
10081008

‎src/bin/pg_config/pg_config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1919
*
20-
* $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.23 2007/01/05 22:19:48 momjian Exp $
20+
* $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.24 2007/02/07 00:28:54 petere Exp $
2121
*
2222
*-------------------------------------------------------------------------
2323
*/
@@ -213,7 +213,7 @@ show_pgxs(bool all)
213213
if (all)
214214
printf("PGXS = ");
215215
get_pkglib_path(mypath,path);
216-
strncat(path,"/pgxs/src/makefiles/pgxs.mk",MAXPGPATH-1-strlen(path));
216+
strlcat(path,"/pgxs/src/makefiles/pgxs.mk",sizeof(path));
217217
cleanup_path(path);
218218
printf("%s\n",path);
219219
}

‎src/include/pg_config.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
don't. */
8888
#undef HAVE_DECL_SNPRINTF
8989

90+
/* Define to 1 if you have the declaration of `strlcat', and to 0 if you
91+
don't. */
92+
#undef HAVE_DECL_STRLCAT
93+
9094
/* Define to 1 if you have the declaration of `strlcpy', and to 0 if you
9195
don't. */
9296
#undef HAVE_DECL_STRLCPY
@@ -389,6 +393,9 @@
389393
/* Define to 1 if you have the <string.h> header file. */
390394
#undef HAVE_STRING_H
391395

396+
/* Define to 1 if you have the `strlcat' function. */
397+
#undef HAVE_STRLCAT
398+
392399
/* Define to 1 if you have the `strlcpy' function. */
393400
#undef HAVE_STRLCPY
394401

‎src/include/port.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.109 2007/01/19 16:42:24 alvherre Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.110 2007/02/07 00:28:55 petere Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -343,6 +343,10 @@ extern intinet_aton(const char *cp, struct in_addr * addr);
343343
externchar*strdup(constchar*str);
344344
#endif
345345

346+
#if !HAVE_DECL_STRLCAT
347+
externsize_tstrlcat(char*dst,constchar*src,size_tsiz);
348+
#endif
349+
346350
#if !HAVE_DECL_STRLCPY
347351
externsize_tstrlcpy(char*dst,constchar*src,size_tsiz);
348352
#endif

‎src/port/strlcat.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*$OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $*/
2+
3+
/*
4+
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
5+
*
6+
* Permission to use, copy, modify, and distribute this software for any
7+
* purpose with or without fee is hereby granted, provided that the above
8+
* copyright notice and this permission notice appear in all copies.
9+
*
10+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17+
*/
18+
19+
#include"c.h"
20+
21+
22+
/*
23+
* Appends src to string dst of size siz (unlike strncat, siz is the
24+
* full size of dst, not space left). At most siz-1 characters
25+
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
26+
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
27+
* If retval >= siz, truncation occurred.
28+
*/
29+
size_t
30+
strlcat(char*dst,constchar*src,size_tsiz)
31+
{
32+
char*d=dst;
33+
constchar*s=src;
34+
size_tn=siz;
35+
size_tdlen;
36+
37+
/* Find the end of dst and adjust bytes left but don't go past end */
38+
while (n--!=0&&*d!='\0')
39+
d++;
40+
dlen=d-dst;
41+
n=siz-dlen;
42+
43+
if (n==0)
44+
return(dlen+strlen(s));
45+
while (*s!='\0') {
46+
if (n!=1) {
47+
*d++=*s;
48+
n--;
49+
}
50+
s++;
51+
}
52+
*d='\0';
53+
54+
return(dlen+ (s-src));/* count does not include NUL */
55+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp