mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix CRT SECURE warning in winutil
This commit is contained in:
parent
c344c42a7d
commit
ac181d2198
@ -12,7 +12,7 @@ __docformat__ = 'restructuredtext en'
|
||||
Test a binary calibre build to ensure that all needed binary images/libraries have loaded.
|
||||
'''
|
||||
|
||||
import os, ctypes, sys, unittest
|
||||
import os, ctypes, sys, unittest, time
|
||||
from calibre.constants import plugins, iswindows, islinux, isosx
|
||||
is_ci = os.environ.get('CI', '').lower() == 'true'
|
||||
|
||||
@ -135,6 +135,16 @@ class BuildTest(unittest.TestCase):
|
||||
au(v, k)
|
||||
for k in os.environ.keys():
|
||||
au(winutil.getenv(unicode(k)), 'getenv-' + k)
|
||||
os.environ['XXXTEST'] = 'YYY'
|
||||
self.assertEqual(winutil.getenv(u'XXXTEST'), u'YYY')
|
||||
del os.environ['XXXTEST']
|
||||
self.assertIsNone(winutil.getenv(u'XXXTEST'))
|
||||
t = time.localtime()
|
||||
fmt = u'%Y%a%b%e%H%M'
|
||||
for fmt in (fmt, fmt.encode('ascii')):
|
||||
x = winutil.strftime(fmt, t)
|
||||
au(x, 'strftime')
|
||||
self.ae(unicode(time.strftime(fmt, t)), x)
|
||||
|
||||
def test_sqlite(self):
|
||||
import sqlite3
|
||||
|
@ -232,11 +232,15 @@ winutil_set_max_stdio(PyObject *self, PyObject *args) {
|
||||
|
||||
static PyObject *
|
||||
winutil_getenv(PyObject *self, PyObject *args) {
|
||||
const wchar_t *q;
|
||||
const Py_UNICODE *q;
|
||||
if (!PyArg_ParseTuple(args, "u", &q)) return NULL;
|
||||
wchar_t *ans = _wgetenv(q);
|
||||
if (ans == NULL) Py_RETURN_NONE;
|
||||
return PyUnicode_FromWideChar(ans, wcslen(ans));
|
||||
wchar_t *buf = NULL;
|
||||
size_t sz = 0;
|
||||
PyObject *ans = NULL;
|
||||
if (_wdupenv_s(&buf, &sz, q) != 0 || buf == NULL) { ans = Py_None; Py_INCREF(ans); }
|
||||
else ans = PyUnicode_FromWideChar(buf, sz);
|
||||
if (buf) free(buf);
|
||||
return ans;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
|
Loading…
x
Reference in New Issue
Block a user