[Assorted-commits] SF.net SVN: assorted:[1352] cpp-commons/trunk/src/commons/files.h
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-04-29 04:28:29
|
Revision: 1352 http://assorted.svn.sourceforge.net/assorted/?rev=1352&view=rev Author: yangzhang Date: 2009-04-29 04:28:27 +0000 (Wed, 29 Apr 2009) Log Message: ----------- added file_size, read_file_as_array; tweaks to use other commons abstractions Modified Paths: -------------- cpp-commons/trunk/src/commons/files.h Modified: cpp-commons/trunk/src/commons/files.h =================================================================== --- cpp-commons/trunk/src/commons/files.h 2009-04-29 02:13:34 UTC (rev 1351) +++ cpp-commons/trunk/src/commons/files.h 2009-04-29 04:28:27 UTC (rev 1352) @@ -12,6 +12,7 @@ #include <unistd.h> #include <fcntl.h> +#include <commons/array.h> #include <commons/check.h> #include <commons/closing.h> @@ -29,6 +30,26 @@ }; /** + * Get the size of a file in bytes. + */ + off_t file_size(const char *path) + { + struct stat s; + check0x(stat(path, &s)); + return s.st_size; + } + + /** + * Get the size of a file in bytes. + */ + off_t file_size(int fd) + { + struct stat s; + check0x(fstat(fd, &s)); + return s.st_size; + } + + /** * Read in a whole file as a string. */ void read_file_as_string ( const string & name, string & out ) { @@ -46,20 +67,9 @@ out = vector<char> ( istreambuf_iterator<char> ( in ), istreambuf_iterator<char>() ); } - off_t file_size(const char *path) - { - struct stat s; - check0x(stat(path, &s)); - return s.st_size; - } - - off_t file_size(int fd) - { - struct stat s; - check0x(fstat(fd, &s)); - return s.st_size; - } - + /** + * Read in a whole file as an array. + */ array<char> read_file_as_array(const char *path) { closingfd fd(checknnegerr(open(path, O_RDONLY))); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |