rewrite: a rust-powered, in-place file rewrite utility

Let’s say you’ve got a terminal open and you want to sort the contents of a file before you email it to a friend. The file can contain anything and it could be of any length, it doesn’t matter. What do you do?

The obvious answer is to use sort. Sorting the file is as easy as sort myfile – except it doesn’t actually sort the file, it sorts the *contents* of the file and dumps them to the command line (via stdout). So how do you sort the file “in-place,” so-to-speak? Again, the obvious answer would be sort myfile > myfile,1 redirecting the output of the sort command back to the file you want to ultimately send sorted.

Continue reading


  1. Don’t do this! 

WaitForMultipleObjects and WIN32 events for Linux/OS X/*nix and Read-Write Locks for Windows

As every programmer worth his salt knows, synchronization primitives form the very building blocks of multithreaded programming. Without them, the world as we know it would cease to exist and chaos would reign free and unchecked.

All joking aside, synchronization objects such as mutexes and semaphores are essential to safe multithreading and are found on just about any platform under the sun. Mutexes and semaphores alike have one purpose: to keep different threads from messing around with bits and bytes at the same time another thread is, keeping your code free of segfaults and memory access violations alike. But that’s about where the similarities between the synchronization primitives on different platforms end.

POSIX-compliant operating systems with pthreads offer additional really neat synchronization primitives not found on Windows, such as condition variables and read-write locks (the latter is now available on Windows Vista+). And Windows programmers have at their disposal automatic and manual reset events, which make designing certain types of multithreaded software incredibly easy, abstracting away much of the hard-core synchronization logic that lies beneath the hood.

Continue reading