From a011c76d8500cb3eab022a73341f0e27cefe5eec Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sat, 12 Apr 2014 00:03:40 +0200 Subject: [PATCH] libc: Make File_descriptor::fd_path char const * --- libports/include/libc-plugin/fd_alloc.h | 11 ++++++----- libports/src/lib/libc/fd_alloc.cc | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libports/include/libc-plugin/fd_alloc.h b/libports/include/libc-plugin/fd_alloc.h index 500e397cc..309727994 100644 --- a/libports/include/libc-plugin/fd_alloc.h +++ b/libports/include/libc-plugin/fd_alloc.h @@ -40,7 +40,7 @@ namespace Libc { struct File_descriptor { int libc_fd = -1; - char *fd_path = 0; /* for 'fchdir', 'fstat' */ + char const *fd_path = 0; /* for 'fchdir', 'fstat' */ Plugin *plugin = 0; Plugin_context *context = 0; unsigned flags = 0; /* for 'fcntl' */ @@ -50,14 +50,15 @@ namespace Libc { void path(char const *newpath) { if (newpath) { - size_t path_size = ::strlen(newpath) + 1; - fd_path = (char*)malloc(path_size); - if (!fd_path) { + size_t const path_size = ::strlen(newpath) + 1; + char *buf = (char*)malloc(path_size); + if (!buf) { PERR("could not allocate path buffer for libc_fd %d%s", libc_fd, libc_fd == ANY_FD ? " (any)" : ""); return; } - ::memcpy(fd_path, newpath, path_size); + ::memcpy(buf, newpath, path_size); + fd_path = buf; } else fd_path = 0; } diff --git a/libports/src/lib/libc/fd_alloc.cc b/libports/src/lib/libc/fd_alloc.cc index f82033e44..ce1efffbe 100644 --- a/libports/src/lib/libc/fd_alloc.cc +++ b/libports/src/lib/libc/fd_alloc.cc @@ -72,7 +72,7 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin, void File_descriptor_allocator::free(File_descriptor *fdo) { - ::free(fdo->fd_path); + ::free((void *)fdo->fd_path); Allocator_avl_base::free(reinterpret_cast(fdo->libc_fd)); }