mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Refactor function signatures to use const char* for string parameters
This commit is contained in:
@@ -83,7 +83,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector(void *context, uint64_t sectorAd
|
|||||||
AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, uint64_t sectorAddress, uint8_t *data,
|
AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, uint64_t sectorAddress, uint8_t *data,
|
||||||
uint32_t *length);
|
uint32_t *length);
|
||||||
|
|
||||||
AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sectorAddress, uint8_t *data,
|
AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sectorAddress, const uint8_t *data,
|
||||||
uint8_t sectorStatus, uint32_t length);
|
uint8_t sectorStatus, uint32_t length);
|
||||||
|
|
||||||
AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context);
|
AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context);
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ struct CacheHeader
|
|||||||
* @param key Key
|
* @param key Key
|
||||||
* @return Value if found, NULL if not
|
* @return Value if found, NULL if not
|
||||||
*/
|
*/
|
||||||
void *find_in_cache(struct CacheHeader *cache, char *key);
|
void *find_in_cache(struct CacheHeader *cache, const char *key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an item to the specified cache
|
* Adds an item to the specified cache
|
||||||
@@ -35,7 +35,7 @@ void *find_in_cache(struct CacheHeader *cache, char *key);
|
|||||||
* @param key Key
|
* @param key Key
|
||||||
* @param value Value
|
* @param value Value
|
||||||
*/
|
*/
|
||||||
void add_to_cache(struct CacheHeader *cache, char *key, void *value);
|
void add_to_cache(struct CacheHeader *cache, const char *key, void *value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds an item in the specified cache using a 64-bit integer key
|
* Finds an item in the specified cache using a 64-bit integer key
|
||||||
|
|||||||
@@ -13,15 +13,15 @@
|
|||||||
// this code is in the public domain http://unlicense.org/
|
// this code is in the public domain http://unlicense.org/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Finds a value in the cache by string key and updates its LRU position.
|
* @brief Finds a value in the cache by string key.
|
||||||
*
|
*
|
||||||
* Searches for a cache entry by key. If found, moves it to the front (most recently used).
|
* Searches for a value in the cache using a string key and moves it to the front if found.
|
||||||
*
|
*
|
||||||
* @param cache Pointer to the cache header.
|
* @param cache Pointer to the cache header.
|
||||||
* @param key String key to search for.
|
* @param key String key to search for.
|
||||||
* @return Pointer to the value if found, or NULL if not found.
|
* @return Pointer to the value if found, or NULL if not found.
|
||||||
*/
|
*/
|
||||||
void *find_in_cache(struct CacheHeader *cache, char *key)
|
void *find_in_cache(struct CacheHeader *cache, const char *key)
|
||||||
{
|
{
|
||||||
struct CacheEntry *entry;
|
struct CacheEntry *entry;
|
||||||
HASH_FIND_STR(cache->cache, key, entry);
|
HASH_FIND_STR(cache->cache, key, entry);
|
||||||
@@ -44,7 +44,7 @@ void *find_in_cache(struct CacheHeader *cache, char *key)
|
|||||||
* @param key String key to add.
|
* @param key String key to add.
|
||||||
* @param value Pointer to the value to store.
|
* @param value Pointer to the value to store.
|
||||||
*/
|
*/
|
||||||
void add_to_cache(struct CacheHeader *cache, char *key, void *value)
|
void add_to_cache(struct CacheHeader *cache, const char *key, void *value)
|
||||||
{
|
{
|
||||||
struct CacheEntry *entry, *tmp_entry;
|
struct CacheEntry *entry, *tmp_entry;
|
||||||
// TODO: Is this needed or we're just losing cycles? uthash does not free the entry
|
// TODO: Is this needed or we're just losing cycles? uthash does not free the entry
|
||||||
|
|||||||
@@ -38,7 +38,8 @@
|
|||||||
* @param length Length of the data buffer.
|
* @param length Length of the data buffer.
|
||||||
* @return AARUF_STATUS_OK on success, or an error code on failure.
|
* @return AARUF_STATUS_OK on success, or an error code on failure.
|
||||||
*/
|
*/
|
||||||
int32_t aaruf_write_sector(void *context, uint64_t sectorAddress, uint8_t *data, uint8_t sectorStatus, uint32_t length)
|
int32_t aaruf_write_sector(void *context, uint64_t sectorAddress, const uint8_t *data, uint8_t sectorStatus,
|
||||||
|
uint32_t length)
|
||||||
{
|
{
|
||||||
TRACE("Entering aaruf_write_sector(%p, %" PRIu64 ", %p, %u, %u)", context, sectorAddress, data, sectorStatus,
|
TRACE("Entering aaruf_write_sector(%p, %" PRIu64 ", %p, %u, %u)", context, sectorAddress, data, sectorStatus,
|
||||||
length);
|
length);
|
||||||
|
|||||||
@@ -23,18 +23,18 @@
|
|||||||
|
|
||||||
#include <aaruformat.h>
|
#include <aaruformat.h>
|
||||||
|
|
||||||
int identify(char *path);
|
int identify(const char *path);
|
||||||
int info(char *path);
|
int info(const char *path);
|
||||||
char *byte_array_to_hex_string(const unsigned char *array, int array_size);
|
char *byte_array_to_hex_string(const unsigned char *array, int array_size);
|
||||||
int read(unsigned long long sector_no, char *path);
|
int read(unsigned long long sector_no, const char *path);
|
||||||
int printhex(unsigned char *array, unsigned int length, int width, bool color);
|
int printhex(unsigned char *array, unsigned int length, int width, bool color);
|
||||||
int read_long(unsigned long long sector_no, char *path);
|
int read_long(unsigned long long sector_no, const char *path);
|
||||||
int verify(const char *path);
|
int verify(const char *path);
|
||||||
int verify_sectors(const char *path);
|
int verify_sectors(const char *path);
|
||||||
bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unknown, bool *has_edc, bool *edc_correct,
|
bool check_cd_sector_channel(CdEccContext *context, uint8_t *sector, bool *unknown, bool *has_edc, bool *edc_correct,
|
||||||
bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct);
|
bool *has_ecc_p, bool *ecc_p_correct, bool *has_ecc_q, bool *ecc_q_correct);
|
||||||
int compare(char *path1, char *path2);
|
int compare(const char *path1, const char *path2);
|
||||||
int cli_compare(char *path1, char *path2);
|
int cli_compare(const char *path1, const char *path2);
|
||||||
int convert(char *input_path, char *output_path);
|
int convert(const char *input_path, const char *output_path);
|
||||||
|
|
||||||
#endif // LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_
|
#endif // LIBAARUFORMAT_TOOL_AARUFORMATTOOL_H_
|
||||||
|
|||||||
@@ -18,28 +18,28 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <aaruformat.h>
|
#include <aaruformat.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "aaruformattool.h"
|
#include "aaruformattool.h"
|
||||||
|
|
||||||
int cli_compare(char *path1, char *path2)
|
int cli_compare(const char *path1, const char *path2)
|
||||||
{
|
{
|
||||||
aaruformatContext *ctx1 = NULL;
|
aaruformatContext *ctx1 = NULL;
|
||||||
aaruformatContext *ctx2 = NULL;
|
aaruformatContext *ctx2 = NULL;
|
||||||
uint8_t *buffer1 = NULL;
|
uint8_t *buffer1 = NULL;
|
||||||
uint8_t *buffer2 = NULL;
|
uint8_t *buffer2 = NULL;
|
||||||
uint32_t buffer1_length = 0;
|
uint32_t buffer1_length = 0;
|
||||||
uint32_t buffer2_length = 0;
|
uint32_t buffer2_length = 0;
|
||||||
uint64_t total_sectors = 0;
|
uint64_t total_sectors = 0;
|
||||||
uint64_t different_sectors = 0;
|
uint64_t different_sectors = 0;
|
||||||
uint64_t sectors_processed = 0;
|
uint64_t sectors_processed = 0;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int32_t read_result1 = 0;
|
int32_t read_result1 = 0;
|
||||||
int32_t read_result2 = 0;
|
int32_t read_result2 = 0;
|
||||||
|
|
||||||
printf("Opening first image: %s\n", path1);
|
printf("Opening first image: %s\n", path1);
|
||||||
ctx1 = aaruf_open(path1);
|
ctx1 = aaruf_open(path1);
|
||||||
@@ -60,27 +60,24 @@ int cli_compare(char *path1, char *path2)
|
|||||||
|
|
||||||
// Access image information through context structure
|
// Access image information through context structure
|
||||||
printf("\nImage Information:\n");
|
printf("\nImage Information:\n");
|
||||||
printf("Image 1: %llu sectors, %u bytes per sector\n",
|
printf("Image 1: %llu sectors, %u bytes per sector\n", (unsigned long long)ctx1->imageInfo.Sectors,
|
||||||
(unsigned long long)ctx1->imageInfo.Sectors, ctx1->imageInfo.SectorSize);
|
ctx1->imageInfo.SectorSize);
|
||||||
printf("Image 2: %llu sectors, %u bytes per sector\n",
|
printf("Image 2: %llu sectors, %u bytes per sector\n", (unsigned long long)ctx2->imageInfo.Sectors,
|
||||||
(unsigned long long)ctx2->imageInfo.Sectors, ctx2->imageInfo.SectorSize);
|
ctx2->imageInfo.SectorSize);
|
||||||
|
|
||||||
if(ctx1->imageInfo.Sectors != ctx2->imageInfo.Sectors)
|
if(ctx1->imageInfo.Sectors != ctx2->imageInfo.Sectors)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Warning: Images have different number of sectors\n");
|
fprintf(stderr, "Warning: Images have different number of sectors\n");
|
||||||
total_sectors = ctx1->imageInfo.Sectors < ctx2->imageInfo.Sectors ?
|
total_sectors =
|
||||||
ctx1->imageInfo.Sectors : ctx2->imageInfo.Sectors;
|
ctx1->imageInfo.Sectors < ctx2->imageInfo.Sectors ? ctx1->imageInfo.Sectors : ctx2->imageInfo.Sectors;
|
||||||
printf("Will compare first %llu sectors\n", (unsigned long long)total_sectors);
|
printf("Will compare first %llu sectors\n", (unsigned long long)total_sectors);
|
||||||
}
|
}
|
||||||
else
|
else { total_sectors = ctx1->imageInfo.Sectors; }
|
||||||
{
|
|
||||||
total_sectors = ctx1->imageInfo.Sectors;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx1->imageInfo.SectorSize != ctx2->imageInfo.SectorSize)
|
if(ctx1->imageInfo.SectorSize != ctx2->imageInfo.SectorSize)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error: Images have different sector sizes (%u vs %u)\n",
|
fprintf(stderr, "Error: Images have different sector sizes (%u vs %u)\n", ctx1->imageInfo.SectorSize,
|
||||||
ctx1->imageInfo.SectorSize, ctx2->imageInfo.SectorSize);
|
ctx2->imageInfo.SectorSize);
|
||||||
aaruf_close(ctx1);
|
aaruf_close(ctx1);
|
||||||
aaruf_close(ctx2);
|
aaruf_close(ctx2);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -128,8 +125,7 @@ int cli_compare(char *path1, char *path2)
|
|||||||
sectors_different = true;
|
sectors_different = true;
|
||||||
}
|
}
|
||||||
else if(sector1_available && sector2_available &&
|
else if(sector1_available && sector2_available &&
|
||||||
(buffer1_length != buffer2_length ||
|
(buffer1_length != buffer2_length || memcmp(buffer1, buffer2, buffer1_length) != 0))
|
||||||
memcmp(buffer1, buffer2, buffer1_length) != 0))
|
|
||||||
{
|
{
|
||||||
// Both sectors are available - compare their content
|
// Both sectors are available - compare their content
|
||||||
sectors_different = true;
|
sectors_different = true;
|
||||||
@@ -154,8 +150,7 @@ int cli_compare(char *path1, char *path2)
|
|||||||
if(sectors_processed % 1000 == 0 || sector == total_sectors - 1)
|
if(sectors_processed % 1000 == 0 || sector == total_sectors - 1)
|
||||||
{
|
{
|
||||||
int progress = (int)((sectors_processed * 100) / total_sectors);
|
int progress = (int)((sectors_processed * 100) / total_sectors);
|
||||||
printf("Progress: %d%% (%llu/%llu sectors)\r",
|
printf("Progress: %d%% (%llu/%llu sectors)\r", progress, (unsigned long long)sectors_processed,
|
||||||
progress, (unsigned long long)sectors_processed,
|
|
||||||
(unsigned long long)total_sectors);
|
(unsigned long long)total_sectors);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
@@ -173,8 +168,7 @@ int cli_compare(char *path1, char *path2)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("✗ Images are different (%llu sectors differ)\n",
|
printf("✗ Images are different (%llu sectors differ)\n", (unsigned long long)different_sectors);
|
||||||
(unsigned long long)different_sectors);
|
|
||||||
result = 1; // Non-zero exit code to indicate differences
|
result = 1; // Non-zero exit code to indicate differences
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void draw_progress_bar(int row, int percent)
|
|||||||
tb_present();
|
tb_present();
|
||||||
}
|
}
|
||||||
|
|
||||||
int compare(char *path1, char *path2)
|
int compare(const char *path1, const char *path2)
|
||||||
{
|
{
|
||||||
int ret = AARUF_STATUS_OK;
|
int ret = AARUF_STATUS_OK;
|
||||||
aaruformatContext *ctx1 = NULL;
|
aaruformatContext *ctx1 = NULL;
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include "aaruformattool.h"
|
#include "aaruformattool.h"
|
||||||
|
|
||||||
int convert(char *input_path, char *output_path)
|
int convert(const char *input_path, const char *output_path)
|
||||||
{
|
{
|
||||||
aaruformatContext *input_ctx = NULL;
|
aaruformatContext *input_ctx = NULL;
|
||||||
aaruformatContext *output_ctx = NULL;
|
aaruformatContext *output_ctx = NULL;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <aaruformat.h>
|
#include <aaruformat.h>
|
||||||
|
|
||||||
int identify(char *path)
|
int identify(const char *path)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#include "aaruformattool.h"
|
#include "aaruformattool.h"
|
||||||
|
|
||||||
int info(char *path)
|
int info(const char *path)
|
||||||
{
|
{
|
||||||
aaruformatContext *ctx = NULL;
|
aaruformatContext *ctx = NULL;
|
||||||
char *strBuffer = NULL;
|
char *strBuffer = NULL;
|
||||||
|
|||||||
24
tool/read.c
24
tool/read.c
@@ -24,12 +24,12 @@
|
|||||||
|
|
||||||
#include "aaruformattool.h"
|
#include "aaruformattool.h"
|
||||||
|
|
||||||
int read(unsigned long long sector_no, char *path)
|
int read(unsigned long long sector_no, const char *path)
|
||||||
{
|
{
|
||||||
aaruformatContext *ctx = NULL;
|
aaruformatContext *ctx = NULL;
|
||||||
int32_t res = 0;
|
int32_t res = 0;
|
||||||
uint32_t length = 0;
|
uint32_t length = 0;
|
||||||
uint8_t *data = NULL;
|
uint8_t *data = NULL;
|
||||||
|
|
||||||
ctx = aaruf_open(path);
|
ctx = aaruf_open(path);
|
||||||
|
|
||||||
@@ -72,14 +72,16 @@ int read(unsigned long long sector_no, char *path)
|
|||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
aaruf_close(ctx);
|
aaruf_close(ctx);
|
||||||
|
|
||||||
|
return AARUF_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_long(unsigned long long sector_no, char *path)
|
int read_long(unsigned long long sector_no, const char *path)
|
||||||
{
|
{
|
||||||
aaruformatContext *ctx = NULL;
|
aaruformatContext *ctx = NULL;
|
||||||
int32_t res = 0;
|
int32_t res = 0;
|
||||||
uint32_t length = 0;
|
uint32_t length = 0;
|
||||||
uint8_t *data = NULL;
|
uint8_t *data = NULL;
|
||||||
|
|
||||||
ctx = aaruf_open(path);
|
ctx = aaruf_open(path);
|
||||||
|
|
||||||
@@ -122,4 +124,6 @@ int read_long(unsigned long long sector_no, char *path)
|
|||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
aaruf_close(ctx);
|
aaruf_close(ctx);
|
||||||
|
|
||||||
|
return AARUF_STATUS_OK;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user