FreeNOS
open.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 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 <FreeNOS/User.h>
19 #include <FileSystemClient.h>
20 #include "limits.h"
21 #include "string.h"
22 #include "errno.h"
23 #include "fcntl.h"
24 #include "sys/stat.h"
25 
26 int open(const char *path, int oflag, ...)
27 {
28  const FileSystemClient filesystem;
29  Size fd = 0;
30 
31  // Attempt to open the file
32  const FileSystem::Result result = filesystem.openFile(path, fd);
33  if (result == FileSystem::Success)
34  {
35  errno = ESUCCESS;
36  return (int) fd;
37  }
38  else
39  {
40  // File not found
41  errno = ENOENT;
42  return -1;
43  }
44 }
fcntl.h
errno
C int errno
The lvalue errno is used by many functions to return error values.
string.h
FileSystemClient
FileSystemClient provides a simple interface to a FileSystemServer.
Definition: FileSystemClient.h:42
ESUCCESS
#define ESUCCESS
Reports a success operation.
Definition: errno.h:43
open
int open(const char *path, int oflag,...)
Open file relative to directory file descriptor.
Definition: open.cpp:26
FileSystem::Success
@ Success
Definition: FileSystem.h:54
limits.h
FileSystemClient::openFile
FileSystem::Result openFile(const char *path, Size &descriptor) const
Open a file.
Definition: FileSystemClient.cpp:198
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
stat.h
ENOENT
#define ENOENT
No such file or directory.
Definition: errno.h:178
FileSystemClient.h
FileSystem::Result
Result
Result code for filesystem Actions.
Definition: FileSystem.h:52
errno.h