Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 791bfda

Browse files
committed
Autocheck for snprintf, and use sprintf if it is not available.
Remove declaration of h_errno, since it is supposedly declared in netdb.h. Changes proposed by itojun.
1 parent c547b46 commit 791bfda

5 files changed

Lines changed: 14 additions & 10 deletions

File tree

Modules/getaddrinfo.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,6 @@ get_addr(hostname, af, res, pai, port0)
544544
struct gai_afd *gai_afd;
545545
int i, error = 0, h_error;
546546
char *ap;
547-
#if !defined(INET6) && !defined(h_errno)
548-
/* In winsock.h, h_errno is #defined as a function call. */
549-
extern int h_errno;
550-
#endif
551547

552548
top = NULL;
553549
sentinel.ai_next = NULL;

Modules/socketmodule.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,9 +1789,6 @@ gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af)
17891789

17901790
if (h == NULL) {
17911791
/* Let's get real error message to return */
1792-
#ifndef h_errno
1793-
extern int h_errno;
1794-
#endif
17951792
PyH_Err(h_errno);
17961793
return NULL;
17971794
}
@@ -2348,7 +2345,11 @@ PySocket_getaddrinfo(PyObject *self, PyObject *args)
23482345
return NULL;
23492346
}
23502347
if (PyInt_Check(pobj)) {
2348+
#ifndef HAVE_SNPRINTF
2349+
sprintf(pbuf, "%ld", PyInt_AsLong(pobj));
2350+
#else
23512351
snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
2352+
#endif
23522353
pptr = pbuf;
23532354
} else if (PyString_Check(pobj)) {
23542355
pptr = PyString_AsString(pobj);
@@ -2419,7 +2420,11 @@ PySocket_getnameinfo(PyObject *self, PyObject *args)
24192420
n = PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, scope_id);
24202421
if (n == 0)
24212422
goto fail;
2423+
#ifdef HAVE_SPRINTF
24222424
snprintf(pbuf, sizeof(pbuf), "%d", port);
2425+
#else
2426+
sprintf(pbuf, "%d", port);
2427+
#endif
24232428
memset(&hints, 0, sizeof(hints));
24242429
hints.ai_family = PF_UNSPEC;
24252430
error = getaddrinfo(hostp, pbuf, &hints, &res);

config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,9 @@
509509
/* Define if you have the sigrelse function. */
510510
#undef HAVE_SIGRELSE
511511

512+
/* Define if you have the snprintf function. */
513+
#undef HAVE_SNPRINTF
514+
512515
/* Define if you have the statvfs function. */
513516
#undef HAVE_STATVFS
514517

configure

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/sh
22

3-
# From configure.in Revision: 1.232
3+
# From configure.in Revision: 1.233
44

55
# Guess values for system-dependent variables and create Makefiles.
66
# Generated automatically using autoconf version 2.13
@@ -4519,7 +4519,7 @@ for ac_func in alarm chown clock confstr ctermid ctermid_r execv \
45194519
nice pathconf pause plock poll pthread_init \
45204520
putenv readlink \
45214521
select setegid seteuid setgid \
4522-
setlocale setregid setreuid setsid setpgid setuid setvbuf \
4522+
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
45234523
sigaction siginterrupt sigrelse strftime strptime symlink sysconf \
45244524
tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
45254525
truncate uname waitpid _getpty getpriority

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ AC_CHECK_FUNCS(alarm chown clock confstr ctermid ctermid_r execv \
11791179
nice pathconf pause plock poll pthread_init \
11801180
putenv readlink \
11811181
select setegid seteuid setgid \
1182-
setlocale setregid setreuid setsid setpgid setuid setvbuf \
1182+
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
11831183
sigaction siginterrupt sigrelse strftime strptime symlink sysconf \
11841184
tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
11851185
truncate uname waitpid _getpty getpriority)

0 commit comments

Comments
 (0)