suffix.c File Reference

Checks filename suffix and creates the destination filename. More...

`#include "private.h"`

## Functions

static bool | is_dir_sep (char c)
| Test if the char is a directory separator. More...
static bool | has_dir_sep (const char *str)
| Test if the string contains a directory separator. More...
static size_t | test_suffix (const char *suffix, const char *src_name, size_t src_len)
| Checks if src_name has given compressed_suffix. More...
static char * | uncompressed_name (const char *src_name, const size_t src_len)
| Removes the filename suffix of the compressed file. More...
static void | msg_suffix (const char *src_name, const char *suffix)
static char * | compressed_name (const char *src_name, size_t src_len)
| Appends suffix to src_name. More...
char * | suffix_get_dest_name (const char *src_name)
| Get the name of the destination file. More...
void | suffix_set (const char *suffix)
| Set a custom filename suffix. More...

## Variables

static char * | custom_suffix = NULL

## Detailed Description

Checks filename suffix and creates the destination filename.

## Function Documentation

## is_dir_sep()

static bool is_dir_sep | ( | char | c | ) |

static

Test if the char is a directory separator.

Referenced by test_suffix().

## has_dir_sep()

static bool has_dir_sep | ( | const char * | str | ) |

static

Test if the string contains a directory separator.

Referenced by suffix_set().

## test_suffix()

static size_t test_suffix | ( | const char * | suffix,
|  | const char * | src_name,
|  | size_t | src_len
| ) |  |

static

Checks if src_name has given compressed_suffix.

Parameters

  suffix | Filename suffix to look for
  src_name | Input filename
  src_len | strlen(src_name)

Returns
  If src_name has the suffix, src_len - strlen(suffix) is returned. It's always a positive integer. Otherwise zero is returned.

References is_dir_sep().

## uncompressed_name()

static char* uncompressed_name | ( | const char * | src_name,
|  | const size_t | src_len
| ) |  |

static

Removes the filename suffix of the compressed file.

Returns
  Name of the uncompressed file, or NULL if file has unknown suffix.

References opt_format.

## msg_suffix()

static void msg_suffix | ( | const char * | src_name,
|  | const char * | suffix
| ) |  |

static

This message is needed in multiple places in compressed_name(), so the message has been put into its own function.

References message_warning().

## compressed_name()

static char* compressed_name | ( | const char * | src_name,
|  | size_t | src_len
| ) |  |

static

Appends suffix to src_name.

In contrast to uncompressed_name(), we check only suffixes that are valid for the specified file format.

## suffix_get_dest_name()

char* suffix_get_dest_name | ( | const char * | src_name | ) |

Get the name of the destination file.

Depending on the global variable opt_mode, this tries to find a matching counterpart for src_name. If the name can be constructed, it is allocated and returned (caller must free it). On error, a message is printed and NULL is returned.

## suffix_set()

void suffix_set | ( | const char * | suffix | ) |

Set a custom filename suffix.

This function calls xstrdup() for the given suffix, thus the caller doesn't need to keep the memory allocated. There can be only one custom suffix, thus if this is called multiple times, the old suffixes are freed and forgotten.

References has_dir_sep(), and message_fatal().