diff --git a/src/convert.c b/src/convert.c index cf196b8..a3fde03 100644 --- a/src/convert.c +++ b/src/convert.c @@ -3,11 +3,13 @@ * * This file is part of the MiniVHD Project. * - * Version: @(#)convert.c 1.0.1 2021/03/16 + * Version: @(#)convert.c 1.0.2 2021/04/16 * - * Author: Sherman Perry, + * Authors: Sherman Perry, + * Fred N. van Kempen, * * Copyright 2019-2021 Sherman Perry. + * Copyright 2021 Fred N. van Kempen. * * MIT License * @@ -40,7 +42,7 @@ #include #include #include -#define BUILDING_DLL +#define BUILDING_LIBRARY #include "minivhd.h" #include "internal.h" @@ -75,7 +77,7 @@ open_existing_raw_img(const char* utf8_raw_path, MVHDGeom* geom, int* err) } -MVHDMeta * +MVHDAPI MVHDMeta * mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_vhd_path, int* err) { MVHDGeom geom; @@ -95,7 +97,7 @@ mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_vhd_path, } -MVHDMeta * +MVHDAPI MVHDMeta * mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8_vhd_path, int* err) { MVHDGeom geom; @@ -136,7 +138,7 @@ end: } -FILE * +MVHDAPI FILE * mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, int *err) { FILE *raw_img = mvhd_fopen(utf8_raw_path, "wb", err); diff --git a/src/create.c b/src/create.c index 449f71c..c7e7d4c 100644 --- a/src/create.c +++ b/src/create.c @@ -3,12 +3,13 @@ * * This file is part of the MiniVHD Project. * - * Version: @(#)create.c 1.0.2 2021/03/16 + * Version: @(#)create.c 1.0.3 2021/04/16 * * Authors: Sherman Perry, * Fred N. van Kempen, * * Copyright 2019-2021 Sherman Perry. + * Copyright 2021 Fred N. van Kempen. * * MIT License * @@ -42,7 +43,7 @@ #include #include #include -#define BUILDING_DLL +#define BUILDING_LIBRARY #include "minivhd.h" #include "internal.h" #include "cwalk.h" @@ -210,7 +211,7 @@ end: } -MVHDMeta * +MVHDAPI MVHDMeta * mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_progress_callback progress_callback) { uint64_t size_in_bytes = mvhd_calc_size_bytes(&geom); @@ -482,7 +483,7 @@ end: } -MVHDMeta * +MVHDAPI MVHDMeta * mvhd_create_sparse(const char* path, MVHDGeom geom, int* err) { uint64_t size_in_bytes = mvhd_calc_size_bytes(&geom); @@ -491,14 +492,14 @@ mvhd_create_sparse(const char* path, MVHDGeom geom, int* err) } -MVHDMeta * +MVHDAPI MVHDMeta * mvhd_create_diff(const char* path, const char* par_path, int* err) { return create_sparse_diff(path, par_path, 0, NULL, MVHD_BLOCK_LARGE, err); } -MVHDMeta * +MVHDAPI MVHDMeta * mvhd_create_ex(MVHDCreationOptions options, int* err) { uint32_t geom_sector_size; diff --git a/src/io.c b/src/io.c index 0e7469a..6b9a9c5 100644 --- a/src/io.c +++ b/src/io.c @@ -5,7 +5,7 @@ * * Sector reading and writing implementations. * - * Version: @(#)io.c 1.0.2 2021/03/16 + * Version: @(#)io.c 1.0.3 2021/04/16 * * Author: Sherman Perry, * @@ -42,17 +42,19 @@ #include #include #include -#define BUILDING_DLL +#define BUILDING_LIBRARY #include "minivhd.h" #include "internal.h" -/* The following bit array macros adapted from - http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html */ - -#define VHD_SETBIT(A,k) ( A[(k/8)] |= (0x80 >> (k%8)) ) -#define VHD_CLEARBIT(A,k) ( A[(k/8)] &= ~(0x80 >> (k%8)) ) -#define VHD_TESTBIT(A,k) ( A[(k/8)] & (0x80 >> (k%8)) ) +/* + * The following bit array macros adapted from: + * + * http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html +*/ +#define VHD_SETBIT(A,k) ( A[(k>>3)] |= (0x80 >> (k&7)) ) +#define VHD_CLEARBIT(A,k) ( A[(k>>3)] &= ~(0x80 >> (k&7)) ) +#define VHD_TESTBIT(A,k) ( A[(k>>3)] & (0x80 >> (k&7)) ) /** diff --git a/src/manage.c b/src/manage.c index 01cff2c..84f5445 100644 --- a/src/manage.c +++ b/src/manage.c @@ -5,11 +5,13 @@ * * VHD management functions (open, close, read write etc) * - * Version: @(#)manage.c 1.0.3 2021/03/22 + * Version: @(#)manage.c 1.0.4 2021/04/16 * - * Author: Sherman Perry, + * Authors: Sherman Perry, + * Fred N. van Kempen, * * Copyright 2019-2021 Sherman Perry. + * Copyright 2021 Fred N. van Kempen. * * MIT License * @@ -42,7 +44,7 @@ #include #include #include -#define BUILDING_DLL +#define BUILDING_LIBRARY #include "minivhd.h" #include "internal.h" #include "version.h" @@ -51,12 +53,12 @@ struct MVHDPaths { - char dir_path[MVHD_MAX_PATH_BYTES]; - char file_name[MVHD_MAX_PATH_BYTES]; - char w2ku_path[MVHD_MAX_PATH_BYTES]; - char w2ru_path[MVHD_MAX_PATH_BYTES]; - char joined_path[MVHD_MAX_PATH_BYTES]; - uint16_t tmp_src_path[MVHD_MAX_PATH_CHARS]; + char dir_path[MVHD_MAX_PATH_BYTES]; + char file_name[MVHD_MAX_PATH_BYTES]; + char w2ku_path[MVHD_MAX_PATH_BYTES]; + char w2ru_path[MVHD_MAX_PATH_BYTES]; + char joined_path[MVHD_MAX_PATH_BYTES]; + uint16_t tmp_src_path[MVHD_MAX_PATH_CHARS]; }; @@ -275,7 +277,7 @@ mvhd_parent_path_exists(struct MVHDPaths* paths, uint32_t plat_code) * \return a pointer to the global string `tmp_open_path`, or NULL if a path could * not be found, or some error occurred */ -static char* +static char * get_diff_parent_path(MVHDMeta* vhdm, int* err) { int utf_outlen, utf_inlen, utf_ret; @@ -410,7 +412,7 @@ assign_io_funcs(MVHDMeta* vhdm) /** * \brief Return the library version as a string */ -const char * +MVHDAPI const char * mvhd_version(void) { return LIB_VERSION_4; @@ -420,7 +422,7 @@ mvhd_version(void) /** * \brief Return the library version as a number */ -uint32_t +MVHDAPI uint32_t mvhd_version_id(void) { return (LIB_VER_MAJOR << 24) | (LIB_VER_MINOR << 16) | @@ -436,7 +438,7 @@ mvhd_version_id(void) * \retval 1 if f is a VHD * \retval 0 if f is not a VHD */ -int +MVHDAPI int mvhd_file_is_vhd(FILE* f) { uint8_t con_str[8]; @@ -455,7 +457,7 @@ mvhd_file_is_vhd(FILE* f) } -MVHDGeom +MVHDAPI MVHDGeom mvhd_calculate_geometry(uint64_t size) { MVHDGeom chs; @@ -498,7 +500,7 @@ mvhd_calculate_geometry(uint64_t size) } -MVHDMeta * +MVHDAPI MVHDMeta * mvhd_open(const char* path, int readonly, int* err) { MVHDError open_err; @@ -624,7 +626,7 @@ end: } -void +MVHDAPI void mvhd_close(MVHDMeta* vhdm) { if (vhdm == NULL) @@ -653,7 +655,7 @@ mvhd_close(MVHDMeta* vhdm) } -int +MVHDAPI int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err) { uint8_t sparse_buff[1024]; @@ -688,21 +690,21 @@ mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err) } -int +MVHDAPI int mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff) { return vhdm->read_sectors(vhdm, offset, num_sectors, out_buff); } -int +MVHDAPI int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff) { return vhdm->write_sectors(vhdm, offset, num_sectors, in_buff); } -int +MVHDAPI int mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors) { int num_full = num_sectors / vhdm->format_buffer.sector_count; @@ -720,7 +722,7 @@ mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors) } -MVHDType +MVHDAPI MVHDType mvhd_get_type(MVHDMeta* vhdm) { return vhdm->footer.disk_type; diff --git a/src/minivhd.h b/src/minivhd.h index 677f4da..4df5dc1 100644 --- a/src/minivhd.h +++ b/src/minivhd.h @@ -10,11 +10,13 @@ * * Definitions for the MiniVHD library. * - * Version: @(#)minivhd.h 1.0.2 2021/03/22 + * Version: @(#)minivhd.h 1.0.3 2021/04/16 * - * Author: Sherman Perry, + * Authors: Sherman Perry, + * Fred N. van Kempen, * * Copyright 2019-2021 Sherman Perry. + * Copyright 2021 Fred N. van Kempen. * * MIT License * @@ -106,36 +108,36 @@ extern int mvhd_errno; /* Shared-library madness. */ -#ifdef STATIC -# define MVHD_API /*nothing*/ -#else -# if defined(_WIN32) && !defined(__GNUC__) -# ifdef BUILDING_DLL -# define MVHD_API __declspec(dllexport) -# else -# define MVHD_API //__declspec(dllimport) -# endif -# elif defined(__GNUC__) -# ifdef BUILDING_DLL -# define MVHD_API __attribute__((visibility("default"))) -# else -# define MVHD_API /*nothing*/ -# endif +#if defined(_WIN32) +# ifdef STATIC +# define MVHDAPI /*nothing*/ # else -# define MVHD_API /*nothing*/ -# endif +# ifdef BUILDING_LIBRARY +# define MVHDAPI __declspec(dllexport) +# else +# define MVHDAPI __declspec(dllimport) +# endif +# endif +#elif defined(__GNUC__) +# ifdef BUILDING_LIBRARY +# define MVHDAPI __attribute__((visibility("default"))) +# else +# define MVHDAPI /*nothing*/ +# endif +#else +# define MVHDAPI /*nothing*/ #endif /** * \brief Return the library version as a string */ -MVHD_API const char *mvhd_version(void); +MVHDAPI const char *mvhd_version(void); /** * \brief Return the library version as a number */ -MVHD_API uint32_t mvhd_version_id(void); +MVHDAPI uint32_t mvhd_version_id(void); /** * \brief Output a string from a MiniVHD error number @@ -144,7 +146,7 @@ MVHD_API uint32_t mvhd_version_id(void); * * \return Error string */ -MVHD_API const char* mvhd_strerr(MVHDError err); +MVHDAPI const char* mvhd_strerr(MVHDError err); /** * \brief A simple test to see if a given file is a VHD @@ -154,7 +156,7 @@ MVHD_API const char* mvhd_strerr(MVHDError err); * \retval 1 if f is a VHD * \retval 0 if f is not a VHD */ -MVHD_API int mvhd_file_is_vhd(FILE* f); +MVHDAPI int mvhd_file_is_vhd(FILE* f); /** * \brief Return the file type of the given file @@ -163,7 +165,7 @@ MVHD_API int mvhd_file_is_vhd(FILE* f); * * \retval one of the defined MVHDType values */ -MVHD_API MVHDType mvhd_get_type(MVHDMeta* vhdm); +MVHDAPI MVHDType mvhd_get_type(MVHDMeta* vhdm); /** * \brief Open a VHD image for reading and/or writing @@ -184,7 +186,7 @@ MVHD_API MVHDType mvhd_get_type(MVHDMeta* vhdm); * \return MVHDMeta pointer. If NULL, check err. err may also be set to MVHD_ERR_TIMESTAMP if * opening a differencing VHD. */ -MVHD_API MVHDMeta* mvhd_open(const char* path, int readonly, int* err); +MVHDAPI MVHDMeta* mvhd_open(const char* path, int readonly, int* err); /** * \brief Update the parent modified timestamp in the VHD file @@ -202,7 +204,7 @@ MVHD_API MVHDMeta* mvhd_open(const char* path, int readonly, int* err); * * \return non-zero on error, 0 on success */ -MVHD_API int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err); +MVHDAPI int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err); /** * \brief Create a fixed VHD image @@ -214,7 +216,7 @@ MVHD_API int mvhd_diff_update_par_timestamp(MVHDMeta* vhdm, int* err); * * \retval NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHD_API MVHDMeta* mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_progress_callback progress_callback); +MVHDAPI MVHDMeta* mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, mvhd_progress_callback progress_callback); /** * \brief Create sparse (dynamic) VHD image. @@ -225,7 +227,7 @@ MVHD_API MVHDMeta* mvhd_create_fixed(const char* path, MVHDGeom geom, int* err, * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHD_API MVHDMeta* mvhd_create_sparse(const char* path, MVHDGeom geom, int* err); +MVHDAPI MVHDMeta* mvhd_create_sparse(const char* path, MVHDGeom geom, int* err); /** * \brief Create differencing VHD imagee. @@ -236,7 +238,7 @@ MVHD_API MVHDMeta* mvhd_create_sparse(const char* path, MVHDGeom geom, int* err) * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHD_API MVHDMeta* mvhd_create_diff(const char* path, const char* par_path, int* err); +MVHDAPI MVHDMeta* mvhd_create_diff(const char* path, const char* par_path, int* err); /** * \brief Create a VHD using the provided options @@ -248,14 +250,14 @@ MVHD_API MVHDMeta* mvhd_create_diff(const char* path, const char* par_path, int* * * \retval NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHD_API MVHDMeta* mvhd_create_ex(MVHDCreationOptions options, int* err); +MVHDAPI MVHDMeta* mvhd_create_ex(MVHDCreationOptions options, int* err); /** * \brief Safely close a VHD image * * \param [in] vhdm MiniVHD data structure to close */ -MVHD_API void mvhd_close(MVHDMeta* vhdm); +MVHDAPI void mvhd_close(MVHDMeta* vhdm); /** * \brief Calculate hard disk geometry from a provided size @@ -275,7 +277,7 @@ MVHD_API void mvhd_close(MVHDMeta* vhdm); * * \return MVHDGeom the calculated geometry. This can be used in the appropriate create functions. */ -MVHD_API MVHDGeom mvhd_calculate_geometry(uint64_t size); +MVHDAPI MVHDGeom mvhd_calculate_geometry(uint64_t size); /** * \brief Get the CHS geometry from the image @@ -284,7 +286,7 @@ MVHD_API MVHDGeom mvhd_calculate_geometry(uint64_t size); * * \return The CHS geometry as stored in the image */ -MVHD_API MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm); +MVHDAPI MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm); /** * \brief Get the 'current_size' value from the image @@ -297,7 +299,7 @@ MVHD_API MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm); * \return The 'current_size' value in bytes, as stored in the image. * Note, this may not match the CHS geometry. */ -MVHD_API uint64_t mvhd_get_current_size(MVHDMeta* vhdm); +MVHDAPI uint64_t mvhd_get_current_size(MVHDMeta* vhdm); /** * \brief Calculate CHS geometry size in bytes @@ -306,7 +308,7 @@ MVHD_API uint64_t mvhd_get_current_size(MVHDMeta* vhdm); * * \return the size in bytes */ -MVHD_API uint64_t mvhd_calc_size_bytes(MVHDGeom *geom); +MVHDAPI uint64_t mvhd_calc_size_bytes(MVHDGeom *geom); /** * \brief Calculate CHS geometry size in sectors @@ -315,7 +317,7 @@ MVHD_API uint64_t mvhd_calc_size_bytes(MVHDGeom *geom); * * \return the size in sectors */ -MVHD_API uint32_t mvhd_calc_size_sectors(MVHDGeom *geom); +MVHDAPI uint32_t mvhd_calc_size_sectors(MVHDGeom *geom); /** * \brief Convert a raw disk image to a fixed VHD image @@ -326,7 +328,7 @@ MVHD_API uint32_t mvhd_calc_size_sectors(MVHDGeom *geom); * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHD_API MVHDMeta* mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_vhd_path, int* err); +MVHDAPI MVHDMeta* mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const char* utf8_vhd_path, int* err); /** * \brief Convert a raw disk image to a sparse VHD image @@ -337,7 +339,7 @@ MVHD_API MVHDMeta* mvhd_convert_to_vhd_fixed(const char* utf8_raw_path, const ch * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns pointer to a MVHDMeta struct */ -MVHD_API MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8_vhd_path, int* err); +MVHDAPI MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const char* utf8_vhd_path, int* err); /** * \brief Convert a VHD image to a raw disk image @@ -348,7 +350,7 @@ MVHD_API MVHDMeta* mvhd_convert_to_vhd_sparse(const char* utf8_raw_path, const c * * \return NULL if an error occurrs. Check value of *err for actual error. Otherwise returns the raw disk image FILE pointer */ -MVHD_API FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, int *err); +MVHDAPI FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_raw_path, int *err); /** * \brief Read sectors from VHD file @@ -362,7 +364,7 @@ MVHD_API FILE* mvhd_convert_to_raw(const char* utf8_vhd_path, const char* utf8_r * * \return the number of sectors that were not read, or zero */ -MVHD_API int mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); +MVHDAPI int mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* out_buff); /** * \brief Write sectors to VHD file @@ -376,7 +378,7 @@ MVHD_API int mvhd_read_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, * * \return the number of sectors that were not written, or zero */ -MVHD_API int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); +MVHDAPI int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors, void* in_buff); /** * \brief Write zeroed sectors to VHD file @@ -391,7 +393,7 @@ MVHD_API int mvhd_write_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors * * \return the number of sectors that were not written, or zero */ -MVHD_API int mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors); +MVHDAPI int mvhd_format_sectors(MVHDMeta* vhdm, uint32_t offset, int num_sectors); #ifdef __cplusplus } diff --git a/src/struct_rw.c b/src/struct_rw.c index 6f64b73..e683505 100644 --- a/src/struct_rw.c +++ b/src/struct_rw.c @@ -5,7 +5,17 @@ * * Header and footer serialize/deserialize functions. * - * Version: @(#)struct_rw.c 1.0.1 2021/03/16 + * Read data from footer into the struct members, swapping + * endian where necessary. + * + * NOTE: Order matters here! + * We must read each field in the order the struct is in. + * Doing this may be less elegant than performing a memcpy + * to a packed struct, but it avoids potential data alignment + * issues, and the endian swapping allows us to use the fields + * directly. + * + * Version: @(#)struct_rw.c 1.0.2 2021/04/16 * * Author: Sherman Perry, * @@ -42,18 +52,11 @@ #include #include #include -#define BUILDING_DLL +#define BUILDING_LIBRARY #include "minivhd.h" #include "internal.h" -/* Read data from footer into the struct members, swapping endian where necessary - Note: order matters here! We must read each field in the order the struct is in. - Doing this may be less elegant than performing a memcpy to a packed struct, but - it avoids potential data alignment issues, and the endian swapping allows us to - use the fields directly. */ - - /** * \brief Get the next field from a buffer and store it in a struct member, converting endian if necessary * @@ -67,18 +70,18 @@ next_buffer_to_struct(void* struct_memb, size_t memb_size, bool req_endian, uint { memcpy(struct_memb, *buffer, memb_size); - if (req_endian) { - switch (memb_size) { + if (req_endian) switch (memb_size) { case 2: *(uint16_t*)(struct_memb) = mvhd_from_be16(*(uint16_t*)(struct_memb)); break; + case 4: *(uint32_t*)(struct_memb) = mvhd_from_be32(*(uint32_t*)(struct_memb)); break; + case 8: *(uint64_t*)(struct_memb) = mvhd_from_be64(*(uint64_t*)(struct_memb)); break; - } } *buffer += memb_size; @@ -100,18 +103,18 @@ next_struct_to_buffer(void* struct_memb, size_t memb_size, bool req_endian, uint memcpy(buf_ptr, struct_memb, memb_size); - if (req_endian) { - switch (memb_size) { + if (req_endian) switch (memb_size) { case 2: *((uint16_t*)buf_ptr) = mvhd_to_be16(*(uint16_t*)(struct_memb)); break; + case 4: *((uint32_t*)buf_ptr) = mvhd_to_be32(*(uint32_t*)(struct_memb)); break; + case 8: *((uint64_t*)buf_ptr) = mvhd_to_be64(*(uint64_t*)(struct_memb)); break; - } } buf_ptr += memb_size; @@ -175,6 +178,7 @@ void mvhd_buffer_to_header(MVHDSparseHeader* header, uint8_t* buffer) { uint8_t* buff_ptr = buffer; + int i; next_buffer_to_struct(&header->cookie, sizeof header->cookie, false, &buff_ptr); next_buffer_to_struct(&header->data_offset, sizeof header->data_offset, true, &buff_ptr); @@ -188,7 +192,6 @@ mvhd_buffer_to_header(MVHDSparseHeader* header, uint8_t* buffer) next_buffer_to_struct(&header->reserved_1, sizeof header->reserved_1, true, &buff_ptr); next_buffer_to_struct(&header->par_utf16_name, sizeof header->par_utf16_name, false, &buff_ptr); - int i; for (i = 0; i < 8; i++) { next_buffer_to_struct(&header->par_loc_entry[i].plat_code, sizeof header->par_loc_entry[i].plat_code, true, &buff_ptr); next_buffer_to_struct(&header->par_loc_entry[i].plat_data_space, sizeof header->par_loc_entry[i].plat_data_space, true, &buff_ptr); @@ -205,6 +208,7 @@ void mvhd_header_to_buffer(MVHDSparseHeader* header, uint8_t* buffer) { uint8_t* buff_ptr = buffer; + int i; next_struct_to_buffer(&header->cookie, sizeof header->cookie, false, &buff_ptr); next_struct_to_buffer(&header->data_offset, sizeof header->data_offset, true, &buff_ptr); @@ -218,7 +222,6 @@ mvhd_header_to_buffer(MVHDSparseHeader* header, uint8_t* buffer) next_struct_to_buffer(&header->reserved_1, sizeof header->reserved_1, true, &buff_ptr); next_struct_to_buffer(&header->par_utf16_name, sizeof header->par_utf16_name, false, &buff_ptr); - int i; for (i = 0; i < 8; i++) { next_struct_to_buffer(&header->par_loc_entry[i].plat_code, sizeof header->par_loc_entry[i].plat_code, true, &buff_ptr); next_struct_to_buffer(&header->par_loc_entry[i].plat_data_space, sizeof header->par_loc_entry[i].plat_data_space, true, &buff_ptr); diff --git a/src/unix/Makefile.linux b/src/unix/Makefile.linux index b0bf8c1..05f6315 100644 --- a/src/unix/Makefile.linux +++ b/src/unix/Makefile.linux @@ -10,12 +10,11 @@ # # Makefile for UNIX and Linux systems using GCC. # -# Version: @(#)Makefile.GCC 1.0.1 2021/03/16 +# Version: @(#)Makefile.GCC 1.0.2 2021/04/16 # # Author: Fred N. van Kempen, # # Copyright 2021 Fred N. van Kempen. -# Copyright 2019-2021 Sherman Perry. # # MIT License # @@ -52,6 +51,9 @@ endif ifndef X64 X64 := n endif +ifndef STATIC + STATIC := n +endif # Name of the projects. @@ -106,6 +108,9 @@ DEPFILE := $(PLATDIR)/.depends-$(PLATNAME) # Set up the correct toolchain flags. OPTS := -DUNIX $(PLATDEFS) +ifeq ($(STATIC), y) + OPTS := -DSTATIC +endif AFLAGS := -msse2 -mfpmath=sse COPTS := -Wall CXXOPTS := -Wall @@ -153,7 +158,7 @@ ifeq ($(AUTODEP), y) else %.o: %.c @echo $< - @$(CC) $(CFLAGS) -c $< + $(CC) $(CFLAGS) -c $< %.o: %.cpp @echo $< @@ -169,7 +174,11 @@ else endif -all: $(LIBS).so $(LIBS).a $(PROGS) $(PROGS)_s +ifeq ($(STATIC),y) +all: $(LIBS).a $(PROGS)_s +else +all: $(LIBS).so $(PROGS) +endif $(LIBS).so: $(LOBJ) @@ -179,21 +188,22 @@ ifneq ($(DEBUG), y) @$(STRIP) --strip-unneeded $(LIBS).so endif + $(LIBS).a: $(LOBJ) @echo Creating $@ .. @$(AR) rv $@ $(LOBJ) @$(RANLIB) $@ -$(PROGS): $(PROGS).o +$(PROGS): tester.o @echo Linking $@ .. - $(CC) $(LFLAGS) -o $@ $(PROGS).o $(SYSLIBS) -lminivhd + $(CC) $(LFLAGS) -o $@ $< $(SYSLIBS) -lminivhd ifneq ($(DEBUG), y) @$(STRIP) $@ endif -$(PROGS)_s: $(PROGS).o +$(PROGS)_s: tester.o @echo Linking $@ .. - $(CC) $(LFLAGS) -o $@ $(PROGS).o $(SYSLIBS) -static -lminivhd + $(CC) $(LFLAGS) -o $@ $< $(SYSLIBS) -static -lminivhd -shared ifneq ($(DEBUG), y) @$(STRIP) $@ endif diff --git a/src/util.c b/src/util.c index 3e02999..8f0547f 100644 --- a/src/util.c +++ b/src/util.c @@ -5,7 +5,7 @@ * * Utility functions. * - * Version: @(#)util.c 1.0.3 2021/03/22 + * Version: @(#)util.c 1.0.4 2021/04/16 * * Author: Sherman Perry, * @@ -46,7 +46,7 @@ #include #include #include -#define BUILDING_DLL +#define BUILDING_LIBRARY #include "minivhd.h" #include "internal.h" #include "xml2_encoding.h" @@ -272,7 +272,7 @@ mvhd_calc_size_sectors(MVHDGeom *geom) } -MVHDGeom +MVHDAPI MVHDGeom mvhd_get_geometry(MVHDMeta* vhdm) { MVHDGeom geometry = { @@ -285,7 +285,7 @@ mvhd_get_geometry(MVHDMeta* vhdm) } -uint64_t +MVHDAPI uint64_t mvhd_get_current_size(MVHDMeta* vhdm) { return vhdm->footer.curr_sz; @@ -327,7 +327,7 @@ mvhd_gen_sparse_checksum(MVHDSparseHeader* header) } -const char * +MVHDAPI const char * mvhd_strerr(MVHDError err) { const char *s = "unknown error"; diff --git a/src/version.h b/src/version.h index 25429ee..badc53f 100644 --- a/src/version.h +++ b/src/version.h @@ -5,7 +5,7 @@ * * Define library version and build info. * - * Version: @(#)version.h 1.0.2 2021/03/22 + * Version: @(#)version.h 1.034 2021/04/16 * * Author: Fred N. van Kempen, * @@ -44,7 +44,7 @@ /* Version info. */ #define LIB_VER_MAJOR 1 #define LIB_VER_MINOR 0 -#define LIB_VER_REV 2 +#define LIB_VER_REV 3 #define LIB_VER_PATCH 0 diff --git a/src/win32/Makefile.MinGW b/src/win32/Makefile.MinGW index 3f90cf7..2770742 100644 --- a/src/win32/Makefile.MinGW +++ b/src/win32/Makefile.MinGW @@ -10,7 +10,7 @@ # # Makefile for Windows systems using the MinGW32 environment. # -# Version: @(#)Makefile.MinGW 1.0.2 2021/03/16 +# Version: @(#)Makefile.MinGW 1.0.3 2021/04/16 # # Author: Fred N. van Kempen, # @@ -57,6 +57,9 @@ endif ifndef X64 X64 := n endif +ifndef STATIC + STATIC := n +endif # Name of the projects. @@ -79,6 +82,7 @@ VPATH := win32 # ifneq ($(CROSS), n) # Cross-compiling (under Linux), select proper version. + PREFIX := /usr/bin/ ifeq ($(X64), y) MINGW := x86_64-w64-mingw32 else @@ -86,14 +90,14 @@ ifneq ($(CROSS), n) endif ifeq ($(X64), y) - CPP := /usr/bin/$(MINGW)-g++ -m64 - CC := /usr/bin/$(MINGW)-gcc -m64 + CPP := $(PREFIX)/$(MINGW)-g++ -m64 + CC := $(PREFIX)/$(MINGW)-gcc -m64 else - CPP := /usr/bin/$(MINGW)-g++ -m32 - CC := /usr/bin/$(MINGW)-gcc -m32 + CPP := $(PREFIX)/$(MINGW)-g++ -m32 + CC := $(PREFIX)/$(MINGW)-gcc -m32 endif - PREPROC := /usr/bin/$(MINGW)-cpp - WINDRES := /usr/bin/$(MINGW)-windres + PREPROC := $(PREFIX)/$(MINGW)-cpp + WINDRES := $(PREFIX)/$(MINGW)-windres SYSINC := -I/usr/$(MINGW)/include SYSLIB := -L/usr/$(MINGW)/lib @@ -125,6 +129,9 @@ DEPFILE := win32/.depends-mingw # Set up the correct toolchain flags. OPTS := -D_CRT_NON_CONFORMING_SWPRINTFS \ -D__USE_MINGW_ANSI_STDIO_X +ifeq ($(STATIC), y) + OPTS += -DSTATIC +endif AFLAGS := -msse2 -mfpmath=sse RFLAGS := --input-format=rc -O coff LFLAGS := @@ -197,7 +204,7 @@ ifeq ($(AUTODEP), y) else %.o: %.c @echo $< - @$(CC) $(CFLAGS) -c $< + $(CC) $(CFLAGS) -c $< %.o: %.cpp @echo $< @@ -213,7 +220,11 @@ else endif -all: $(LIBS).dll $(LNAME).a $(PROGS).exe $(PROGS)_s.exe +ifeq ($(STATIC), y) +all: $(LNAME).a $(PROGS)_s.exe +else +all: $(LIBS).dll $(PROGS).exe +endif $(LIBS).res: win32/minivhd.rc diff --git a/src/win32/Makefile.VC b/src/win32/Makefile.VC index dfd97a3..65cfaee 100644 --- a/src/win32/Makefile.VC +++ b/src/win32/Makefile.VC @@ -10,7 +10,7 @@ # # Makefile for Windows using Microsoft Visual Studio. # -# Version: @(#)Makefile.VC 1.0.1 2021/03/16 +# Version: @(#)Makefile.VC 1.0.2 2021/04/16 # # Author: Fred N. van Kempen, # @@ -55,6 +55,9 @@ endif ifndef X64 X64 := n endif +ifndef STATIC + STATIC := n +endif # Name of the projects. @@ -76,7 +79,6 @@ VPATH := win32 # # Select the required build environment. # -VCOPTS := -D_CRT_SECURE_NO_WARNINGS -D__MSC__ ifeq ($(X64), y) ARCH := x64 CPP := cl -nologo @@ -101,25 +103,28 @@ DEPFILE := win32\.depends-msvc # Set up the correct toolchain flags. -OPTS := $(VCOPTS) \ +OPTS := -D__MSC__ \ -D_USE_MATH_DEFINES \ -D_CRT_NONSTDC_NO_DEPRECATE \ -D_WINSOCK_DEPRECATED_NO_WARNINGS \ -D_CRT_SECURE_NO_WARNINGS \ -D_CRT_STDIO_ISO_WIDE_SPECIFIERS +ifeq ($(STATIC), y) + OPTS += -DSTATIC +endif AFLAGS := #/arch:SSE2 RFLAGS := /n COPTS := -W3 CXXOPTS := -EHsc DOPTS := ifeq ($(X64), y) -LOPTS := -MACHINE:$(ARCH) -LOPTS_C := -SUBSYSTEM:CONSOLE -LOPTS_W := -SUBSYSTEM:WINDOWS + LOPTS := -MACHINE:$(ARCH) + LOPTS_C := -SUBSYSTEM:CONSOLE + LOPTS_W := -SUBSYSTEM:WINDOWS else -LOPTS := -MACHINE:$(ARCH) -LOPTS_C := -SUBSYSTEM:CONSOLE,5.01 -LOPTS_W := -SUBSYSTEM:WINDOWS,5.01 + LOPTS := -MACHINE:$(ARCH) + LOPTS_C := -SUBSYSTEM:CONSOLE,5.01 + LOPTS_W := -SUBSYSTEM:WINDOWS,5.01 endif OPTS += $(SYSINC) ifeq ($(OPTIM), y) @@ -159,9 +164,6 @@ CXXFLAGS := $(OPTS) $(CXXOPTS) $(COPTS) $(COPTIM) $(DOPTS) $(AFLAGS) -I. LOBJ := cwalk.obj xml2_encoding.obj \ convert.obj create.obj io.obj manage.obj \ struct_rw.obj util.obj -LOBJ_S := cwalk.sbj xml2_encoding.sbj \ - convert.sbj create.sbj io.sbj manage.sbj \ - struct_rw.sbj util.sbj # Build module rules. @@ -177,9 +179,6 @@ else %.obj: %.c @$(CC) $(CFLAGS) -Fo$@ -c $< -%.sbj: %.c - @$(CC) $(CFLAGS) -DSTATIC -Fo$@ -c $< - %.obj: %.cpp @$(CPP) $(CXXFLAGS) -Fo$@ -c $< @@ -191,7 +190,11 @@ else endif -all: $(LIBS).dll $(LIBS)_s.lib $(PROGS).exe $(PROGS)_s.exe +ifeq ($(STATIC), y) +all: $(LIBS)_s.lib $(PROGS)_s.exe +else +all: $(LIBS).dll $(PROGS).exe +endif $(LIBS).res: win32\$(LIBS).rc @echo Processing $< @@ -202,17 +205,17 @@ $(LIBS).dll: $(LOBJ) $(LIBS).res @$(LINK) /DLL $(LFLAGS) $(LOPTS_W) -OUT:$(LIBS).dll \ $(LOBJ) $(LIBS).res $(SYSLIBS) -$(LIBS)_s.lib: $(LOBJ_S) +$(LIBS)_s.lib: $(LOBJ) @echo Creating $@ .. - @$(AR) /OUT:$@ $(LOBJ_S) + @$(AR) /OUT:$@ $(LOBJ) $(PROGS).exe: $(PROGS).obj @echo Linking $@ .. @$(LINK) $(LFLAGS) /OUT:$@ $(PROGS).obj $(SYSLIBS) minivhd.lib -$(PROGS)_s.exe: $(PROGS).sbj +$(PROGS)_s.exe: $(PROGS).obj @echo Linking $@ .. - @$(LINK) $(LFLAGS) /OUT:$@ $(PROGS).sbj $(SYSLIBS) minivhd_s.lib + @$(LINK) $(LFLAGS) /OUT:$@ $(PROGS).obj $(SYSLIBS) minivhd_s.lib install: all @@ -233,7 +236,6 @@ endif clean: @echo Cleaning objects.. @-del *.obj 2>NUL - @-del *.sbj 2>NUL @-del *.res 2>NUL clobber: clean diff --git a/src/xml2_encoding.c b/src/xml2_encoding.c index 77239da..896be6a 100644 --- a/src/xml2_encoding.c +++ b/src/xml2_encoding.c @@ -25,7 +25,7 @@ #include #include #include -#define BUILDING_DLL +#define BUILDING_LIBRARY #include "minivhd.h" #include "internal.h" #include "xml2_encoding.h"