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

📄 open.c

📁 嵌入式实验uC-OS-II相关程序用例与参考资料
💻 C
字号:
/* $id:dmOpen.c  V1.0 2001/09/5 */

/******************************************************************************
 *  This source code has been made available to you by CORETEK  on
 *  AS-IS.Anyone receiving this source is licensed under
 *  CORETEK copyrights to use it in any way he or she deems fit,including
 *  copying it,modifying it,compiling it,and redistributing it either with
 *  or without modifictions.
 *
 *
 *  Any person who transfers this source code or any derivative work must
 *  include the CORETEK copyright notice, this paragraph,and the preceding
 *  two paragraphs in the transferred software.
 *
 *
 *       COPYRIGHT CORETEK CORPORATION 2001
 *     LICENSED MATERIAL - PROGRAM PROPERTY OF CORETEK
 *****************************************************************************/


/******************************************************************************
 *
 *  FILE: Open.c
 *
 *  MODULE: RLT
 *
 *  PURPOSE: open() - POSIX 1003.1 5.3.1 - Open a File
 *
 *  AUTHOR(S):Zhang Yumin
 *
 *  GROUP:TOOL_GROUP
 *
 *  DATE CREATED:2001/09/05
 *
 *  REFERENCE DOCUMENT ID:
 *
 *  MODIFICATIONS:
 *  Date          user Name       Description
 *  2001/09/05    Zhang Yumin    Create this file
 *
 *********************************************************************************/
#include <stdarg.h>
#include <sys/reent.h>


int sys_open(const char* pathname, int flags,int mode)
{
	//实现open系统调用方法
	return 0;	
}



/********************************************************************
 *  FUNCTION: open
 *
 *  PURPOSE:  Open a file or device for reading or writing.
 *
 *  PARAMETERS:
 *
 *    Input:  pathname	-The file name specified by path is opened for reading
 *					 and/or writing.
 *			  flags	-The flags specified are formed by or'ing the following
 *					 values:
 *						O_RDONLY 	open for reading only
 *						O_WRONLY 	open for writing only
 *						O_RDWR 		open for reading and writing
 *						O_NONBLOCK 	do not block on open
 *						O_APPEND 	append on each write
 *						O_CREAT 	create file if it does not exist
 *						O_TRUNC 	truncate size to 0
 *						O_EXCL 		error if create and file exists
 *						O_SHLOCK 	atomically obtain a shared lock
 *						O_EXLOCK 	atomically obtain an exclusive lock
 *					 The flags argument may indicate the file is to be
 *					 created if it does not exist (by specifying the O_CREAT
 *					 flag). In this case open requires a third argument
 *					 'mode_t mode'.
 *			   mode	-Modes may be absolute or symbolic.An absolute mode is
 *					 an octal number constructed from the sum of one or more
 *					 of the following values:
 *						4000	the set-user-ID-on-execution bit
 *						2000	the set-group-ID-on-execution bit
 *						1000	the stickybit
 *						0400	set file I/O limitation to -r--------
 *						0200	set file I/O limitation to --w-------
 *						0100	set file I/O limitation to ---x------
 *						0040	set file I/O limitation to ----r-----
 *						0020	set file I/O limitation to -----w----
 *						0010	set file I/O limitation to ------x---
 *						0004	set file I/O limitation to -------r--
 *						0002	set file I/O limitation to --------w-
 *						0001	set file I/O limitation to ---------x
 *    Output: None
 *    InOut:  None
 *
 *  Return value: If successful,open() returns a non-negative integer,
 *				  termed a file descriptor.It returns -1 on failure, and
 *				  sets global variable 'errno' to indicate the error.
 *  Reentrant: Yes
 ********************************************************************/
 int _open_r(
 	struct _reent   *ptr,
 	const char      *pathname,
 	int           flags,
 	...
	)
{
	int rc;
	va_list  ap;

    va_start( ap, flags );
    rc = sys_open(pathname,flags,va_arg (ap,int));
 	va_end(ap);
	if(rc < 0)
	{
		ptr->_errno = -rc;
		return -1;
	}
	return rc;
}

#ifndef _REENT_ONLY

int open (const char *file, int flags, ...)
{
  va_list ap;
  int ret;

  va_start (ap, flags);
  ret = _open_r (_REENT, file, flags, va_arg (ap,int));
  va_end (ap);
  return ret;
}

#endif

⌨️ 快捷键说明

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