Visual C ++ 2015 express: _stat does not work on Windows XP

The following example is executed for _stat from MSDN , compiled using Visual C ++ 2015 Express using v140_xp , since the Platform Toolset (target Win32) works fine on Windows 7, but not on Windows XP on several machines we tested.

 // crt_stat.c // This program uses the _stat function to // report information about the file named crt_stat.c. #include <time.h> #include <sys/types.h> #include <sys/stat.h> #include <stdio.h> #include <errno.h> int main() { struct _stat buf; int result; char timebuf[26]; char* filename = "crt_stat.c"; // Absolute paths like "D:\\crt_stat.c" produce the same behaviour. 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: /* Should 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 ); } } 

Windows 7 Output:

 File size : 6 Drive : D: Time modified : Tue Sep 8 10:06:57 2015 

Windows XP Output:

 Problem getting information: Invalid argument Invalid parameter to _stat. 

And yes crt_stat.c is in the executable directory, which is also CWD.

Is this a mistake or am I missing something?

+6
source share
2 answers

Error resolved on Visual C ++ Redistributable for Visual Studio 2015 Update 1

I solved the problem by installing this update form here: https://www.microsoft.com/en-us/download/details.aspx?id=49984

0
source

All Articles