Mercurial > hg
comparison mercurial/cext/osutil.c @ 48841:2ef3b7d30cc1
cext: really remove Python 2 file handling code
Disclaimer: This is _WIN32 code and I have no machine to test.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 03 Mar 2022 09:45:21 +0900 |
parents | 499733de460f |
children | c6a3243567b6 |
comparison
equal
deleted
inserted
replaced
48840:499733de460f | 48841:2ef3b7d30cc1 |
---|---|
1174 int bufsize = -1; | 1174 int bufsize = -1; |
1175 char m0, m1, m2; | 1175 char m0, m1, m2; |
1176 char fpmode[4]; | 1176 char fpmode[4]; |
1177 int fppos = 0; | 1177 int fppos = 0; |
1178 int plus; | 1178 int plus; |
1179 #ifndef IS_PY3K | |
1180 FILE *fp; | |
1181 #endif | |
1182 | 1179 |
1183 if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|yi:posixfile", | 1180 if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|yi:posixfile", |
1184 kwlist, | 1181 kwlist, |
1185 Py_FileSystemDefaultEncoding, | 1182 Py_FileSystemDefaultEncoding, |
1186 &name, &mode, &bufsize)) | 1183 &name, &mode, &bufsize)) |
1248 if (fd == -1) { | 1245 if (fd == -1) { |
1249 CloseHandle(handle); | 1246 CloseHandle(handle); |
1250 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); | 1247 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); |
1251 goto bail; | 1248 goto bail; |
1252 } | 1249 } |
1253 #ifndef IS_PY3K | |
1254 fp = _fdopen(fd, fpmode); | |
1255 if (fp == NULL) { | |
1256 _close(fd); | |
1257 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); | |
1258 goto bail; | |
1259 } | |
1260 | |
1261 file_obj = PyFile_FromFile(fp, name, mode, fclose); | |
1262 if (file_obj == NULL) { | |
1263 fclose(fp); | |
1264 goto bail; | |
1265 } | |
1266 | |
1267 PyFile_SetBufSize(file_obj, bufsize); | |
1268 #else | |
1269 file_obj = PyFile_FromFd(fd, name, mode, bufsize, NULL, NULL, NULL, 1); | 1250 file_obj = PyFile_FromFd(fd, name, mode, bufsize, NULL, NULL, NULL, 1); |
1270 if (file_obj == NULL) | 1251 if (file_obj == NULL) |
1271 goto bail; | 1252 goto bail; |
1272 #endif | |
1273 bail: | 1253 bail: |
1274 PyMem_Free(name); | 1254 PyMem_Free(name); |
1275 return file_obj; | 1255 return file_obj; |
1276 } | 1256 } |
1277 #endif | 1257 #endif |