pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

是否有適用于 Windows (Visual C) 的 unistd.h 的替代品

Is there a replacement for unistd.h for Windows (Visual C)?(是否有適用于 Windows (Visual C) 的 unistd.h 的替代品?)
本文介紹了是否有適用于 Windows (Visual C) 的 unistd.h 的替代品?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在將一個為 Unix 編寫的相對簡單的控制臺程序移植到 Windows 平臺 (VisualC++ 8.0).所有源文件都包含不存在的unistd.h".刪除它后,我收到了關于缺少 'srandom'、'random' 和 'getopt' 原型的抱怨.我知道我可以替換隨機函數,而且我很確定我可以找到/修改 getopt 實現.

I'm porting a relatively simple console program written for Unix to the Windows platform (Visual C++ 8.0). All the source files include "unistd.h", which doesn't exist. Removing it, I get complaints about misssing prototypes for 'srandom', 'random', and 'getopt'. I know I can replace the random functions, and I'm pretty sure I can find/hack-up a getopt implementation.

但我相信其他人也遇到了同樣的挑戰.我的問題是:Windows 是否有unistd.h"的端口?至少有一個包含那些具有本機 Windows 實現的函數 - 我不需要管道或分叉.

But I'm sure others have run into the same challenge. My question is: is there a port of "unistd.h" to Windows? At least one containg those functions which do have a native Windows implementation - I don't need pipes or forking.

編輯:

我知道我可以創建我自己的unistd.h",其中包含我需要的東西的替代品 - 特別是在這種情況下,因為它是一個有限的集合.但由于這似乎是一個常見問題,我想知道是否有人已經為更大的功能子集完成了這項工作.

I know I can create my very own "unistd.h" which contains replacements for the things I need - especially in this case, since it is a limited set. But since it seems like a common problem, I was wondering if someone had done the work already for a bigger subset of the functionality.

在工作中無法切換到不同的編譯器或環境 - 我一直在使用 Visual Studio.

Switching to a different compiler or environment isn't possible at work - I'm stuck with Visual Studio.

推薦答案

網上找不到版本,就從這里開始吧.
大多數 Windows 端口可能只需要完整 Unix 文件的一個子集.
這是一個起點.請根據需要添加定義.

Since we can't find a version on the Internet, let's start one here.
Most ports to Windows probably only need a subset of the complete Unix file.
Here's a starting point. Please add definitions as needed.

#ifndef _UNISTD_H
#define _UNISTD_H    1

/* This is intended as a drop-in replacement for unistd.h on Windows.
 * Please add functionality as neeeded.
 * https://stackoverflow.com/a/826027/1202830
 */

#include <stdlib.h>
#include <io.h>
#include <getopt.h> /* getopt at: https://gist.github.com/ashelly/7776712 */
#include <process.h> /* for getpid() and the exec..() family */
#include <direct.h> /* for _getcwd() and _chdir() */

#define srandom srand
#define random rand

/* Values for the second argument to access.
   These may be OR'd together.  */
#define R_OK    4       /* Test for read permission.  */
#define W_OK    2       /* Test for write permission.  */
//#define   X_OK    1       /* execute permission - unsupported in windows*/
#define F_OK    0       /* Test for existence.  */

#define access _access
#define dup2 _dup2
#define execve _execve
#define ftruncate _chsize
#define unlink _unlink
#define fileno _fileno
#define getcwd _getcwd
#define chdir _chdir
#define isatty _isatty
#define lseek _lseek
/* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */

#ifdef _WIN64
#define ssize_t __int64
#else
#define ssize_t long
#endif

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
/* should be in some equivalent to <sys/types.h> */
typedef __int8            int8_t;
typedef __int16           int16_t; 
typedef __int32           int32_t;
typedef __int64           int64_t;
typedef unsigned __int8   uint8_t;
typedef unsigned __int16  uint16_t;
typedef unsigned __int32  uint32_t;
typedef unsigned __int64  uint64_t;

#endif /* unistd.h  */

這篇關于是否有適用于 Windows (Visual C) 的 unistd.h 的替代品?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

boost_1_60_0 .zip installation in windows(Windows 中的 boost_1_60_0 .zip 安裝)
How do I get console output in C++ with a Windows program?(如何使用 Windows 程序在 C++ 中獲得控制臺輸出?)
How do I calculate the week number given a date?(如何計算給定日期的周數?)
OpenCV with Network Cameras(帶有網絡攝像機的 OpenCV)
Export all symbols when creating a DLL(創建 DLL 時導出所有符號)
Getting started with OpenCV 2.4 and MinGW on Windows 7(Windows 7 上的 OpenCV 2.4 和 MinGW 入門)
主站蜘蛛池模板: 能耗监测系统-节能监测系统-能源管理系统-三水智能化 | 北京乾茂兴业科技发展有限公司| 上海小程序开发-小程序制作-上海小程序定制开发公司-微信商城小程序-上海咏熠 | 济南律师,济南法律咨询,山东法律顾问-山东沃德律师事务所 | 全自动翻转振荡器-浸出式水平振荡器厂家-土壤干燥箱价格-常州普天仪器 | 紫外荧光硫分析仪-硫含量分析仪-红外光度测定仪-泰州美旭仪器 | 铝合金线槽_铝型材加工_空调挡水板厂家-江阴炜福金属制品有限公司 | MOOG伺服阀维修,ATOS比例流量阀维修,伺服阀维修-上海纽顿液压设备有限公司 | 篷房|仓储篷房|铝合金篷房|体育篷房|篷房厂家-华烨建筑科技官网 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 | 钛合金标准件-钛合金螺丝-钛管件-钛合金棒-钛合金板-钛合金锻件-宝鸡远航钛业有限公司 | 余姚生活网_余姚论坛_余姚市综合门户网站| 振动筛-交叉筛-螺旋筛-滚轴筛-正弦筛-方形摇摆筛「新乡振动筛厂家」 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 昆山新莱洁净应用材料股份有限公司-卫生级蝶阀,无菌取样阀,不锈钢隔膜阀,换向阀,离心泵 | 轻型地埋电缆故障测试仪,频响法绕组变形测试仪,静荷式卧式拉力试验机-扬州苏电 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 比士亚-专业恒温恒湿酒窖,酒柜,雪茄柜的设计定制 | 东莞市天进机械有限公司-钉箱机-粘箱机-糊箱机-打钉机认准东莞天进机械-厂家直供更放心! | 北京律师事务所_房屋拆迁律师_24小时免费法律咨询_云合专业律师网 | 流变仪-热分析联用仪-热膨胀仪厂家-耐驰科学仪器商贸 | 浙江自考_浙江自学考试网 | 企业微信scrm管理系统_客户关系管理平台_私域流量运营工具_CRM、ERP、OA软件-腾辉网络 | 光环国际-新三板公司_股票代码:838504| 重庆监控_电子围栏设备安装公司_门禁停车场管理系统-劲浪科技公司 | 河北凯普威医疗器材有限公司,高档轮椅系列,推车系列,座厕椅系列,协步椅系列,拐扙系列,卫浴系列 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 电竞馆加盟,沈阳网吧加盟费用选择嘉棋电竞_售后服务一体化 | 真空吸污车_高压清洗车厂家-程力专用汽车股份有限公司官网 | 浇钢砖,流钢砖_厂家价低-淄博恒森耐火材料有限公司 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | 上海宿田自动化设备有限公司-双面/平面/单面贴标机 | 河北中仪伟创试验仪器有限公司是专业生产沥青,土工,水泥,混凝土等试验仪器的厂家,咨询电话:13373070969 | 标策网-专注公司商业知识服务、助力企业发展 | 压缩空气检测_气体_水质找上海京工-服务专业、价格合理 | 科威信洗净科技,碳氢清洗机,超声波清洗机,真空碳氢清洗机 | 标准光源箱|对色灯箱|色差仪|光泽度仪|涂层测厚仪_HRC大品牌生产厂家 | 矿用履带式平板车|探水钻机|气动架柱式钻机|架柱式液压回转钻机|履带式钻机-启睿探水钻机厂家 | 最新电影-好看的电视剧大全-朝夕电影网 | 非小号行情 - 专业的区块链、数字藏品行情APP、金色财经官网 | 走心机厂家,数控走心机-台州博城智能科技有限公司 |