Mercurial > hg
comparison mercurial/cext/osutil.c @ 48840:499733de460f
cext: backout e9ca736f5b52 "remove Python 2 file handling code"
It's if"n"def.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 03 Mar 2022 09:43:10 +0900 |
parents | 3aa1b7ded52c |
children | 2ef3b7d30cc1 |
comparison
equal
deleted
inserted
replaced
48839:7b068abe4aa2 | 48840:499733de460f |
---|---|
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 | |
1179 FILE *fp; | 1180 FILE *fp; |
1181 #endif | |
1180 | 1182 |
1181 if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|yi:posixfile", | 1183 if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|yi:posixfile", |
1182 kwlist, | 1184 kwlist, |
1183 Py_FileSystemDefaultEncoding, | 1185 Py_FileSystemDefaultEncoding, |
1184 &name, &mode, &bufsize)) | 1186 &name, &mode, &bufsize)) |
1246 if (fd == -1) { | 1248 if (fd == -1) { |
1247 CloseHandle(handle); | 1249 CloseHandle(handle); |
1248 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); | 1250 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); |
1249 goto bail; | 1251 goto bail; |
1250 } | 1252 } |
1253 #ifndef IS_PY3K | |
1251 fp = _fdopen(fd, fpmode); | 1254 fp = _fdopen(fd, fpmode); |
1252 if (fp == NULL) { | 1255 if (fp == NULL) { |
1253 _close(fd); | 1256 _close(fd); |
1254 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); | 1257 PyErr_SetFromErrnoWithFilename(PyExc_IOError, name); |
1255 goto bail; | 1258 goto bail; |
1260 fclose(fp); | 1263 fclose(fp); |
1261 goto bail; | 1264 goto bail; |
1262 } | 1265 } |
1263 | 1266 |
1264 PyFile_SetBufSize(file_obj, bufsize); | 1267 PyFile_SetBufSize(file_obj, bufsize); |
1268 #else | |
1269 file_obj = PyFile_FromFd(fd, name, mode, bufsize, NULL, NULL, NULL, 1); | |
1270 if (file_obj == NULL) | |
1271 goto bail; | |
1272 #endif | |
1265 bail: | 1273 bail: |
1266 PyMem_Free(name); | 1274 PyMem_Free(name); |
1267 return file_obj; | 1275 return file_obj; |
1268 } | 1276 } |
1269 #endif | 1277 #endif |