Fri, 11 Jan 2008

Microsoft and the POSIX Standard.

POSIX defines a set of functions for retrieving information, such as file size, creation date, last modification date, ownership etc about files on disk. Two commonly used functions in this set are defined as follows:

int stat (const char *path, struct stat *buf) ; int fstat (int filedes, struct stat *buf) ;

The first operates on the filename, and the second operates on a pre-existing file descriptor. Both functions interrogate the file system and fill in a bunch of fields of a struct supplied by the caller.

Microsoft also provides these functions in its C run time library and even documents them here and here. However, stat, the function that is probably more commonly used than fstat, does not always work as expected. In particular, the following scenario:

Create a new file using the open function.

function. Write N bytes to the file descriptor returned by open .

. Call stat on the file using the file name used during file creation.

on the file using the file name used during file creation. Call fstat on the file descriptor returned by open.

On any sane system, the file length field of the struct filled in by stat and fstat calls in the above scenario should be the same. On windows however, they are not, fstat returns the correct value N, while stat returns zero.

With the help from a kind volunteer on the libsndfile-devel mailing list this broken-ness was confirmed on Win2k, WinXP and Vista.

Microsoft; bringing new and improved versions of the DeathStation 9000 to the desk and laptop bag of every programmer. From that wiki page:

DeathStation 9000 (often abbreviated DS9K) is a fictional computer architecture often used as part of a discussion about the portability of computer code (often C code). It is imagined to be as obstructive and unhelpful as possible, whilst still conforming to any relevant standards, deliberately acting unexpectedly whenever possible.

Posted at: 23:21 | Category: Windiots | Permalink