Permalink
Browse files

Add fuctions to read config file size.

  • Loading branch information...
pjbroad committed May 6, 2012
1 parent e6a8e69 commit c3f12ccdef9ad377177ee489dd6396d6a0150e81
Showing with 30 additions and 0 deletions.
  1. +12 −0 io/elpathwrapper.c
  2. +9 −0 io/elpathwrapper.h
  3. +8 −0 misc.c
  4. +1 −0 misc.h
View
@@ -672,6 +672,18 @@ void file_check_datadir(void)
#endif // WINDOWS
}
+off_t get_file_size_config( const char *filename )
+{
+ char locbuffer[MAX_PATH];
+ const char * cfgdir = get_path_config();
+ if(strlen(cfgdir) + strlen(filename) + 1 > MAX_PATH){
+ return -1;
+ }
+ strcpy(locbuffer, cfgdir);
+ strcat(locbuffer, filename);
+ return get_file_size(locbuffer);
+}
+
int file_exists_config( const char *filename )
{
char locbuffer[MAX_PATH];
View
@@ -12,6 +12,7 @@ extern "C" {
#endif //C++
#include <stdio.h>
+#include <sys/types.h>
/**
* @brief Gets the base directory for config files
@@ -197,6 +198,14 @@ int copy_file(const char *source, const char *dest);
*/
int file_exists_config( const char *filename );
+/**
+ * @brief Get the size of the specified file from the config_dir
+ *
+ * @param filename The name of the file in the config_dir
+ * @return size if file exists in config_dir, -1 if the size check fails (may not exist)
+ */
+off_t get_file_size_config( const char *filename );
+
/**
* @brief Rename a specified file in the config_dir
*
View
8 misc.c
@@ -147,6 +147,14 @@ FILE *my_fopen (const char *fname, const char *mode)
return file;
}
+off_t get_file_size(const char *fname)
+{
+ struct stat fstat;
+ if (stat(fname, &fstat) < 0)
+ return -1;
+ return fstat.st_size;
+}
+
//warning: when checking directories, do not include the trailing slash, for portability reasons
int file_exists(const char *fname)
{
View
1 misc.h
@@ -87,6 +87,7 @@ FILE *my_tmpfile ();
* \retval FILE* Pointer to the file on success, NULL otherwise
*/
FILE *my_fopen (const char *fname, const char *mode);
+off_t get_file_size(const char *fname);
int file_exists(const char *fname);
int gzfile_exists(const char *fname);

0 comments on commit c3f12cc

Please sign in to comment.