self.check(os.pathconf, "PC_NAME_MAX")
self.check(os.fpathconf, "PC_NAME_MAX")
+ @unittest.skipUnless(hasattr(os, 'pathconf'), 'test needs os.pathconf()')
+ @unittest.skipIf(
+ support.linked_to_musl(),
+ 'musl fpathconf ignores the file descriptor and returns a constant',
+ )
+ def test_pathconf_negative_fd_uses_fd_semantics(self):
+ with self.assertRaises(OSError) as ctx:
+ os.pathconf(-1, 1)
+ self.assertEqual(ctx.exception.errno, errno.EBADF)
+
@unittest.skipUnless(hasattr(os, 'ftruncate'), 'test needs os.ftruncate()')
def test_ftruncate(self):
self.check(os.truncate, 0)
* Contains a file descriptor if path.accept_fd was true
* and the caller provided a signed integer instead of any
* sort of string.
+ * path.is_fd
+ * True if path was provided as a file descriptor.
*
* WARNING: if your "path" parameter is optional, and is
* unspecified, path_converter will never get called.
const wchar_t *wide;
const char *narrow;
int fd;
+ bool is_fd;
int value_error;
Py_ssize_t length;
PyObject *object;
#define PATH_T_INITIALIZE(function_name, argument_name, nullable, nonstrict, \
make_wide, suppress_value_error, allow_fd) \
{function_name, argument_name, nullable, nonstrict, make_wide, \
- suppress_value_error, allow_fd, NULL, NULL, -1, 0, 0, NULL, NULL}
+ suppress_value_error, allow_fd, NULL, NULL, -1, false, 0, 0, NULL, NULL}
#ifdef MS_WINDOWS
#define PATH_T_INITIALIZE_P(function_name, argument_name, nullable, \
nonstrict, suppress_value_error, allow_fd) \
}
path->wide = NULL;
path->narrow = NULL;
+ path->is_fd = true;
goto success_exit;
}
else {
errno = 0;
#ifdef HAVE_FPATHCONF
- if (path->fd != -1)
+ if (path->is_fd) {
limit = fpathconf(path->fd, name);
+ }
else
#endif
limit = pathconf(path->narrow, name);