comparison Modules/socketmodule.c @ 18818:cebb4e187449 legacy-trunk

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.
author Martin v. Löwis <martin@v.loewis.de>
date Tue, 24 Jul 2001 06:33:08 +0000
parents 6d9874bb978f
children 4677d2ff3150
comparison
equal deleted inserted replaced
18817:315b3cb127c0 18818:cebb4e187449
1787 PyObject *addr_list = (PyObject *)NULL; 1787 PyObject *addr_list = (PyObject *)NULL;
1788 PyObject *tmp; 1788 PyObject *tmp;
1789 1789
1790 if (h == NULL) { 1790 if (h == NULL) {
1791 /* Let's get real error message to return */ 1791 /* Let's get real error message to return */
1792 #ifndef h_errno
1793 extern int h_errno;
1794 #endif
1795 PyH_Err(h_errno); 1792 PyH_Err(h_errno);
1796 return NULL; 1793 return NULL;
1797 } 1794 }
1798 if (h->h_addrtype != af) { 1795 if (h->h_addrtype != af) {
1799 #ifdef HAVE_STRERROR 1796 #ifdef HAVE_STRERROR
2346 &hptr, &pobj, &family, &socktype, 2343 &hptr, &pobj, &family, &socktype,
2347 &protocol, &flags)) { 2344 &protocol, &flags)) {
2348 return NULL; 2345 return NULL;
2349 } 2346 }
2350 if (PyInt_Check(pobj)) { 2347 if (PyInt_Check(pobj)) {
2348 #ifndef HAVE_SNPRINTF
2349 sprintf(pbuf, "%ld", PyInt_AsLong(pobj));
2350 #else
2351 snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj)); 2351 snprintf(pbuf, sizeof(pbuf), "%ld", PyInt_AsLong(pobj));
2352 #endif
2352 pptr = pbuf; 2353 pptr = pbuf;
2353 } else if (PyString_Check(pobj)) { 2354 } else if (PyString_Check(pobj)) {
2354 pptr = PyString_AsString(pobj); 2355 pptr = PyString_AsString(pobj);
2355 } else if (pobj == Py_None) { 2356 } else if (pobj == Py_None) {
2356 pptr = (char *)NULL; 2357 pptr = (char *)NULL;
2417 if (PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags) == 0) 2418 if (PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags) == 0)
2418 return NULL; 2419 return NULL;
2419 n = PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, scope_id); 2420 n = PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, scope_id);
2420 if (n == 0) 2421 if (n == 0)
2421 goto fail; 2422 goto fail;
2423 #ifdef HAVE_SPRINTF
2422 snprintf(pbuf, sizeof(pbuf), "%d", port); 2424 snprintf(pbuf, sizeof(pbuf), "%d", port);
2425 #else
2426 sprintf(pbuf, "%d", port);
2427 #endif
2423 memset(&hints, 0, sizeof(hints)); 2428 memset(&hints, 0, sizeof(hints));
2424 hints.ai_family = PF_UNSPEC; 2429 hints.ai_family = PF_UNSPEC;
2425 error = getaddrinfo(hostp, pbuf, &hints, &res); 2430 error = getaddrinfo(hostp, pbuf, &hints, &res);
2426 if (error) { 2431 if (error) {
2427 PyGAI_Err(error); 2432 PyGAI_Err(error);