Author: Zhu Jincan
Source: http://www.cnblogs.com/clever101
Please refer to the following sectionCode:
# Include < Time. h >
# Include < Sys / Types. h >
# Include < Sys / Stat. h >
# Include < Stdio. h >
# Include < Errno. h >
Int Main ( Void )
{
Struct _ Stat Buf;
Int Result;
Char Timebuf [ 26 ];
Char * Filename = " F: \ mytest \ SRC \ testunix \ stdafx. h " ;
Errno_t err;
//Get data associated with "crt_stat.c ":
Result=_ Stat (filename,&Buf );
// Check if statistics are valid:
If (Result ! = 0 )
{
Perror ( " Problem getting information " );
Switch (Errno)
{
Case Enoent:
Printf ( " File % s not found. \ n " , Filename );
Break ;
Case Einval:
Printf ( " Invalid parameter to _ Stat. \ n " );
Break ;
Default :
/* Shoshould never be reached. */
Printf ( " Unexpected error in _ Stat. \ n " );
}
}
Else
{
// Output some of the statistics:
Printf ( " File Size: % LD \ n " , Buf. st_size );
Printf ( " Drive: % C: \ n " , Buf. st_dev + ' A ' );
Err = Ctime_s (timebuf, 26 , & Buf. st_mtime );
If (ERR)
{
Printf ( " Invalid arguments to ctime_s. " );
Return 1 ;
}
Printf ( " Time modified: % s " , Timebuf );
}
Getchar ();
Return 0;
}
A friend familiar with Unix or Linux platform development may think that it was developed on Unix or Linux platform. In fact, it is an example of msdn library for Visual Studio 2005. It can be compiled successfully on vs C ++ 2005 (Multi-Byte Character Set compilation ).
At first, I didn't quite understand why Windows has UNIX header files. I recently read "Windows operating system principles" to fully understand it. Windows 2000/XP has three environment subsystems: POSIX/Unix, OS/2, and Win32 (OS/2 can only be used in x86 systems ). With the POSIX/Unix subsystem, there is a unix sdk, so it is not surprising that the header file above appears. In fact, Microsoft's development and Unix systems have some origins: Microsoft has launched UNIX operating systems in its history; many core developers of Windows systems are senior UNIX operating system design and development personnel.
So what is the use of this POSIX/Unix subsystem? POSIX represents the international standard set of UNIX operating systems, which encourages manufacturers to implement Compatible UNIX-style interfaces so that programmers can easily integrate their applicationsProgramMove from one system to another. Because of this feature, many underlying software (for cross-platform implementation) and cross-platform libraries like to callUNIX SDK. I have seen it in the famous open-source Image Library gdal.UNIX SDK. However, Windows 2000/XP only implements the posix.1 standard (ISO/IEC 9945-11990 or ieee posix 1003.1-1990 ). The POSIX consistency document is located in the "Help directory of Platform SDK.
References:
1.Msdn libraries for Visual Studio 2005, Microsoft Corporation
2.Windows operating system principles,Yujinyuan Shi Meilin Chen xiangqun Xiang Yong Wang Lei Ma hongbing Zheng jiegenMa hongbingEdited