Wrapping C++ objects in C

Introduction Using C functions from C++ is very easy but going the other way isn’t. However, it can be done with a little ingenuity. Really, this isn’t as crazy as it sounds. I’ll use a simple adder for the object. It takes an integer as a starting value and has two functions for adding and […]

JNI is (Not) Your Friend

Introduction So far we’ve scratched the surface of using JNI when we looked at wrapping a C library and Calling Java from C. Now we’re going to look into some more complex uses. Java Class Since we’re working with JNI, we’ll need a Java class to use what we’re going to expose from C. DemoFuncs.java […]

Calling Java From C

Introduction Obviously, JNI lets you call Java functions and use Java classes in C. Typical a Java app is the one calling into C. Now Let’s say you don’t have a Java app that kicks off the process but you want your C app to still use some Java code. Okay, I know what you’re […]

Wrapping a C library in Java

Introduction It can’t be argued that Java is popular and successful. It is consistently the number one language on TIOBE’s popularity list, above C which comes in as number two. This ranking is based on popularity and doesn’t mean Java is more used than C but that doesn’t change the fact that there is a […]

Recursive Create Directory in C

C has a very large gap when it comes to working with files and directories. It is C, so all the building blocks are there. Thankfully, it’s pretty easy to put together something useful. In a project I’ve been working on I needed to create a directory. This is pretty trivial but I needed to […]

Poddown a simple podcast downloader

I have been listing to podcasts for a long time and many years ago I wrote a podcast downloader. Back then I had a media center and I wanted my favorite podcasts to automatically download each night. At that time there wasn’t anything that really did that. Well, there was but they were full management […]

String Splitting in C

For a project I’ve been working on I needed to split a string into it’s component parts. There is `strtok` which I find useless for pretty much any task. It is not thread-safe, nor is it re-entrant, which makes it impossible to parse two strings (in a loop) at once. Yet another issue with `strtok` […]

Constant Time String Comparison in C

Comparing strings in C is typically handled with `strncmp`. This is fine in most cases but if you need to compare sensitive information, such as a message digest, it’s a really bad choice. `strncmp` is susceptible to timing attacks because it will stop comparing once the first difference is encountered. The overall design of constant […]

Efficient C String Builder

One task that always annoys me when I work with C is building strings. `snprintf` is all well and good if I know exactly the format I want. It falls down with anything that needs to be build iteratively and dynamically. Other languages that have built in strings will automatically create a new string when […]

Interop Objective-C Objects In C Using ARC

Introduction Using C functions from Objective-C is very easy but going the other way isn’t so easy. Especially with ARC which can destroy the object out from under you because C code is outside of ARC. With ARC Objective-C objects are no longer allowed in C structs for this very reason. Here is a situation […]