Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
3a77c7ab
Commit
3a77c7ab
authored
Jun 06, 2007
by
Walter Dörwald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If append mode is specified seek to the end of the file.
Add a test to test_fileio.py for this.
parent
fee1af9d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
Lib/test/test_fileio.py
Lib/test/test_fileio.py
+18
-0
Modules/_fileio.c
Modules/_fileio.c
+12
-0
No files found.
Lib/test/test_fileio.py
View file @
3a77c7ab
...
...
@@ -205,6 +205,24 @@ class OtherFileTests(unittest.TestCase):
finally
:
os
.
unlink
(
TESTFN
)
def
testAppend
(
self
):
try
:
f
=
open
(
TESTFN
,
'wb'
)
f
.
write
(
b'spam'
)
f
.
close
()
f
=
open
(
TESTFN
,
'ab'
)
f
.
write
(
b'eggs'
)
f
.
close
()
f
=
open
(
TESTFN
,
'rb'
)
d
=
f
.
read
()
f
.
close
()
self
.
assertEqual
(
d
,
b'spameggs'
)
finally
:
try
:
os
.
unlink
(
TESTFN
)
except
:
pass
def
test_main
():
# Historically, these tests have been sloppy about removing TESTFN.
# So get rid of it no matter what.
...
...
Modules/_fileio.c
View file @
3a77c7ab
...
...
@@ -242,6 +242,18 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
PyErr_SetFromErrnoWithFilename
(
PyExc_IOError
,
name
);
goto
error
;
}
if
(
append
)
{
int
result
;
Py_BEGIN_ALLOW_THREADS
errno
=
0
;
result
=
lseek
(
self
->
fd
,
0
,
SEEK_END
);
Py_END_ALLOW_THREADS
if
(
result
<
0
)
{
close
(
self
->
fd
);
PyErr_SetFromErrnoWithFilename
(
PyExc_IOError
,
name
);
goto
error
;
}
}
}
goto
done
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment