You may not know that Windows has a Unix subsystem.

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.