Reactos
at master 41 lines 1.3 kB view raw
1// 2// creat.cpp 3// 4// Copyright (c) Microsoft Corporation. All rights reserved. 5// 6// Defines _creat() (and _wcreat(), via inclusion), which creates a new file. 7// 8#include <corecrt_internal_lowio.h> 9 10 11 12// Creates a new file. 13// 14// If the file does not exist, this function creates a new file with the given 15// permission setting and opens it for writing. If the file already exists and 16// its permission allows writing, this function truncates it to zero length and 17// opens it for writing. 18// 19// The only XENIX mode bit supported is user write (S_IWRITE). 20// 21// On success, the handle for the newly created file is returned. On failure, 22// -1 is returned and errno is set. 23template <typename Character> 24static int __cdecl common_creat(Character const* const path, int const pmode) throw() 25{ 26 typedef __crt_char_traits<Character> traits; 27 // creat is just the same as open... 28 int fh = -1; 29 errno_t e = traits::tsopen_s(&fh, path, _O_CREAT + _O_TRUNC + _O_RDWR, _SH_DENYNO, pmode); 30 return e == 0 ? fh : -1; 31} 32 33extern "C" int __cdecl _creat(char const* const path, int const pmode) 34{ 35 return common_creat(path, pmode); 36} 37 38extern "C" int __cdecl _wcreat(wchar_t const* const path, int const pmode) 39{ 40 return common_creat(path, pmode); 41}