ReactOS 0.4.16-dev-927-g467dec4
creat.cpp
Go to the documentation of this file.
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//
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}
#define __cdecl
Definition: accygwin.h:79
static int __cdecl common_creat(Character const *const path, int const pmode)
Definition: creat.cpp:24
int __cdecl _wcreat(wchar_t const *const path, int const pmode)
Definition: creat.cpp:38
int __cdecl _creat(char const *const path, int const pmode)
Definition: creat.cpp:33
#define _SH_DENYNO
Definition: share.h:17
#define _O_RDWR
Definition: cabinet.h:39
#define _O_TRUNC
Definition: cabinet.h:47
#define _O_CREAT
Definition: cabinet.h:46
#define e
Definition: ke_i.h:82
int errno_t
Definition: corecrt.h:615