Unix to Windows Porting Dictionary for HPC

Links

Function List

stat


Unix

header file: sys/types.h, sys/stat.h

int stat (const char *path, struct stat *sb);
int stat64(const char *path, struct stat64 *buf);
int wcs_stat (const wchar_t *path, struct stat *sb);
int lstat (const char *path, struct stat *sb);
int lstat64(const char *, struct stat64 *);
int wcs_lstat (const wchar_t *path, struct stat *sb);
int fstat (int fd, struct stat *sb);
int fstat64(int fildes, struct stat64 *buf);

Windows

header files: sys/types.h, sys/stat.h

int _stat(const char *path, struct _stat *buffer);
int _stat32(const char *path, struct __stat32 *buffer);
int _stat64(const char *path, struct __stat64 *buffer);
int _stati64(const char *path, struct _stati64 *buffer);
int _stat32i64(str const char *path, struct _stat32i64 *buffer);
int _stat64i32(str const char *path, struct _stat64i32 *buffer);
int _wstat(const wchar_t *path, struct _stat *buffer);
int _wstat32(const wchar_t *path, struct __stat32 *buffer);
int _wstat64(const wchar_t *path, struct __stat64 *buffer);
int _wstati64(const wchar_t *path, struct _stati64 *buffer);
int _wstat32i64(const wchar_t *path, struct _stat32i64 *buffer);
int _wstat64i32(const wchar_t *path, struct _stat64i32 *buffer);

Purpose

Get file status information.

Discussion

There are a collection of releated API's to get information about a file. On Unix systems there are several API's that obtain the file information in different ways. Since, historically, the information returned used variables (members of structure) for size 32 bit this limited reporting size information to 2G or less. The *64() API's were created to allow larger files sizes to be reported accurately with 64 bit variables (up to 4T). The original API's used only ASCII based pathnames. The wcs_* versions allow for wide character pathnames.

On Windows there is no direct equivalent to the Unix API's but there are API's to obtain the same information. To help port applications, helper functions have been written by Microsoft with function names that are very similar to the Unix API names. It should be noted that while these helper API's are useful they do add additional resource use and time overhead.

The default is to prefix the Unix API name with an underscore (e.g. stat() to _stat() ) to get a information on a file in the same format (structure) as on the Unix system. The Unix wcs_*() functions are named _w*() functions with Windows. Windows uses the same header files as the Unix system.

The Windows API's also include *32() to explicitly have size information returned in 32 bit variables. Windows has additional API's that result in the returned information for time being 32 or 64 bit while allowing the file size information to be in 64 or 32 bit in the same structure.

Windows does not have API's to match the Unix fstat(), fstat64(), lstat() and lstat64() API's. All file information on WIndows must be obtained with a pathname. This will mean adding to or restructuring your code so the original pathname can be referenced where the Unix source code previously called fstat() or lstat(). This requirement is a reflextion of the underlying API's used to create the helper functions; it is not that the matching helper functions were ignored or forgotten.

blog comments powered by Disqus