Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make more static arrays const #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/ext_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static int ext_header_common_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_common = {
static const LHAExtHeaderType lha_ext_header_common = {
LHA_EXT_HEADER_COMMON,
ext_header_common_decoder,
2
Expand Down Expand Up @@ -150,7 +150,7 @@ static int ext_header_filename_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_filename = {
static const LHAExtHeaderType lha_ext_header_filename = {
LHA_EXT_HEADER_FILENAME,
ext_header_filename_decoder,
1
Expand Down Expand Up @@ -200,7 +200,7 @@ static int ext_header_path_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_path = {
static const LHAExtHeaderType lha_ext_header_path = {
LHA_EXT_HEADER_PATH,
ext_header_path_decoder,
1
Expand All @@ -224,7 +224,7 @@ static int ext_header_windows_timestamps(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_windows_timestamps = {
static const LHAExtHeaderType lha_ext_header_windows_timestamps = {
LHA_EXT_HEADER_WINDOWS_TIMESTAMPS,
ext_header_windows_timestamps,
24
Expand All @@ -243,7 +243,7 @@ static int ext_header_unix_perms_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_unix_perms = {
static const LHAExtHeaderType lha_ext_header_unix_perms = {
LHA_EXT_HEADER_UNIX_PERMISSION,
ext_header_unix_perms_decoder,
2
Expand All @@ -262,7 +262,7 @@ static int ext_header_unix_uid_gid_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_unix_uid_gid = {
static const LHAExtHeaderType lha_ext_header_unix_uid_gid = {
LHA_EXT_HEADER_UNIX_UID_GID,
ext_header_unix_uid_gid_decoder,
4
Expand Down Expand Up @@ -294,7 +294,7 @@ static int ext_header_unix_username_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_unix_username = {
static const LHAExtHeaderType lha_ext_header_unix_username = {
LHA_EXT_HEADER_UNIX_USER,
ext_header_unix_username_decoder,
1
Expand Down Expand Up @@ -327,7 +327,7 @@ static int ext_header_unix_group_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_unix_group = {
static const LHAExtHeaderType lha_ext_header_unix_group = {
LHA_EXT_HEADER_UNIX_GROUP,
ext_header_unix_group_decoder,
1
Expand All @@ -347,7 +347,7 @@ static int ext_header_unix_timestamp_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_unix_timestamp = {
static const LHAExtHeaderType lha_ext_header_unix_timestamp = {
LHA_EXT_HEADER_UNIX_TIMESTAMP,
ext_header_unix_timestamp_decoder,
4
Expand All @@ -371,15 +371,15 @@ static int ext_header_os9_decoder(LHAFileHeader *header,
return 1;
}

static LHAExtHeaderType lha_ext_header_os9 = {
static const LHAExtHeaderType lha_ext_header_os9 = {
LHA_EXT_HEADER_OS9,
ext_header_os9_decoder,
12
};

// Table of extended headers.

static const LHAExtHeaderType *ext_header_types[] = {
static const LHAExtHeaderType *const ext_header_types[] = {
&lha_ext_header_common,
&lha_ext_header_filename,
&lha_ext_header_path,
Expand Down
2 changes: 1 addition & 1 deletion lib/lh1_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ static size_t lha_lh1_read(void *data, uint8_t *buf)
return result;
}

LHADecoderType lha_lh1_decoder = {
const LHADecoderType lha_lh1_decoder = {
lha_lh1_init,
NULL,
lha_lh1_read,
Expand Down
4 changes: 2 additions & 2 deletions lib/lh_new_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ static size_t lha_lh_new_read(void *data, uint8_t *buf)
return result;
}

LHADecoderType DECODER_NAME = {
const LHADecoderType DECODER_NAME = {
lha_lh_new_init,
NULL,
lha_lh_new_read,
Expand All @@ -617,7 +617,7 @@ LHADecoderType DECODER_NAME = {
// This is a hack for -lh4-:

#ifdef DECODER2_NAME
LHADecoderType DECODER2_NAME = {
const LHADecoderType DECODER2_NAME = {
lha_lh_new_init,
NULL,
lha_lh_new_read,
Expand Down
2 changes: 1 addition & 1 deletion lib/lha_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef enum {
* an error occurred in generating the string.
*/

int lha_arch_vasprintf(char **result, char *fmt, va_list args);
int lha_arch_vasprintf(char **result, const char *fmt, va_list args);

/**
* Change the mode of the specified FILE handle to be binary mode.
Expand Down
2 changes: 1 addition & 1 deletion lib/lha_arch_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
// implementation of it, but develop a compatible workaround for
// operating systems that don't have it.

int lha_arch_vasprintf(char **result, char *fmt, va_list args)
int lha_arch_vasprintf(char **result, const char *fmt, va_list args)
{
return vasprintf(result, fmt, args);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/lha_arch_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

static uint64_t unix_epoch_offset = 0;

int lha_arch_vasprintf(char **result, char *fmt, va_list args)
int lha_arch_vasprintf(char **result, const char *fmt, va_list args)
{
int len;

Expand Down
2 changes: 1 addition & 1 deletion lib/lha_basic_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static size_t decoder_callback(void *buf, size_t buf_len, void *user_data)

LHADecoder *lha_basic_reader_decode(LHABasicReader *reader)
{
LHADecoderType *dtype;
const LHADecoderType *dtype;

if (reader->curr_file == NULL) {
return NULL;
Expand Down
34 changes: 17 additions & 17 deletions lib/lha_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "lha_decoder.h"

// Null decoder, used for -lz4-, -lh0-, -pm0-:
extern LHADecoderType lha_null_decoder;
extern const LHADecoderType lha_null_decoder;

// LArc compression algorithms:
extern LHADecoderType lha_lz5_decoder;
extern LHADecoderType lha_lzs_decoder;
extern const LHADecoderType lha_lz5_decoder;
extern const LHADecoderType lha_lzs_decoder;

// LHarc compression algorithms:
extern LHADecoderType lha_lh1_decoder;
extern LHADecoderType lha_lh4_decoder;
extern LHADecoderType lha_lh5_decoder;
extern LHADecoderType lha_lh6_decoder;
extern LHADecoderType lha_lh7_decoder;
extern LHADecoderType lha_lhx_decoder;
extern LHADecoderType lha_lk7_decoder;
extern const LHADecoderType lha_lh1_decoder;
extern const LHADecoderType lha_lh4_decoder;
extern const LHADecoderType lha_lh5_decoder;
extern const LHADecoderType lha_lh6_decoder;
extern const LHADecoderType lha_lh7_decoder;
extern const LHADecoderType lha_lhx_decoder;
extern const LHADecoderType lha_lk7_decoder;

// PMarc compression algorithms:
extern LHADecoderType lha_pm1_decoder;
extern LHADecoderType lha_pm2_decoder;
extern const LHADecoderType lha_pm1_decoder;
extern const LHADecoderType lha_pm2_decoder;

static struct {
char *name;
LHADecoderType *dtype;
static const struct {
const char *name;
const LHADecoderType *dtype;
} decoders[] = {
{ "-lz4-", &lha_null_decoder },
{ "-lz5-", &lha_lz5_decoder },
Expand All @@ -65,7 +65,7 @@ static struct {
{ "-pm2-", &lha_pm2_decoder },
};

LHADecoder *lha_decoder_new(LHADecoderType *dtype,
LHADecoder *lha_decoder_new(const LHADecoderType *dtype,
LHADecoderCallback callback,
void *callback_data,
size_t stream_length)
Expand Down Expand Up @@ -108,7 +108,7 @@ LHADecoder *lha_decoder_new(LHADecoderType *dtype,
return decoder;
}

LHADecoderType *lha_decoder_for_name(char *name)
const LHADecoderType *lha_decoder_for_name(const char *name)
{
unsigned int i;

Expand Down
2 changes: 1 addition & 1 deletion lib/lha_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct _LHADecoder {

/** Type of decoder (algorithm) */

LHADecoderType *dtype;
const LHADecoderType *dtype;

/** Callback function to monitor decoder progress. */

Expand Down
4 changes: 2 additions & 2 deletions lib/lha_file_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

char *lha_file_header_full_path(LHAFileHeader *header)
{
char *path;
char *filename;
const char *path;
const char *filename;
char *result;

if (header->path != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion lib/lz5_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static size_t lha_lz5_read(void *data, uint8_t *buf)
return result;
}

LHADecoderType lha_lz5_decoder = {
const LHADecoderType lha_lz5_decoder = {
lha_lz5_init,
NULL,
lha_lz5_read,
Expand Down
2 changes: 1 addition & 1 deletion lib/lzs_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static size_t lha_lzs_read(void *data, uint8_t *buf)
return result;
}

LHADecoderType lha_lzs_decoder = {
const LHADecoderType lha_lzs_decoder = {
lha_lzs_init,
NULL,
lha_lzs_read,
Expand Down
2 changes: 1 addition & 1 deletion lib/macbinary.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ static size_t macbinary_decoder_read(void *_decoder, uint8_t *buf)
return result;
}

static LHADecoderType macbinary_decoder_type = {
static const LHADecoderType macbinary_decoder_type = {
macbinary_decoder_init,
NULL,
macbinary_decoder_read,
Expand Down
2 changes: 1 addition & 1 deletion lib/null_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static size_t lha_null_read(void *data, uint8_t *buf)
return decoder->callback(buf, BLOCK_READ_SIZE, decoder->callback_data);
}

LHADecoderType lha_null_decoder = {
const LHADecoderType lha_null_decoder = {
lha_null_init,
NULL,
lha_null_read,
Expand Down
2 changes: 1 addition & 1 deletion lib/pm1_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ static size_t lha_pm1_read(void *data, uint8_t *buf)
}
}

LHADecoderType lha_pm1_decoder = {
const LHADecoderType lha_pm1_decoder = {
lha_pm1_init,
NULL,
lha_pm1_read,
Expand Down
2 changes: 1 addition & 1 deletion lib/pm2_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ static size_t lha_pm2_decoder_read(void *data, uint8_t *buf)
return result;
}

LHADecoderType lha_pm2_decoder = {
const LHADecoderType lha_pm2_decoder = {
lha_pm2_decoder_init,
NULL,
lha_pm2_decoder_read,
Expand Down
4 changes: 2 additions & 2 deletions lib/public/lha_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ typedef void (*LHADecoderProgressCallback)(unsigned int num_blocks,
* is no decoder type for the specified name.
*/

LHADecoderType *lha_decoder_for_name(char *name);
const LHADecoderType *lha_decoder_for_name(const char *name);

/**
* Allocate a new decoder for the specified type.
Expand All @@ -114,7 +114,7 @@ LHADecoderType *lha_decoder_for_name(char *name);
* @return Pointer to the new decoder, or NULL for failure.
*/

LHADecoder *lha_decoder_new(LHADecoderType *dtype,
LHADecoder *lha_decoder_new(const LHADecoderType *dtype,
LHADecoderCallback callback,
void *callback_data,
size_t stream_length);
Expand Down
10 changes: 5 additions & 5 deletions src/extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ typedef struct {
int invoked;
LHAFileHeader *header;
LHAOptions *options;
char *filename;
char *operation;
const char *filename;
const char *operation;
} ProgressCallbackData;

// Given a file header structure, get the path to extract to.
Expand Down Expand Up @@ -109,14 +109,14 @@ static char *file_full_path(LHAFileHeader *header, LHAOptions *options)
return result;
}

static void print_filename(char *filename, char *status)
static void print_filename(const char *filename, const char *status)
{
printf("\r");
safe_printf("%s", filename);
printf("\t- %s ", status);
}

static void print_filename_brief(char *filename)
static void print_filename_brief(const char *filename)
{
printf("\r");
safe_printf("%s :", filename);
Expand Down Expand Up @@ -337,7 +337,7 @@ static int make_parent_directories(char *orig_path)
// Prompt the user with a message, and return the first character of
// the typed response.

static char prompt_user(char *message)
static char prompt_user(const char *message)
{
char result;
int c;
Expand Down
Loading