]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Mad readfile() read the file in one fell swoop.
authorGuido van Rossum <guido@python.org>
Wed, 24 Oct 1990 16:40:15 +0000 (16:40 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 24 Oct 1990 16:40:15 +0000 (16:40 +0000)
Lib/commands.py

index c96953cb9c6460a43d3abcea6cfef10993818e2f..dc467408310c1787c7e41cbde1f24fa2daf842d8 100644 (file)
@@ -41,7 +41,17 @@ def getstatusoutput(cmd):
 # Return a string containing a file's contents.
 #
 def readfile(fn):
-       return open(fn, 'r').read(posix.stat(fn)[stat.ST_SIZE])
+       st = posix.stat(fn)
+       size = st[stat.ST_SIZE]
+       if not size: return ''
+       try:
+               fp = open(fn, 'r')
+       except:
+               raise posix.error, 'readfile(' + fn + '): open failed'
+       try:
+               return fp.read(size)
+       except:
+               raise posix.error, 'readfile(' + fn + '): read failed'
 
 
 # Make command argument from directory and pathname (prefix space, add quotes).