Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0cec0ff

Browse files
committed
Patch #573770: Implement lchown.
1 parent ddc6f47 commit 0cec0ff

6 files changed

Lines changed: 49 additions & 8 deletions

File tree

Doc/lib/libos.tex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,13 @@ \subsection{Files and Directories \label{os-file-dir}}
641641
Availability: \UNIX.
642642
\end{funcdesc}
643643

644+
\begin{funcdesc}{lchown}{path, uid, gid}
645+
Change the owner and group id of \var{path} to the numeric \var{uid}
646+
and gid. This function will not follow symbolic links.
647+
Availability: \UNIX.
648+
\versionadded{2.3}
649+
\end{funcdesc}
650+
644651
\begin{funcdesc}{link}{src, dst}
645652
Create a hard link pointing to \var{src} named \var{dst}.
646653
Availability: \UNIX.

Misc/NEWS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ Extension modules
162162
This will create a temporary in-memory bsddb that won't be
163163
written to disk.
164164

165-
- posix.killpg, posix.mknod, and posix.getpgid have been added where
166-
available.
165+
- posix.lchown, posix.killpg, posix.mknod, and posix.getpgid have been
166+
added where available.
167167

168168
- The locale module now exposes the C library's gettext interface.
169169

@@ -339,7 +339,7 @@ Build
339339
to require editing the core to teach the trashcan mechanism about the
340340
new type.
341341

342-
- Accoring to Annex F of the current C standard,
342+
- According to Annex F of the current C standard,
343343

344344
The Standard C macro HUGE_VAL and its float and long double analogs,
345345
HUGE_VALF and HUGE_VALL, expand to expressions whose values are

Modules/posixmodule.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
935962
PyDoc_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

configure

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 1.334 .
2+
# From configure.in Revision: 1.335 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.53.
55
#
@@ -11436,13 +11436,14 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6
1143611436
1143711437
1143811438
11439+
1143911440
1144011441
1144111442
for ac_func in alarm chown chroot clock confstr ctermid ctermid_r execv \
1144211443
fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
1144311444
gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
11444-
hstrerror inet_pton kill killpg link lstat mkfifo mknod mktime mremap \
11445-
nice pathconf pause plock poll pthread_init \
11445+
hstrerror inet_pton kill killpg lchown link lstat mkfifo mknod mktime \
11446+
mremap nice pathconf pause plock poll pthread_init \
1144611447
putenv readlink \
1144711448
select setegid seteuid setgid setgroups \
1144811449
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \

configure.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,8 @@ AC_MSG_RESULT(MACHDEP_OBJS)
16191619
AC_CHECK_FUNCS(alarm chown chroot clock confstr ctermid ctermid_r execv \
16201620
fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
16211621
gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
1622-
hstrerror inet_pton kill killpg link lstat mkfifo mknod mktime mremap \
1623-
nice pathconf pause plock poll pthread_init \
1622+
hstrerror inet_pton kill killpg lchown link lstat mkfifo mknod mktime \
1623+
mremap nice pathconf pause plock poll pthread_init \
16241624
putenv readlink \
16251625
select setegid seteuid setgid setgroups \
16261626
setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \

pyconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@
211211
Solaris and Linux, the necessary defines are already defined.) */
212212
#undef HAVE_LARGEFILE_SUPPORT
213213

214+
/* Define to 1 if you have the `lchown' function. */
215+
#undef HAVE_LCHOWN
216+
214217
/* Define to 1 if you have the `dl' library (-ldl). */
215218
#undef HAVE_LIBDL
216219

0 commit comments

Comments
 (0)