clonefile.pyx 554 B

123456789101112131415161718
  1. import six
  2. cdef extern from "sys/clonefile.h" nogil:
  3. int clonefile(const char * src, const char * dst, int flags)
  4. cdef extern from "Python.h":
  5. ctypedef struct PyObject
  6. cdef PyObject *PyExc_OSError
  7. PyObject *PyErr_SetFromErrno(PyObject *)
  8. cdef int _macos_clone_file(const char* src, const char* dst) except? 0:
  9. if clonefile(src, dst, 0) == -1:
  10. PyErr_SetFromErrno(PyExc_OSError)
  11. return 0
  12. return 1
  13. def macos_clone_file(src, dst):
  14. return _macos_clone_file(six.ensure_binary(src), six.ensure_binary(dst)) != 0