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

Skip to content

Commit 4e30a84

Browse files
committed
Merged revisions 59239-59244 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r59240 | amaury.forgeotdarc | 2007-11-30 21:37:22 +0100 (Fri, 30 Nov 2007) | 2 lines Add a NEWS entry for r59231 ........ r59241 | amaury.forgeotdarc | 2007-11-30 21:51:40 +0100 (Fri, 30 Nov 2007) | 5 lines Issue #1521: on 64bit platforms, str.decode fails on very long strings. The t# and w# formats were not correctly handled. Will backport. ........ r59242 | christian.heimes | 2007-11-30 22:11:28 +0100 (Fri, 30 Nov 2007) | 3 lines Fix for feature request #1528 Add os.fchmod Georg Brandl has added fchmod() and fchown(). I've contributed lchown but I'm not able to test it on Linux. However it should be available on Mac and some other flavors of Unix. I've made a quick test of fchmod() and fchown() on my system. They are working as expected. ........
1 parent 04a4eb3 commit 4e30a84

7 files changed

Lines changed: 128 additions & 11 deletions

File tree

Doc/library/os.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,19 @@ by file descriptors.
417417
Availability: Macintosh, Unix, Windows.
418418

419419

420+
.. function:: fchmod(fd, mode)
421+
422+
Change the mode of the file given by *fd* to the numeric *mode*. See the docs
423+
for :func:`chmod` for possible values of *mode*. Availability: Unix.
424+
425+
426+
.. function:: fchown(fd, uid, gid)
427+
428+
Change the owner and group id of the file given by *fd* to the numeric *uid*
429+
and *gid*. To leave one of the ids unchanged, set it to -1.
430+
Availability: Unix.
431+
432+
420433
.. function:: fdatasync(fd)
421434

422435
Force write of file with filedescriptor *fd* to disk. Does not force update of
@@ -475,6 +488,13 @@ by file descriptors.
475488
tty(-like) device, else ``False``. Availability: Macintosh, Unix.
476489

477490

491+
.. function:: lchmod(path, mode)
492+
493+
Change the mode of *path* to the numeric *mode*. If path is a symlink, this
494+
affects the symlink rather than the target. See the docs for :func:`chmod`
495+
for possible values of *mode*. Availability: Unix.
496+
497+
478498
.. function:: lseek(fd, pos, how)
479499

480500
Set the current position of file descriptor *fd* to position *pos*, modified by

Lib/test/test_bigmem.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ def test_count(self, size):
6464
self.assertEquals(s.count('i'), 1)
6565
self.assertEquals(s.count('j'), 0)
6666

67-
@bigmemtest(minsize=0, memuse=1)
67+
@bigmemtest(minsize=_2G + 2, memuse=3)
6868
def test_decode(self, size):
69-
pass
69+
s = '.' * size
70+
self.assertEquals(len(s.decode('utf-8')), size)
7071

71-
@bigmemtest(minsize=0, memuse=1)
72+
@bigmemtest(minsize=_2G + 2, memuse=3)
7273
def test_encode(self, size):
73-
pass
74+
s = u'.' * size
75+
self.assertEquals(len(s.encode('utf-8')), size)
7476

7577
@bigmemtest(minsize=_2G, memuse=2)
7678
def test_endswith(self, size):

Modules/posixmodule.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ extern int chmod(const char *, int);
186186
#else
187187
extern int chmod(const char *, mode_t);
188188
#endif
189+
/*#ifdef HAVE_FCHMOD
190+
extern int fchmod(int, mode_t);
191+
#endif*/
192+
/*#ifdef HAVE_LCHMOD
193+
extern int lchmod(const char *, mode_t);
194+
#endif*/
189195
extern int chown(const char *, uid_t, gid_t);
190196
extern char *getcwd(char *, int);
191197
extern char *strerror(int);
@@ -1747,6 +1753,52 @@ posix_chmod(PyObject *self, PyObject *args)
17471753
#endif
17481754
}
17491755

1756+
#ifdef HAVE_FCHMOD
1757+
PyDoc_STRVAR(posix_fchmod__doc__,
1758+
"fchmod(fd, mode)\n\n\
1759+
Change the access permissions of the file given by file\n\
1760+
descriptor fd.");
1761+
1762+
static PyObject *
1763+
posix_fchmod(PyObject *self, PyObject *args)
1764+
{
1765+
int fd, mode, res;
1766+
if (!PyArg_ParseTuple(args, "ii:fchmod", &fd, &mode))
1767+
return NULL;
1768+
Py_BEGIN_ALLOW_THREADS
1769+
res = fchmod(fd, mode);
1770+
Py_END_ALLOW_THREADS
1771+
if (res < 0)
1772+
return posix_error();
1773+
Py_RETURN_NONE;
1774+
}
1775+
#endif /* HAVE_FCHMOD */
1776+
1777+
#ifdef HAVE_LCHMOD
1778+
PyDoc_STRVAR(posix_lchmod__doc__,
1779+
"lchmod(path, mode)\n\n\
1780+
Change the access permissions of a file. If path is a symlink, this\n\
1781+
affects the link itself rather than the target.");
1782+
1783+
static PyObject *
1784+
posix_lchmod(PyObject *self, PyObject *args)
1785+
{
1786+
char *path = NULL;
1787+
int i;
1788+
int res;
1789+
if (!PyArg_ParseTuple(args, "eti:lchmod", Py_FileSystemDefaultEncoding,
1790+
&path, &i))
1791+
return NULL;
1792+
Py_BEGIN_ALLOW_THREADS
1793+
res = lchmod(path, i);
1794+
Py_END_ALLOW_THREADS
1795+
if (res < 0)
1796+
return posix_error_with_allocated_filename(path);
1797+
PyMem_Free(path);
1798+
Py_RETURN_NONE;
1799+
}
1800+
#endif /* HAVE_LCHMOD */
1801+
17501802

17511803
#ifdef HAVE_CHFLAGS
17521804
PyDoc_STRVAR(posix_chflags__doc__,
@@ -1868,6 +1920,28 @@ posix_chown(PyObject *self, PyObject *args)
18681920
}
18691921
#endif /* HAVE_CHOWN */
18701922

1923+
#ifdef HAVE_FCHOWN
1924+
PyDoc_STRVAR(posix_fchown__doc__,
1925+
"fchown(fd, uid, gid)\n\n\
1926+
Change the owner and group id of the file given by file descriptor\n\
1927+
fd to the numeric uid and gid.");
1928+
1929+
static PyObject *
1930+
posix_fchown(PyObject *self, PyObject *args)
1931+
{
1932+
int fd, uid, gid;
1933+
int res;
1934+
if (!PyArg_ParseTuple(args, "iii:chown", &fd, &uid, &gid))
1935+
return NULL;
1936+
Py_BEGIN_ALLOW_THREADS
1937+
res = fchown(fd, (uid_t) uid, (gid_t) gid);
1938+
Py_END_ALLOW_THREADS
1939+
if (res < 0)
1940+
return posix_error();
1941+
Py_RETURN_NONE;
1942+
}
1943+
#endif /* HAVE_FCHOWN */
1944+
18711945
#ifdef HAVE_LCHOWN
18721946
PyDoc_STRVAR(posix_lchown__doc__,
18731947
"lchown(path, uid, gid)\n\n\
@@ -6664,9 +6738,18 @@ static PyMethodDef posix_methods[] = {
66646738
{"chflags", posix_chflags, METH_VARARGS, posix_chflags__doc__},
66656739
#endif /* HAVE_CHFLAGS */
66666740
{"chmod", posix_chmod, METH_VARARGS, posix_chmod__doc__},
6741+
#ifdef HAVE_FCHMOD
6742+
{"fchmod", posix_fchmod, METH_VARARGS, posix_fchmod__doc__},
6743+
#endif /* HAVE_FCHMOD */
66676744
#ifdef HAVE_CHOWN
66686745
{"chown", posix_chown, METH_VARARGS, posix_chown__doc__},
66696746
#endif /* HAVE_CHOWN */
6747+
#ifdef HAVE_LCHMOD
6748+
{"lchmod", posix_lchmod, METH_VARARGS, posix_lchmod__doc__},
6749+
#endif /* HAVE_LCHMOD */
6750+
#ifdef HAVE_FCHOWN
6751+
{"fchown", posix_fchown, METH_VARARGS, posix_fchown__doc__},
6752+
#endif /* HAVE_FCHOWN */
66706753
#ifdef HAVE_LCHFLAGS
66716754
{"lchflags", posix_lchflags, METH_VARARGS, posix_lchflags__doc__},
66726755
#endif /* HAVE_LCHFLAGS */

Python/getargs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
11821182
case 'w': { /* memory buffer, read-write access */
11831183
void **p = va_arg(*p_va, void **);
11841184
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
1185-
int count;
1185+
Py_ssize_t count;
11861186
int temp=-1;
11871187
Py_buffer view;
11881188

@@ -1216,7 +1216,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
12161216
case 't': { /* 8-bit character buffer, read-only access */
12171217
char **p = va_arg(*p_va, char **);
12181218
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
1219-
int count;
1219+
Py_ssize_t count;
12201220
Py_buffer view;
12211221

12221222
if (*format++ != '#')

configure

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# From configure.in Revision: 58054 .
2+
# From configure.in Revision: 58817 .
33
# Guess values for system-dependent variables and create Makefiles.
44
# Generated by GNU Autoconf 2.61 for python 3.0.
55
#
@@ -15436,15 +15436,18 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6; }
1543615436

1543715437

1543815438

15439+
15440+
15441+
1543915442

1544015443

1544115444

1544215445

1544315446
for ac_func in alarm bind_textdomain_codeset chflags chown clock confstr \
15444-
ctermid execv fork fpathconf ftime ftruncate \
15447+
ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
1544515448
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
1544615449
getpriority getpwent getspnam getspent getsid getwd \
15447-
kill killpg lchflags lchown lstat mkfifo mknod mktime \
15450+
kill killpg lchflags lchmod lchown lstat mkfifo mknod mktime \
1544815451
mremap nice pathconf pause plock poll pthread_init \
1544915452
putenv readlink realpath \
1545015453
select setegid seteuid setgid \

configure.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,10 +2275,10 @@ AC_MSG_RESULT(MACHDEP_OBJS)
22752275

22762276
# checks for library functions
22772277
AC_CHECK_FUNCS(alarm bind_textdomain_codeset chflags chown clock confstr \
2278-
ctermid execv fork fpathconf ftime ftruncate \
2278+
ctermid execv fchmod fchown fork fpathconf ftime ftruncate \
22792279
gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
22802280
getpriority getpwent getspnam getspent getsid getwd \
2281-
kill killpg lchflags lchown lstat mkfifo mknod mktime \
2281+
kill killpg lchflags lchmod lchown lstat mkfifo mknod mktime \
22822282
mremap nice pathconf pause plock poll pthread_init \
22832283
putenv readlink realpath \
22842284
select setegid seteuid setgid \

pyconfig.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@
141141
/* Define if you have the 'fchdir' function. */
142142
#undef HAVE_FCHDIR
143143

144+
/* Define to 1 if you have the `fchmod' function. */
145+
#undef HAVE_FCHMOD
146+
147+
/* Define to 1 if you have the `fchown' function. */
148+
#undef HAVE_FCHOWN
149+
144150
/* Define to 1 if you have the <fcntl.h> header file. */
145151
#undef HAVE_FCNTL_H
146152

@@ -297,6 +303,9 @@
297303
/* Define to 1 if you have the `lchflags' function. */
298304
#undef HAVE_LCHFLAGS
299305

306+
/* Define to 1 if you have the `lchmod' function. */
307+
#undef HAVE_LCHMOD
308+
300309
/* Define to 1 if you have the `lchown' function. */
301310
#undef HAVE_LCHOWN
302311

0 commit comments

Comments
 (0)