Crossfire Server, Trunk  R20513
Data Structures | Functions
output_file.h File Reference

Functions for creating text output files. More...

#include <stdio.h>
Include dependency graph for output_file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  OutputFile
 

Functions

void of_cancel (OutputFile *of)
 Cancels a save process. More...
 
int of_close (OutputFile *of)
 Closes an output file. More...
 
FILE * of_open (OutputFile *of, const char *fname)
 Opens an output file. More...
 

Detailed Description

Functions for creating text output files.

During (re-)writing a new file or if a write error occurs the old file contents are still available.

Example usage:

OutputFile of;
FILE *f;
f = of_open(&of, "some_file.txt", llevError);
if (f == NULL)
    return;
fprintf(f, "...");
fprintf(f, "...");
if (!of_close(&of))
    return;

Definition in file output_file.h.

Function Documentation

void of_cancel ( OutputFile of)

Cancels a save process.

This closes and deletes the temporary file, leaving the original file contents unmodified. This function (or on_close()} must be called exactly once for each successful call to op_open().

Parameters
ofthe output file instance to operate on

Definition at line 89 of file output_file.c.

References OutputFile::file, OutputFile::fname, and OutputFile::fname_tmp.

Referenced by save_map().

Here is the caller graph for this function:

int of_close ( OutputFile of)

Closes an output file.

This function (or of_cancel()} must be called exactly once for each successful call to of_open().

Parameters
ofthe output file instance to operate on
Returns
whether writing was successful; if unsuccessful an error message has been printed and the original file content are unchanged

Definition at line 61 of file output_file.c.

References OutputFile::file, OutputFile::fname, OutputFile::fname_tmp, llevError, and LOG().

Referenced by account_char_save(), accounts_save(), hiscore_save(), knowledge_write_player_data(), quest_write_player_data(), resurrect_player(), save_map(), save_player(), write_book_archive(), write_map_log(), and write_todclock().

Here is the call graph for this function:

Here is the caller graph for this function:

FILE* of_open ( OutputFile of,
const char *  fname 
)

Opens an output file.

It is equivalent to fopen(fname, "w"); but uses a temporary file instead of fname until of_close() is called.

Parameters
ofan OutputFile instance allocated by the caller; it must not be freed or reused until of_close() has been called
fnamethe filename to open; the string may be freed or reused afterwards
Returns
the file pointer or NULL if the file could not be opened; in this case an error message has been printed and the original file content are unchanged

Definition at line 30 of file output_file.c.

References OutputFile::file, OutputFile::fname, OutputFile::fname_tmp, llevError, LOG(), strdup_local, and TMP_EXT.

Referenced by account_char_save(), accounts_save(), hiscore_save(), knowledge_write_player_data(), quest_write_player_data(), resurrect_player(), save_map(), save_player(), write_book_archive(), write_map_log(), and write_todclock().

Here is the call graph for this function:

Here is the caller graph for this function: