Rizin
unix-like reverse engineering framework and cli tools
suffix.h File Reference

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

Go to the source code of this file.

Functions

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...
 

Detailed Description

Checks filename suffix and creates the destination filename.

Definition in file suffix.h.

Function Documentation

◆ 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.

Definition at line 373 of file suffix.c.

374 {
375  assert(src_name != NULL);
376 
377  // Length of the name is needed in all cases to locate the end of
378  // the string to compare the suffix, so calculate the length here.
379  const size_t src_len = strlen(src_name);
380 
381  return opt_mode == MODE_COMPRESS
382  ? compressed_name(src_name, src_len)
383  : uncompressed_name(src_name, src_len);
384 }
enum operation_mode opt_mode
Definition: coder.c:24
@ MODE_COMPRESS
Definition: coder.h:14
#define NULL
Definition: cris-opc.c:27
assert(limit<=UINT32_MAX/2)
static char * compressed_name(const char *src_name, size_t src_len)
Appends suffix to src_name.
Definition: suffix.c:196
static char * uncompressed_name(const char *src_name, const size_t src_len)
Removes the filename suffix of the compressed file.
Definition: suffix.c:110

References assert(), compressed_name(), MODE_COMPRESS, NULL, opt_mode, and uncompressed_name().

Referenced by io_open_dest_real().

◆ 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.

Definition at line 388 of file suffix.c.

389 {
390  // Empty suffix and suffixes having a directory separator are
391  // rejected. Such suffixes would break things later.
392  if (suffix[0] == '\0' || has_dir_sep(suffix))
393  message_fatal(_("%s: Invalid filename suffix"), suffix);
394 
395  // Replace the old custom_suffix (if any) with the new suffix.
398  return;
399 }
unsigned char suffix[65536]
Definition: gun.c:164
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
char * xstrdup(const char *) ATTRIBUTE_MALLOC
Definition: util.c:48
void message_fatal(const char *fmt,...)
Definition: message.c:777
#define _(String)
Definition: opintl.h:53
static char * custom_suffix
Definition: suffix.c:25
static bool has_dir_sep(const char *str)
Test if the string contains a directory separator.
Definition: suffix.c:42

References _, custom_suffix, free(), has_dir_sep(), message_fatal(), suffix, and xstrdup().

Referenced by parse_real().