• Beach Tweets

  • Archives

  • RSS PEER 1 Blog

    • An error has occurred; the feed is probably down. Try again later.

A Binary Salute to a Digital Visionary

October 2011 hasn’t been kind to the fathers of modern computing.

The death of Apple front man Steve Jobs spawned a wave of iWakes across the world, but the loss of Dennis Ritchie – the father of the C programming language and unix, was just as sad a day for techies everywhere. Perhaps even worse – as many people didn’t even notice.

Afterall, OSX could not exist without the work that Ritchie did 30 years ago.

To pay respect to the digital pioneer, our very own Sean Davis wrote a C program to send a cheers to the big bit bucket in the sky.

You can find the original here.

—–

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/uio.h>

#define URANDOM "/dev/urandom"
#define OUT "/dev/null"
#define A_FORTY 5 /* 40 bits */

int
main(argc,argv)
	int argc;
	char **argv;
{
	char *buf;
	int fd,ret;
	size_t rwret;

	buf = (char *)malloc(A_FORTY);

	if (buf == NULL) {
		fprintf(stderr,"Can't hold a forty. (%s)\n",
			strerror(errno));
		exit(1);
	}

	fd = open(URANDOM,O_RDONLY);

	if (fd == -1) {
		fprintf(stderr,"Failed to open %s: %s\n",
			URANDOM,strerror(errno));
		free(buf);
		exit(1);
	}

	rwret = read(fd,buf,A_FORTY);

	if (rwret == -1) {
		fprintf(stderr,"Failed to grab a forty: %s\n",
			strerror(errno));
		free(buf);
		exit(1);
	}

	if (rwret == 5) {
		printf("Got a forty.\n");
	} else if (rwret == -1) {
		fprintf(stderr,"Couldn't get a forty. (%s)\n",
			strerror(errno));
		free(buf);
		exit(1);
	} else {
		fprintf(stderr,"This forty is light, only %d bits!\n",
			(int)rwret * 8);
		free(buf);
		exit(1);
	}

	ret = close(fd);

	if (ret == -1) {
		fprintf(stderr,"Failed to close the beer fridge. (%s)\n",
			strerror(errno));
		free(buf);
		exit(1);
	}

	fd = open(OUT,O_WRONLY);

	if (fd == -1) {
		fprintf(stderr,"Can't find the drain. (%s)\n",
			strerror(errno));
		free(buf);
		exit(1);
	}

	rwret = write(fd,buf,A_FORTY);

	if (rwret == 5) {
		printf("Goodbye, Dennis. I wouldn't be what I am without you.\n");
		printf("Poured out forty bits for our dead homie.\n");
	} else {
		fprintf(stderr,"The drain must be clogged, only poured out %d bits.\n",
			(int)rwret * 8);
		free(buf);
		ret = close(fd);
		if (ret == -1) {
			fprintf(stderr,"Can't plug the drain (%s)\n",
				strerror(errno));
			exit(1);
		}
	}

	free(buf);
	exit(0);
}

Goodbye Dennis, and thanks for all the magic!

2 Responses

  1. I’ll bet that Dennis Ritchie would never have taken down a million teaching blogs. That’ll show ’em.

  2. Be health care happy with measurments

Leave a comment