FreeNOS
getcwd.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 <Assert.h>
19#include <FileSystemClient.h>
20#include <string.h>
21#include <errno.h>
22#include "unistd.h"
23
24char *getcwd(char *buf, size_t size)
25{
26 const FileSystemClient filesystem;
27 const String *currentDirectory = filesystem.getCurrentDirectory();
28
29 // Copy our current working directory
30 assert(currentDirectory != NULL);
31 memcpy(buf, **currentDirectory, size);
32
33 // Set errno
35
36 // Done
37 return buf;
38}
FileSystemClient provides a simple interface to a FileSystemServer.
const String * getCurrentDirectory() const
Get current directory String.
Abstraction of strings.
Definition String.h:42
#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 assert(exp)
Insert program diagnostics.
Definition assert.h:60
C void * memcpy(void *dest, const void *src, size_t count)
Copy memory from one place to another.
Definition memcpy.cpp:20
char * getcwd(char *buf, size_t size)
Get the pathname of the current working directory.
Definition getcwd.cpp:24
#define NULL
NULL means zero.
Definition Macros.h:39