Using .in Files and Macros for API Management

Overview When working with large graphics APIs like OpenGL ES and EGL, especially in complex systems like Android, developers face the challenge of managing hundreds of function declarations, pointers, and related metadata. A common and powerful solution is to use macro-based code generation with .in files. This approach, while adding some complexity, brings significant benefits in maintainability, consistency, and flexibility. This post explains what .in files are, how they’re used with macros, and why this pattern is so valuable in graphics stacks like OpenGL ES and EGL. We’ll also look at concrete examples and discuss the trade-offs involved. ...

June 25, 2025 · 3 min

Generating Package Patch for Buildroot

Generating a Patch Using diff 1. Extract the Original Source Ensure you have a pristine copy of the original source for comparison. You can extract it from the tarball in the dl directory: tar -xf dl/<package>-<version>.tar.gz -C /tmp/ This will create a directory like /tmp/<package>-<version>/. Using buildroot’s mechanism Clean the build directory and apply current patches of buildroot make <pkg>-dirclean # Remove <pkg> build directory make <pkg>-extract # Extract <pkg> sources make <pkg>-patch # Apply patches to <pkg> (Optional) cp -r output/build/<package> /tmp/ 2. Generate the Patch Use the diff command to create a unified diff between the original and modified sources: ...

May 20, 2025 · 2 min

POCO Libraries

The POCO C++ Libraries are powerful cross-platform C++ libraries for building network- and internet-based applications that run on desktop, server, mobile, IoT, and embedded systems. Cross-Compiling With a proper CMake toolchain file (specified via the CMAKE_TOOLCHAIN_FILE CMake variable), the POCO C++ Libraries can be cross-compiled for embedded Linux systems: mkdir cmake-build cd cmake-build cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/mytoolchain.cmake -DCMAKE_INSTALL_PREFIX=/path/to/target cmake -DENAMLE-SAMPLE=YES cmake --build . --target install # make all install OR mkdir cmake-build-ipc2 && cd cmake-build-ipc2 && cmake .. -DCMAKE_TOOLCHAIN_FILE= /opt/IPCam2_Host/host/share/buildroot/toolchainfile.cmake -DCMAKE_INSTALL_PREFIX=target -DENABLE_SAMPLES=ON -DBUILD_SHARED_LIBS=ON Installing The POCO C++ Libraries headers and libraries can be optionally be installed by building the install target. ...

April 29, 2025 · 1 min

GitFlow

Reference GirFlow Explained: https://youtu.be/Aa8RpP0sf-Y

February 3, 2025 · 1 min

SHA-256 (Secure Hash Algorithm 256-bit)

SHA-256 is a cryptographic hash function that produces a fixed-size 256-bit (32-byte) hash. It is deterministic, collision-resistant, and designed for security-critical applications. How SHA-256 Works Preprocessing: Pad the input to a multiple of 512 bits. Append a 1, then add k zeros, and finally append the original message length (64 bits). Initialize Hash Values: Use constants derived from the fractional parts of square roots of the first 8 primes (eight 32-bit words). Example: h0 = 0x6a09e667, h1 = 0xbb67ae85, .... Process Blocks: Split the padded message into 512-bit blocks. For each block: Expand the block into 64 words using a message schedule. Perform 64 rounds of compression using bitwise operations (e.g., XOR, AND, modular addition). Compression Function A compression function is applied to each block, creating a new hash value. This function involves mixing the bits of the current hash value and the message block. Iteration Repeat the compression function for each block, using the output of each iteration as input for the next. Final Hash: Combine the intermediate hash values to produce the final 256-bit digest. Example: SHA-256 for String “Hello” Input: “Hello” → ASCII 48656C6C6F. Padding: Length = 40 bits (5 bytes). Pad with 1, 407 zeros, and 0000000000000028 (hex for 40 bits). Hash Computation: After processing, the final hash is: 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969. Use Cases SHA-256 Cryptographic security in: Digital signatures (SSL/TLS certificates). Password storage (hashed+salted). Blockchain (Bitcoin transactions). File integrity verification (e.g., software downloads). Guarantees: Pre-image resistance, collision resistance.

January 29, 2025 · 2 min

C,C++ Code Style Guide

This guide provides step-by-step instructions for setting up consistent formatting, rules checking, and documentation for C/C++ code using clang-format, clang-tidy, and Doxygen in VS Code. Follow this guide to ensure uniformity across the team. 1. Prerequisites Before starting, ensure you have the following tools installed: VS Code (latest version) Extensions for VS Code: C/C++ (Microsoft) Doxygen Documentation Generator Command-line tools: clang-format clang-tidy doxygen Python (for pre-commit hooks) 2. Auto-Formatting Using clang-format clang-format is used for consistent code formatting. ...

November 28, 2024 · 3 min

Git Undo Mistakes

Undoing Mistakes in Git 1. Discarding Uncommitted Changes a) git restore <file> Discards uncommitted modifications in the specified file. Irreversible: once applied, changes cannot be recovered. b) git restore -p <file> The -p (patch) option lets you interactively choose hunks to discard. Useful for selectively reverting parts of a file. c) git restore . Discards all uncommitted changes in the working directory since the last commit. 2. Amending the Last Commit git commit --amend -m "New Commit Message" Updates the message (and/or contents) of the last commit. Do not amend commits that have already been shared with others. 3. Reverting a Specific Commit git revert <SHA> Creates a new commit that inverts the changes of the specified commit. Safe way to “undo” a change without rewriting history. Obtain the SHA from git log, e.g. 74e3b2b. 4. Resetting to an Earlier Commit a) git reset --hard <SHA> Moves HEAD and current branch to the given commit, discarding all subsequent commits and uncommitted changes. Warning: unpushed commits are permanently lost. b) git reset --mixed <SHA> (default) Similar to --hard, but preserves changes from discarded commits as unstaged modifications. 5. Restoring a File from a Past Commit git restore --source <SHA> -- <file> Replaces the working copy of <file> with its state at the given commit. Only affects the specified file. 6. Using the Reflog to Recover Lost Commits git reflog Records updates to HEAD (including resets) for a limited time. Find the SHA of a lost state and then create a branch or reset to it. Restoring After a Hard Reset Locate the prior HEAD reference in the reflog. Use git branch <new-branch> <reflog-SHA> to recover. Recovering a Deleted Branch Identify the branch tip SHA via git reflog. Recreate the branch: git branch <branch-name> <SHA>. 7. Moving Commits to Another Branch a) To a New Branch git branch <new-branch> git reset --hard HEAD~1 Creates <new-branch> at the current HEAD, then removes the last commit from the original branch. b) To an Existing Branch git checkout <target-branch> git cherry-pick <SHA> git checkout <original-branch> git reset --hard HEAD~1 Cherry-picks the commit into <target-branch>, then removes it from the source branch. 8. Interactive Rebase for History Rewriting Use with caution: Interactive rebase rewrites commit history, which can break shared branches. ...

March 24, 2021 · 3 min