Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

file.c File Reference


Detailed Description

Miscellaneous common file routines.

Author:
Raphael Manfredi
Date:
2002-2003

#include "common.h"
#include "file.h"
#include "misc.h"
#include "tm.h"
#include "override.h"

Functions

 RCSID ("$Id:file.c, v 1.11 2005/09/08 21:45:58 cbiere Exp $")
void file_register_fd_reclaimer (reclaim_fd_t callback)
 Register fd reclaiming callback.

FILE * open_read (const gchar *what, const file_path_t *fv, gint fvcnt, gboolean renaming, gint *chosen)
 Open configuration file, renaming it as ".orig" when `renaming' is TRUE.

FILE * file_config_open_read (const gchar *what, const file_path_t *fv, gint fvcnt)
 Open configuration file, renaming it as ".orig".

FILE * file_config_open_read_norename (const gchar *what, const file_path_t *fv, gint fvcnt)
 Open configuration file, without renaming it.

FILE * file_config_open_read_norename_chosen (const gchar *what, const file_path_t *fv, gint fvcnt, gint *chosen)
 Same as file_config_open_read_norename(), but also returns the index of the path chosen within the array, if a file was opened at all.

FILE * file_config_open (const gchar *what, const file_path_t *fv)
 Open configuration file for writing.

FILE * file_config_open_write (const gchar *what, const file_path_t *fv)
 Open configuration file for writing.

gboolean file_config_close (FILE *out, const file_path_t *fv)
 Close configuration file opened for writing, and rename it.

void file_config_preamble (FILE *out, const gchar *what)
 Emit the configuration preamble.

void file_path_set (file_path_t *fp, const char *dir, const char *name)
 Initializes `fp' with directory path `dir' and filename `name'.

gint do_open (const gchar *path, gint flags, gint mode, gboolean missing)
 Open file, returning file descriptor or -1 on error with errno set.

gint file_open (const gchar *path, gint flags)
 Open file, returning file descriptor or -1 on error with errno set.

gint file_open_missing (const gchar *path, gint flags)
 Open file, returning file descriptor or -1 on error with errno set.

gint file_create (const gchar *path, gint flags, gint mode)
 Create file, returning file descriptor or -1 on error with errno set.

FILE * do_fopen (const gchar *path, const gchar *mode, gboolean missing)
 Open file, returning FILE pointer if success or NULL on error.

FILE * file_fopen (const gchar *path, const gchar *mode)
 Open file, returning FILE pointer if success or NULL on error.

FILE * file_fopen_missing (const gchar *path, const gchar *mode)
 Open file, returning FILE pointer if success or NULL on error.


Variables

const gchar orig_ext [] = "orig"
const gchar new_ext [] = "new"
const gchar instead_str [] = " instead"
const gchar empty_str [] = ""
reclaim_fd_t reclaim_fd = NULL
 In order to avoid having a dependency between file.c and ban.c, we have ban.c register a callback to reclaim file descriptors at init time.


Function Documentation

FILE* do_fopen const gchar *  path,
const gchar *  mode,
gboolean  missing
[static]
 

Open file, returning FILE pointer if success or NULL on error.

Errors are logged as a warning, unless error is ENOENT and `missing' is TRUE.

gint do_open const gchar *  path,
gint  flags,
gint  mode,
gboolean  missing
[static]
 

Open file, returning file descriptor or -1 on error with errno set.

Errors are logged as a warning, unless `missing' is true, in which case no error is logged for ENOENT.

gboolean file_config_close FILE *  out,
const file_path_t fv
 

Close configuration file opened for writing, and rename it.

Returns:
TRUE on success.

FILE* file_config_open const gchar *  what,
const file_path_t fv
[static]
 

Open configuration file for writing.

We don't clobber the existing file yet and open a ".new" instead. Renaming will occur afterwards, when file_config_close() is called.

Returns:
opened FILE if success, NULL on error.

FILE* file_config_open_read const gchar *  what,
const file_path_t fv,
gint  fvcnt
 

Open configuration file, renaming it as ".orig".

If configuration file cannot be found, try opening the ".orig" variant if already present. If not found, try with successive alternatives, if supplied.

Attention:
NB: the supplied `fv' argument is a vector of `fvcnt' elements.
Returns:
opened FILE, or NULL if we were unable to open any.

FILE* file_config_open_read_norename const gchar *  what,
const file_path_t fv,
gint  fvcnt
 

Open configuration file, without renaming it.

If configuration file cannot be found, try opening the ".orig" variant if already present. If not found, try with successive alternatives, if supplied.

Attention:
NB: the supplied `fv' argument is a vector of `fvcnt' elements.
Returns:
opened FILE, or NULL if we were unable to open any.

FILE* file_config_open_read_norename_chosen const gchar *  what,
const file_path_t fv,
gint  fvcnt,
gint *  chosen
 

Same as file_config_open_read_norename(), but also returns the index of the path chosen within the array, if a file was opened at all.

FILE* file_config_open_write const gchar *  what,
const file_path_t fv
 

Open configuration file for writing.

void file_config_preamble FILE *  out,
const gchar *  what
 

Emit the configuration preamble.

gint file_create const gchar *  path,
gint  flags,
gint  mode
 

Create file, returning file descriptor or -1 on error with errno set.

Errors are logged as a warning.

FILE* file_fopen const gchar *  path,
const gchar *  mode
 

Open file, returning FILE pointer if success or NULL on error.

Errors are logged as a warning.

FILE* file_fopen_missing const gchar *  path,
const gchar *  mode
 

Open file, returning FILE pointer if success or NULL on error.

Errors are logged as a warning, unless the file is missing, in which case nothing is logged.

gint file_open const gchar *  path,
gint  flags
 

Open file, returning file descriptor or -1 on error with errno set.

Errors are logged as a warning.

gint file_open_missing const gchar *  path,
gint  flags
 

Open file, returning file descriptor or -1 on error with errno set.

Errors are logged as a warning, unless the file is missing, in which case nothing is logged.

void file_path_set file_path_t fp,
const char *  dir,
const char *  name
 

Initializes `fp' with directory path `dir' and filename `name'.

void file_register_fd_reclaimer reclaim_fd_t  callback  ) 
 

Register fd reclaiming callback.

Use NULL to unregister it.

FILE* open_read const gchar *  what,
const file_path_t fv,
gint  fvcnt,
gboolean  renaming,
gint *  chosen
[static]
 

Open configuration file, renaming it as ".orig" when `renaming' is TRUE.

If configuration file cannot be found, try opening the ".orig" variant if already present and `renaming' is TRUE. If not found, try with successive alternatives, if supplied.

Attention:
NB: the supplied `fv' argument is a vector of `fvcnt' elements.
Parameters:
what is what is being opened, for logging purposes.
fv is a vector of files to try to open, in sequence
fvcnt is the size of the vector
renaming indicates whether the opened file should be renamed .orig.
chosen is filled with the index of the chosen path in the vector, unless NULL is given.
Returns:
opened FILE, or NULL if we were unable to open any. `chosen' is only filled if the file is opened.

RCSID "$Id:file.  c,
v 1.11 2005/09/08 21:45:58 cbiere Exp $" 
 


Variable Documentation

const gchar empty_str[] = "" [static]
 

const gchar instead_str[] = " instead" [static]
 

const gchar new_ext[] = "new" [static]
 

const gchar orig_ext[] = "orig" [static]
 

reclaim_fd_t reclaim_fd = NULL [static]
 

In order to avoid having a dependency between file.c and ban.c, we have ban.c register a callback to reclaim file descriptors at init time.

--RAM, 2004-08-18


Generated on Sun Feb 12 10:50:00 2006 for Gtk-Gnutella by doxygen 1.3.6