linux lstat 移植
使用windows下的 _stat 代替linux的 lstat
// 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( void ) { struct _stat buf; int result; char timebuf[26]; char* filename = "crt_stat.c"; 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. ", filename); break; case EINVAL: printf("Invalid parameter to _stat. "); break; default: /* Should never be reached. */ printf("Unexpected error in _stat. "); } } else { // Output some of the statistics: printf( "File size : %ld ", buf.st_size ); printf( "Drive : %c: ", buf.st_dev + "A" ); err = ctime_s(timebuf, 26, &buf.st_mtime); if (err) { printf("Invalid arguments to ctime_s."); exit(1); } printf( "Time modified : %s", timebuf ); } }
参考:
https://msdn.microsoft.com/en-us/library/14h5k7ff.aspx
https://stackoverflow.com/questions/12085761/what-is-lstat-alternative-in-windows
http://blog.csdn.net/mociml/article/details/4710007
http://blog.csdn.net/edonlii/article/details/21093111
http://blog.csdn.net/qq_21792169/article/details/50454475
另外github上有对微软库函数的扩展,增加了一些linux下函数的实现
https://github.com/JFLarvoire/SysToolsLib
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了