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

📄 fopen.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
字号:
/* $Id: fopen.c 21262 2006-03-08 23:27:16Z audit $
 *
 *  ReactOS msvcrt library
 *
 *  fopen.c
 *
 *  Copyright (C) 2002  Robert Dickenson <robd@reactos.org>
 *
 *  Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
 *                         28/12/1998: Appropriated for Reactos
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */

#include <precomp.h>

#include <tchar.h>

//might change fopen(file,mode) -> fsopen(file,mode,_SH_DENYNO);

FILE* _tfopen(const _TCHAR *file, const _TCHAR *mode)
{
  FILE *f;
  int fd, rw, oflags = 0;

  if (file == 0)
    return 0;
  if (mode == 0)
    return 0;

  f = __alloc_file();
  if (f == NULL)
    return NULL;

  rw = (_tcschr(mode, '+') == NULL) ? 0 : 1;
  if (_tcschr(mode, 'a'))
    oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
  if (_tcschr(mode, 'r'))
    oflags = rw ? O_RDWR : O_RDONLY;
  if (_tcschr(mode, 'w'))
    oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
  if (_tcschr(mode, 't'))
    oflags |= O_TEXT;
  else if (_tcschr(mode, 'b'))
    oflags |= O_BINARY;
  else
    oflags |= (_fmode& (O_TEXT|O_BINARY));

  fd = _topen(file, oflags, 0);
  if (fd < 0)
    return NULL;

// msvcrt ensures that writes will end up at the end of file in append mode
// we just move the file pointer to the end of file initially

  if (_tcschr(mode, 'a'))
    _lseek(fd, 0, SEEK_END);

  f->_cnt = 0;
  f->_file = fd;
  f->_bufsiz = 0;
  if (rw)
    f->_flag = _IOREAD | _IOWRT;
  else if (_tcschr(mode, 'r'))
    f->_flag = _IOREAD;
  else
    f->_flag = _IOWRT;

  if (_tcschr(mode, 't'))
    f->_flag |= _IOTEXT;
  else if (_tcschr(mode, 'b'))
    f->_flag |= _IOBINARY;
  else if (_fmode& O_BINARY)
    f->_flag |= _IOBINARY;

  f->_base = f->_ptr = NULL;
  return f;
}

⌨️ 快捷键说明

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