@@ -930,6 +930,33 @@ posix_chown(PyObject *self, PyObject *args)
930930}
931931#endif /* HAVE_CHOWN */
932932
933+ #ifdef HAVE_LCHOWN
934+ PyDoc_STRVAR (posix_lchown__doc__ ,
935+ "lchown (path , uid , gid )\n \n \
936+ Change the owner and group id of path to the numeric uid and gid .\n \
937+ This function will not follow symbolic links .");
938+
939+ static PyObject *
940+ posix_lchown (PyObject * self , PyObject * args )
941+ {
942+ char * path = NULL ;
943+ int uid , gid ;
944+ int res ;
945+ if (!PyArg_ParseTuple (args , "etii:lchown" ,
946+ Py_FileSystemDefaultEncoding , & path ,
947+ & uid , & gid ))
948+ return NULL ;
949+ Py_BEGIN_ALLOW_THREADS
950+ res = lchown (path , (uid_t ) uid , (gid_t ) gid );
951+ Py_END_ALLOW_THREADS
952+ if (res < 0 )
953+ return posix_error_with_allocated_filename (path );
954+ PyMem_Free (path );
955+ Py_INCREF (Py_None );
956+ return Py_None ;
957+ }
958+ #endif /* HAVE_LCHOWN */
959+
933960
934961#ifdef HAVE_GETCWD
935962PyDoc_STRVAR (posix_getcwd__doc__ ,
@@ -6225,6 +6252,9 @@ static PyMethodDef posix_methods[] = {
62256252#ifdef HAVE_CHOWN
62266253 {"chown" , posix_chown , METH_VARARGS , posix_chown__doc__ },
62276254#endif /* HAVE_CHOWN */
6255+ #ifdef HAVE_LCHOWN
6256+ {"lchown" , posix_lchown , METH_VARARGS , posix_lchown__doc__ },
6257+ #endif /* HAVE_LCHOWN */
62286258#ifdef HAVE_CHROOT
62296259 {"chroot" , posix_chroot , METH_VARARGS , posix_chroot__doc__ },
62306260#endif
0 commit comments