Freeciv-3.3: /fast/freeciv/nightly/main/utility/ioz.c File Reference

Freeciv-3.3

Loading...
Searching...
No Matches
Data Structures | Macros | Functions
ioz.c File Reference
`#include "fc_prehdrs.h"`
`#include <errno.h>`
`#include <stdarg.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include "log.h"`
`#include "mem.h"`
`#include "shared.h"`
`#include "support.h"`
`#include "ioz.h"`

Go to the source code of this file.

## Data Structures

struct | mem_fzFILE
struct | fz_FILE_s

## Macros

#define | PLAIN_FILE_BUF_SIZE (8096*1024)
#define | fz_method_validate(method)

## Functions

static bool | fz_method_is_valid (enum fz_method method)
fz_FILE * | fz_from_memory (char *buffer, int size, bool control)
fz_FILE * | fz_from_file (const char *filename, const char *in_mode, enum fz_method method, int compress_level)
fz_FILE * | fz_from_stream (FILE *stream)
int | fz_fclose (fz_FILE *fp)
char * | fz_fgets (char *buffer, int size, fz_FILE *fp)
int | fz_fprintf (fz_FILE *fp, const char *format,...)
int | fz_ferror (fz_FILE *fp)
const char * | fz_strerror (fz_FILE *fp)

## Macro Definition Documentation

## ◆ fz_method_validate

#define fz_method_validate | ( |  | method | ) |

Value:
(fz_method_is_valid(method) ? method \
: (fc_assert_msg(fz_method_is_valid(method), \
"Unsupported compress method %d, reverting to plain.",\
method), FZ_PLAIN))
fz_method_is_valid
static bool fz_method_is_valid(enum fz_method method)
Definition ioz.c:174
FZ_PLAIN
@ FZ_PLAIN
Definition ioz.h:37
fc_assert_msg
#define fc_assert_msg(condition, message,...)
Definition log.h:181

Definition at line 195 of file ioz.c.

## ◆ PLAIN_FILE_BUF_SIZE

#define PLAIN_FILE_BUF_SIZE (8096*1024)

Definition at line 69 of file ioz.c.

## Function Documentation

## ◆ fz_fclose()

int fz_fclose | ( | fz_FILE * | fp | ) |

Close file, like fclose(). Returns 0 on success, or non-zero for problems (but don't call fz_ferror() in that case because the struct has already been free'd; wishlist: better interface for errors?) (For FZ_PLAIN returns EOF and could check errno; for FZ_ZLIB: returns zlib error number; see zlib.h.)

Definition at line 571 of file ioz.c.

Referenced by get_token_value(), inf_close_partial(), and secfile_save().

## ◆ fz_ferror()

int fz_ferror | ( | fz_FILE * | fp | ) |

Return non-zero if there is an error status associated with this stream. Check fz_strerror() for details.

Definition at line 1099 of file ioz.c.

Referenced by inf_close_partial(), and secfile_save().

## ◆ fz_fgets()

char * fz_fgets | ( | char * | buffer,
|  | int | size,
|  | fz_FILE * | fp
| ) |  |

Get a line, like fgets(). Returns nullptr in case of error, or when end-of-file reached and no characters have been read.

Definition at line 655 of file ioz.c.

Referenced by get_token_value(), and read_a_line().

## ◆ fz_fprintf()

int fz_fprintf | ( | fz_FILE * | fp,
|  | const char * | format,
|  |  | ...
| ) |  |

Print formatted, like fprintf().

Note: zlib doesn't have gzvfprintf(), but thats ok because its fprintf() only does similar to what we do here (print to fixed buffer), and in addition this way we get to use our safe snprintf().

Returns number of (uncompressed) bytes actually written, or 0 on error.

Definition at line 971 of file ioz.c.

Referenced by entry_to_file(), and secfile_save().

## ◆ fz_from_file()

fz_FILE * fz_from_file | ( | const char * | filename,
|  | const char * | in_mode,
|  | enum fz_method | method,
|  | int | compress_level
| ) |  |

Open file for reading/writing, like fopen(). Parameters compress_method and compress_level only apply for writing: for reading try to use the most appropriate available method. Returns nullptr if there was a problem; check errno for details. (If errno is 0, and using FZ_ZLIB, probably had zlib error Z_MEM_ERROR. Wishlist: better interface for errors?)

Definition at line 230 of file ioz.c.

Referenced by get_token_value(), inf_from_file(), and secfile_save().

## ◆ fz_from_memory()

fz_FILE * fz_from_memory | ( | char * | buffer,
|  | int | size,
|  | bool | control
| ) |  |

Open memory buffer for reading as fz_FILE. If control is TRUE, caller gives up control of the buffer so ioz will free it when fz_FILE closed.

Definition at line 207 of file ioz.c.

Referenced by netfile_get_section_file().

## ◆ fz_from_stream()

fz_FILE * fz_from_stream | ( | FILE * | stream | ) |

Open uncompressed stream for reading/writing.

Definition at line 548 of file ioz.c.

Referenced by fc_querysocket().

## ◆ fz_method_is_valid()

static bool fz_method_is_valid | ( | enum fz_method | method | ) |

inlinestatic

Validate the compression method.

Definition at line 174 of file ioz.c.

## ◆ fz_strerror()

const char * fz_strerror | ( | fz_FILE * | fp | ) |

Return string (pointer to static memory) containing an error description associated with the file. Should only call this is you know there is an error (eg, from fz_ferror()). Note the error string may be based on errno, so should call this immediately after problem, or possibly something else might overwrite errno.

Definition at line 1157 of file ioz.c.

Referenced by inf_close_partial(), and secfile_save().