libc: Make File_descriptor::fd_path char const *

This commit is contained in:
Norman Feske 2014-04-12 00:03:40 +02:00 committed by Christian Helmuth
parent dd9b606182
commit a011c76d85
2 changed files with 7 additions and 6 deletions

View File

@ -40,7 +40,7 @@ namespace Libc {
struct File_descriptor struct File_descriptor
{ {
int libc_fd = -1; int libc_fd = -1;
char *fd_path = 0; /* for 'fchdir', 'fstat' */ char const *fd_path = 0; /* for 'fchdir', 'fstat' */
Plugin *plugin = 0; Plugin *plugin = 0;
Plugin_context *context = 0; Plugin_context *context = 0;
unsigned flags = 0; /* for 'fcntl' */ unsigned flags = 0; /* for 'fcntl' */
@ -50,14 +50,15 @@ namespace Libc {
void path(char const *newpath) void path(char const *newpath)
{ {
if (newpath) { if (newpath) {
size_t path_size = ::strlen(newpath) + 1; size_t const path_size = ::strlen(newpath) + 1;
fd_path = (char*)malloc(path_size); char *buf = (char*)malloc(path_size);
if (!fd_path) { if (!buf) {
PERR("could not allocate path buffer for libc_fd %d%s", PERR("could not allocate path buffer for libc_fd %d%s",
libc_fd, libc_fd == ANY_FD ? " (any)" : ""); libc_fd, libc_fd == ANY_FD ? " (any)" : "");
return; return;
} }
::memcpy(fd_path, newpath, path_size); ::memcpy(buf, newpath, path_size);
fd_path = buf;
} else } else
fd_path = 0; fd_path = 0;
} }

View File

@ -72,7 +72,7 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin,
void File_descriptor_allocator::free(File_descriptor *fdo) void File_descriptor_allocator::free(File_descriptor *fdo)
{ {
::free(fdo->fd_path); ::free((void *)fdo->fd_path);
Allocator_avl_base::free(reinterpret_cast<void*>(fdo->libc_fd)); Allocator_avl_base::free(reinterpret_cast<void*>(fdo->libc_fd));
} }