FreeNOS
creat.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <FileSystemClient.h>
19#include "errno.h"
20#include "limits.h"
21#include "stdio.h"
22#include "string.h"
23#include "sys/stat.h"
24
25int creat(const char *path, mode_t mode)
26{
27 const FileSystemClient filesystem;
28
29 // Ask FileSystem to create the file for us
30 const FileSystem::Result result = filesystem.createFile(path,
33 // Set errno
34 if (result == FileSystem::Success)
36 else
37 errno = EIO;
38
39 // Report result
40 return errno == ESUCCESS ? 0 : -1;
41}
FileSystemClient provides a simple interface to a FileSystemServer.
FileSystem::Result createFile(const char *path, const FileSystem::FileType type, const FileSystem::FileModes mode) const
Create a new file.
int creat(const char *path, mode_t mode)
Create a new file or rewrite an existing one.
Definition creat.cpp:25
#define ESUCCESS
Reports a success operation.
Definition errno.h:43
C int errno
The lvalue errno is used by many functions to return error values.
#define EIO
I/O error.
Definition errno.h:130
uint mode_t
Used for some file attributes.
Definition types.h:47
#define FILEMODE_MASK
Masker value for all FileMode values.
Definition stat.h:45
Result
Result code for filesystem Actions.
Definition FileSystem.h:53
u16 FileModes
Multiple FileMode values combined.
Definition FileSystem.h:108