⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wincompat.c

📁 goahead webserver源码
💻 C
📖 第 1 页 / 共 2 页
字号:
}/******************************************************************************//* *	Delete a file. */int _wunlink(char_t *file){	char_t	*cwd, *cwdFile;	cwdFile = NULL;	if ((*file != '/') && (*file != '\\')) {		cwd = balloc(B_L, LF_PATHSIZE);		ggetcwd(cwd, LF_PATHSIZE / sizeof(char_t));		fmtAlloc(&cwdFile, LF_PATHSIZE / sizeof(char_t), T("%s/%s"), cwd, file);		bfree(B_L, cwd);		file = cwdFile;	}	if (DeleteFile(file) != TRUE) {		bfreeSafe(B_L, cwdFile);		return -1;	}	bfreeSafe(B_L, cwdFile);	return 0;}/******************************************************************************//* *	Create a new directory */int _wmkdir(const char_t *path){	char_t	*cwd, *cwdPath;	cwdPath = NULL;	if ((*path != '/') && (*path != '\\')) {		cwd = balloc(B_L, LF_PATHSIZE);		ggetcwd(cwd, LF_PATHSIZE / sizeof(char_t));		fmtAlloc(&cwdPath, LF_PATHSIZE, T("%s/%s"), cwd, path);		bfree(B_L, cwd);		path = cwdPath;	}	if (CreateDirectory(path, NULL) == 0) {		bfreeSafe(B_L, cwdPath);		return -1;	}	bfreeSafe(B_L, cwdPath);	return 0;}/******************************************************************************//* *	Remove a directory */int _wrmdir(const char_t *path){	char_t	*cwd, *cwdPath;	cwdPath = NULL;	if ((*path != '/') && (*path != '\\')) {		cwd = balloc(B_L, LF_PATHSIZE);		ggetcwd(cwd, LF_PATHSIZE / sizeof(char_t));		fmtAlloc(&cwdPath, LF_PATHSIZE, T("%s/%s"), cwd, path);		bfree(B_L, cwd);		path = cwdPath;	}	if (RemoveDirectory(path) == 0) {		bfreeSafe(B_L, cwdPath);		return -1;	}	bfreeSafe(B_L, cwdPath);	return 0;}/******************************************************************************//* *	Get file information about an open file. */int fstat(int fid, struct _stat *sbuf){	BY_HANDLE_FILE_INFORMATION	info;	long						size;	fh_t						*fp;	a_assert(0 <= fid && fid < fMax);	fp = f[fid];	if (fp == NULL || fp->hand == INVALID_HANDLE_VALUE) {		return -1;	}	size = GetFileSize(fp->hand, NULL);	if (size == 0xFFFFFFFF) {		return -1;	}	sbuf->st_size = (int) size;	if (GetFileInformationByHandle(fp->hand, &info)) {		if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {			sbuf->st_mode = S_IFDIR;		} else {			sbuf->st_mode = S_IFREG;		}		sbuf->st_mtime = fileTimeToUnixEpochTime(info.ftLastWriteTime);		return 0;	}	return -1;}/******************************************************************************//* *	Our implementation of wide character stat: get file information. */int _wstat(char_t *filename, struct _stat *sbuf){	DWORD	dwAttributes;	int		fid, rc;	memset(sbuf, 0, sizeof(struct _stat));	dwAttributes = GetFileAttributes(filename);	if (dwAttributes != 0xFFFFFFFF && dwAttributes & FILE_ATTRIBUTE_DIRECTORY) {		sbuf->st_mode = S_IFDIR;		return 0;	}	sbuf->st_mode = S_IFREG;	if ((fid = _wopen(filename, 0, 0)) < 0) {		return -1;	}	rc = fstat(fid, sbuf);	close(fid);	return rc;		 }/******************************************************************************//* *	Our implementation of wide character rename: change the name of a file. */int _wrename(const char_t *oldname, const char_t *newname){	char_t	*cwd, *cwdOldname, *cwdNewname;	cwdOldname = cwd = NULL;	if ((*oldname != '/') && (*oldname != '\\')) {		cwd = balloc(B_L, LF_PATHSIZE);		ggetcwd(cwd, LF_PATHSIZE / sizeof(char_t));		fmtAlloc(&cwdOldname, LF_PATHSIZE, T("%s/%s"), cwd, oldname);		oldname = cwdOldname;	}		cwdNewname = NULL;	if ((*newname != '/') && (*newname != '\\')) {		if (cwd != NULL) {			cwd = balloc(B_L, LF_PATHSIZE);			ggetcwd(cwd, LF_PATHSIZE / sizeof(char_t));		}		fmtAlloc(&cwdNewname, LF_PATHSIZE, T("%s/%s"), cwd, newname);		newname = cwdNewname;	}	if (MoveFile(oldname, newname) == 0) {		bfreeSafe(B_L, cwdOldname);		bfreeSafe(B_L, cwdNewname);		bfreeSafe(B_L, cwd);		return 1;	} else {		bfreeSafe(B_L, cwdOldname);		bfreeSafe(B_L, cwdNewname);		bfreeSafe(B_L, cwd);		return 0;	}}/******************************************************************************//* *	Our implementation of wide character access: get file access permission. */int _waccess(const unsigned short *path, int mode){	int	fid, omode;	if (mode == R_OK) {		omode = O_RDONLY;	} else if (mode == W_OK) {		omode = O_RDWR;	} else {		a_assert(0);	}	if ((fid = _wopen(path, omode)) < 0) {		return -1;	}	close(fid);	return 0;}/******************************************************************************//* *	Support for stream I/O. The only way we supply a FILE* is via fdopen. In *	this case we return the real file handle. */FILE* fdopen(int handle, const unsigned short *mode){	return (FILE*) handle;}#if 0int fclose(FILE *stream){	fh_t	*fp;	int		fid;	for (fid = 0; fid > fMax; fid++) {		if ((fp = f[fid]) != NULL) {			if (fp->hand == stream) {				close(fid);				return 0;			}		}	}	return EOF;}int fflush(FILE* stream){	return 0;}#endif /* 0 *//******************************************************************************//* * lseek  -  position a file. */long lseek(int handle, long offset, int origin){	fh_t	*fp;	fp = f[handle];	return SetFilePointer(fp->hand, offset, NULL, origin);}/******************************************************************************//* *	A bunch of ASCII character routines. *//******************************************************************************//* *	Our implementation of isupper. */#if 0/* 10 Apr 03 BgP -- CE.NET work. The following functions are now directly supported by CE,    so we do not need these compatibility versions.*/int isupper(int c){	if (c >= 'A' && c <= 'Z') {		return 1;	}	return 0;}/******************************************************************************//* *	Our implementation of islower. */int islower(int c){	if (c >= 'a' && c <= 'z') {		return 1;	}	return 0;}/******************************************************************************//* *	Our implementation of isdigit. */int isdigit(int c){	if (c >= '0' && c <= '9') {		return 1;	}	return 0;}/******************************************************************************//* *	Our implementation of isspace. */int isspace(int c){	if (c >= 0x9 && c <= 0xd || c == 0x20) {		return 1;	}	return 0;}/******************************************************************************//* *	Our implementation of isprint. */int isprint(int c){	if (c >= 0x20 && c <= 0x7e) {		return 1;	}	return 0;}/******************************************************************************//* *	Our implementation of isxdigit. */int isxdigit(int c){	if ((c >= '0' && c <= '9') ||		(c >= 'a' && c <= 'f') ||		(c >= 'A' && c <= 'F')) {		return 1;	}	return 0;}#endif/******************************************************************************/#ifndef LITTLEFOOTint umask(int mode){	return 0;}#endif/******************************************************************************//* * If the application needs wprintf functionality, insert it here. */#if 0int wprintf(const char_t *fmt, ...){	return 0;}#endif#if 0int fwprintf(FILE *stream, const char_t *fmt, ...){	return 0;}int fputws(const char_t *fmt, FILE *stream){	return 0;}#endif /* 0 */#ifndef LITTLEFOOTint _wexecvp(char_t *path, char_t** argv){	return -1;}#endif/******************************************************************************//* *	Return the current working directory */char_t *_wgetcwd(char_t *dir, int len){	if (len > LF_PATHSIZE) {		return NULL;	} else {		return wcscpy(dir, ceCwd);	}}/******************************************************************************//* *	Change the current working directory */int _wchdir(unsigned short *path){	char_t	*p;	char_t	buf[LF_PATHSIZE];	int		len;	gstat_t	statDir;/* *	Ignore leading spaces */	while(*path == ' ') {		path++;	}	if (path == NULL || *path == '\0') {		return -1;	} else if ((*path == '/') || (*path == '\\')) {		 wcscpy(ceCwd, path);	} else {/* *		Otherwise, it's a relative path.  Combine with current path. *		Append a '/' if the last character is not already a '/'. *		Check for leading "./" or "../" and back up the cwd accordingly. */		for (p = path; *p; p++) {			if (*p == '\\') {				*p = '/';			}		}		gstrcpy(buf, ceCwd);		for (p = buf; *p; p++) {			if (*p == '\\') {				*p = '/';			}		}		if (*path == '.' && *(path+1) == '/') {			path++;			while (*path == '/') {				path++;			}		}		while (*path == '.' && *(path+1) == '.') {			path += 2;			if ((p = wcsrchr(buf, '/')) == NULL) {				return -1;			}			*p = '\0';			if (*path == '\0') {				break;			}			if (*path != '/') {				return -1;			}			while (*path == '/') {				path++;			}		}/* *		Ignore leading spaces and dots */		while(*path == '.' || *path == ' ') {			path++;		}/* *		Append to cwd. */		len = wcslen(buf);		if (*(buf + len - 1) != '/') {			*(buf + len) = '/';			*(buf + len + 1) = '\0';			len++;		}		if ((len + gstrlen(path) + 1) > LF_PATHSIZE ) {			return -1;		}		gstrcpy(buf+len, path);		if (_wstat(buf, &statDir) == -1) {			return -1;		}		gstrcpy(ceCwd, buf);	}	return 0;}/******************************************************************************//* *	Change the file-permission settings */int _wchmod(const char_t *filename, int pmode){	return 0;}/******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -