Skip to content

Resolve asprintf undeclared error and add cross-platform support #46

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

moonwaystar
Copy link

This PR includes two changes:

  1. Cross-platform support in output_file.cpp and backed_block.cpp

    • Added #ifndef _WIN32 around <unistd.h> and defined PAGESIZE (4096 for Windows, sysconf(_SC_PAGESIZE) elsewhere) in output_file.cpp for non-POSIX compatibility.
    • Updated aligned_offset logic to use the PAGESIZE macro for consistent alignment.
    • Reordered calloc args in backed_block.cpp from sizeof(struct backed_block_list), 1 to 1, sizeof(struct backed_block_list) for clarity.
  2. Portability fixes in simg2simg.cpp, sparse.cpp, and append2simg.cpp

    • Standardized calloc args (e.g., sizeof(struct sparse_file*), files to files, sizeof(struct sparse_file*)) across all three files.
    • Replaced asprintf with a custom custom_asprintf using snprintf in append2simg.cpp to resolve "append2simg.cpp:67:9: error: 'asprintf' was not declared in this scope". The custom_asprintf implementation fixes this compilation failure.

Fixes issue #44 with these commits.

Testing:

  • Tested locally and via GitHub Actions on ubuntu-latest and windows-latest. Builds pass without issues.
  • Build log: GitHub Actions Runner

Closes Issue #44.

- Include unistd.h only for non-Windows systems
- Define PAGESIZE as 4096 on Windows, sysconf(_SC_PAGESIZE) elsewhere
- Update aligned_offset calculation to use PAGESIZE macro

Fixes the error -
output_file.cpp:660:39: error: '_SC_PAGESIZE' was not declared in this scope
  660 |   aligned_offset = offset & ~(sysconf(_SC_PAGESIZE) - 1);
      |                                       ^~~~~~~~~~~~
output_file.cpp:660:31: error: 'sysconf' was not declared in this scope; did you mean 'swscanf'?
…nd append2simg

- Resolve 'asprintf was not declared in this scope' error in append2simg.cpp:67:9
  by replacing asprintf with custom_asprintf using snprintf
- Add custom_asprintf implementation to address missing asprintf declaration
- Reorder calloc args to (count, size) in simg2simg.cpp, sparse.cpp, and append2simg.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile error on both Windows and Arch
1 participant