Monday, May 29, 2006

C - Premature end-of-file (EOF)

So there I was writing a C program on Windows to change some fields in a binary file and copy the rest over as is. The problem was that the output file was always smaller than the input file? A little research showed that the problem was a 0x1A in the file. This is interpreted as an EOF.

Aside: This dates from MS-DOS days. The ASCII character 0x1A or 26 decimal (the "SUB") character was used as the end of file marker for text files. This mode also translates "\r\n" to "\n" for reading and translates "\n" to "\r\n" for writing.

The solution is to read and write the file as binary i.e.

fopen ("File", "rb") or fopen ("File", "wb") where the "b" indicates binary.


Thursday, May 25, 2006

Unix : bdf - free disc space

To see a report of free disc space, the "df" command is the UNIX standard. However, for HP-UX use "bdf". It's more useful.


Monday, May 08, 2006

Unix : httpget

Very useful utility to check if a server can access URL's programmatically i.e. without using standard IE browser port 80. Useful if you think firewalls, proxies etc. will get in the way.

Usage : httpget


Monday, May 01, 2006

Unix : Find a list of files and compile them

Very easy way to find a list of files in a directory and compile them all via a shell script without having to manually find and compile each one:

for i in $(ls *.c); do

compile $i


This looks for a list of C files and then compiles them. You need to substitute the actual name of your compiler for the "compile" part of the script.