From: Guido van Rossum Date: Wed, 24 Oct 1990 16:40:15 +0000 (+0000) Subject: Mad readfile() read the file in one fell swoop. X-Git-Tag: v0.9.8~1153 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f49ef1cad0a7d7aa597dd8c9430a802084ec16a2;p=thirdparty%2FPython%2Fcpython.git Mad readfile() read the file in one fell swoop. --- diff --git a/Lib/commands.py b/Lib/commands.py index c96953cb9c64..dc467408310c 100644 --- a/Lib/commands.py +++ b/Lib/commands.py @@ -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).