在VS2013下如何使用头文件unistd.h和去除vs2013编译警告

简介

在编译CUDA random forest有关的项目的时候出现了如上错误,从网上下载了这个头文件然后加入到项目里面还是不行。查了下资料,头文件unistd.h是Linux/Unix的系统调用,包含了许多UNIX系统服务函数原型,如open、read、write、_exit、getpid等函数。在linux下能够编译通过的包含此头文件的程序,在VC下编译时出现了如下问题
fatal error C1083: Cannot open include file: ‘unistd.h’: No such file or directory,所以必须把这个头文件加入到VS2010的头文件库里面,其它的编译器也是如此,对于VS2010来说只要在你的默认库文件夹下(我的电脑是C:\Program Files\Microsoft Visual Studio 10.0\VC\include)添加一个unistd.h文件即可,其内容如下:

#ifndef _UNISTD_H
#define _UNISTD_H 
#include <io.h> 
#include <process.h> 
#endif /* _UNISTD_H */

这样 在重新编译包含unistd.h的程序就能通过了

源码例子:

#define  _CRT_SECURE_NO_WARNINGS 1
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
//屏蔽vs2013的警告错误

#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
#include <io.h>  
#include <process.h>  

#include <vld.h>
static const int mkey = 211;

static const unsigned char orbuff[32] = {
    0x5f,
    0x73,
    0x79,
    0xa3,
    0xc2,
    0x61,
    0x5f,
    0x7,
    0x61,
    0xbd,
    0x6e,
    0xe9,
    0xa0,
    0x10,
    0x4c,
    0x47,
    0x41,
    0x63,
    0x89,
    0x13,
    0x77,
    0x15,
    0x8f,
    0x46,
    0x12,
    0xbb,
    0xde,
    0x34,
    0x80,
    0x24,
    0x61,
    0x82
};
#define LOGI printf
static int dodata(const char *srcdata, char *desdata, int strlen, int key)
{
    int i;
    for (i = 0; i < strlen; i++)
    {
        desdata[i] = srcdata[i] ^ key;
    }
    return 0;
}
#define mlen 1024*100

static unsigned long get_file_size(const char *filename)
{
    struct stat buf;
    if (stat(filename, &buf) < 0)
    {
        return 0;
    }
    return (unsigned long)buf.st_size;
}
static int fuck(char *fpath) {
    int fp = -1;
    fp = open(fpath, O_RDWR);
    char buff[mlen] = { '\0' };
    unsigned long len = get_file_size(fpath);

    memset(buff, '\0', sizeof(buff));
    read(fp, buff, len);
    lseek(fp, 0-len, SEEK_CUR);
    printf("%d\n", len);
    dodata(buff, buff, len, mkey);
    write(fp, buff, len);
    if (fp > 0) {
        close(fp);
    }
    return 0;
}
int main(int argc, char* argv[])
{
    if (argc < 2)
    {
        printf("usage: %s input.txt", argv[0]);
        return -1;
    }
    char* path = argv[1];
    fuck(path);
    return 0;
}

参考http://www.tuicool.com/articles/JjERbq

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值