X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Futils.c;h=335144932a1b8b894578a2100dcc86276671de83;hp=cd1e645d42e7968ec4eb5d8dfdf5d9400b818e5a;hb=5cb8a6f44dc55734dc1def8abd904ed9108f4d67;hpb=f0c20666da7f1de54106cfec6ca912f07384e9ec diff --git a/src/utils.c b/src/utils.c index cd1e645d..33514493 100644 --- a/src/utils.c +++ b/src/utils.c @@ -554,6 +554,22 @@ file_non_directory_p (const char *path) return S_ISDIR (buf.st_mode) ? 0 : 1; } +/* Return the size of file named by FILENAME, or -1 if it cannot be + opened or seeked into. */ +long +file_size (const char *filename) +{ + long size; + /* We use fseek rather than stat to determine the file size because + that way we can also verify whether the file is readable. + Inspired by the POST patch by Arnaud Wylie. */ + FILE *fp = fopen (filename, "rb"); + fseek (fp, 0, SEEK_END); + size = ftell (fp); + fclose (fp); + return size; +} + /* Return a unique filename, given a prefix and count */ static char * unique_name_1 (const char *fileprefix, int count)