diff --git a/io/include/pcl/io/impl/pcd_io.hpp b/io/include/pcl/io/impl/pcd_io.hpp index 22b80c88018..fae1ff5ff0b 100644 --- a/io/include/pcl/io/impl/pcd_io.hpp +++ b/io/include/pcl/io/impl/pcd_io.hpp @@ -44,43 +44,11 @@ #include #include #include -#include #include +#include +#include #include -#ifdef _WIN32 -# include -# ifndef WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif // WIN32_LEAN_AND_MEAN -# ifndef NOMINMAX -# define NOMINMAX -# endif // NOMINMAX -# include -# define pcl_open _open -# define pcl_close(fd) _close(fd) -# define pcl_lseek(fd,offset,origin) _lseek(fd,offset,origin) -# define pcl_read(fd,dest,size) _read(fd,dest,size) -/* ssize_t is also not available (copy/paste from MinGW) */ -#ifdef _MSC_VER -#ifndef _SSIZE_T_DEFINED -#define _SSIZE_T_DEFINED -#undef ssize_t -#ifdef _WIN64 -typedef __int64 ssize_t; -#else -typedef int ssize_t; -#endif /* _WIN64 */ -#endif /* _SSIZE_T_DEFINED */ -#endif /* _MSC_VER */ -#else -# include -# define pcl_open open -# define pcl_close(fd) close(fd) -# define pcl_lseek(fd,offset,origin) lseek(fd,offset,origin) -# define pcl_read(fd,dest,size) ::read(fd,dest,size) -#endif - #include ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -162,7 +130,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, return (-1); } #else - int fd = pcl_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int fd = io::raw_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { throw pcl::IOException ("[pcl::PCDWriter::writeBinary] Error during open!"); @@ -209,7 +177,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, // Allocate disk space for the entire file to prevent bus errors. if (::posix_fallocate (fd, 0, data_idx + data_size) != 0) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinary] posix_fallocate errno: %d strerror: %s\n", errno, strerror (errno)); @@ -217,10 +185,10 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, return (-1); } - char *map = static_cast (mmap (0, data_idx + data_size, PROT_WRITE, MAP_SHARED, fd, 0)); + char *map = static_cast (::mmap (0, data_idx + data_size, PROT_WRITE, MAP_SHARED, fd, 0)); if (map == reinterpret_cast (-1)) //MAP_FAILED) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); throw pcl::IOException ("[pcl::PCDWriter::writeBinary] Error during mmap ()!"); return (-1); @@ -252,9 +220,9 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, #if _WIN32 UnmapViewOfFile (map); #else - if (munmap (map, (data_idx + data_size)) == -1) + if (::munmap (map, (data_idx + data_size)) == -1) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); throw pcl::IOException ("[pcl::PCDWriter::writeBinary] Error during munmap ()!"); return (-1); @@ -264,7 +232,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, #if _WIN32 CloseHandle (h_native_file); #else - pcl_close (fd); + io::raw_close (fd); #endif resetLockingPermissions (file_name, file_lock); return (0); @@ -294,7 +262,7 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, return (-1); } #else - int fd = pcl_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int fd = io::raw_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { throw pcl::IOException ("[pcl::PCDWriter::writeBinaryCompressed] Error during open!"); @@ -391,7 +359,7 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, else { #if !_WIN32 - pcl_close (fd); + io::raw_close (fd); #endif resetLockingPermissions (file_name, file_lock); throw pcl::IOException ("[pcl::PCDWriter::writeBinaryCompressed] Error during compression!"); @@ -408,7 +376,7 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, // Allocate disk space for the entire file to prevent bus errors. if (::posix_fallocate (fd, 0, compressed_final_size) != 0) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] posix_fallocate errno: %d strerror: %s\n", errno, strerror (errno)); @@ -416,10 +384,10 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, return (-1); } - char *map = static_cast (mmap (0, compressed_final_size, PROT_WRITE, MAP_SHARED, fd, 0)); + char *map = static_cast (::mmap (0, compressed_final_size, PROT_WRITE, MAP_SHARED, fd, 0)); if (map == reinterpret_cast (-1)) //MAP_FAILED) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); throw pcl::IOException ("[pcl::PCDWriter::writeBinaryCompressed] Error during mmap ()!"); return (-1); @@ -441,9 +409,9 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, #if _WIN32 UnmapViewOfFile (map); #else - if (munmap (map, (compressed_final_size)) == -1) + if (::munmap (map, (compressed_final_size)) == -1) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); throw pcl::IOException ("[pcl::PCDWriter::writeBinaryCompressed] Error during munmap ()!"); return (-1); @@ -454,7 +422,7 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, #if _WIN32 CloseHandle (h_native_file); #else - pcl_close (fd); + io::raw_close (fd); #endif resetLockingPermissions (file_name, file_lock); @@ -666,7 +634,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, return (-1); } #else - int fd = pcl_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int fd = io::raw_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { throw pcl::IOException ("[pcl::PCDWriter::writeBinary] Error during open!"); @@ -708,7 +676,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, // Allocate disk space for the entire file to prevent bus errors. if (::posix_fallocate (fd, 0, data_idx + data_size) != 0) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinary] posix_fallocate errno: %d strerror: %s\n", errno, strerror (errno)); @@ -716,10 +684,10 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, return (-1); } - char *map = static_cast (mmap (0, data_idx + data_size, PROT_WRITE, MAP_SHARED, fd, 0)); + char *map = static_cast (::mmap (0, data_idx + data_size, PROT_WRITE, MAP_SHARED, fd, 0)); if (map == reinterpret_cast (-1)) //MAP_FAILED) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); throw pcl::IOException ("[pcl::PCDWriter::writeBinary] Error during mmap ()!"); return (-1); @@ -751,9 +719,9 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, #if _WIN32 UnmapViewOfFile (map); #else - if (munmap (map, (data_idx + data_size)) == -1) + if (::munmap (map, (data_idx + data_size)) == -1) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); throw pcl::IOException ("[pcl::PCDWriter::writeBinary] Error during munmap ()!"); return (-1); @@ -763,7 +731,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, #if _WIN32 CloseHandle(h_native_file); #else - pcl_close (fd); + io::raw_close (fd); #endif resetLockingPermissions (file_name, file_lock); diff --git a/io/include/pcl/io/low_level_io.h b/io/include/pcl/io/low_level_io.h new file mode 100644 index 00000000000..958175b88b0 --- /dev/null +++ b/io/include/pcl/io/low_level_io.h @@ -0,0 +1,165 @@ +/* + * Software License Agreement (BSD License) + * + * Point Cloud Library (PCL) - www.pointclouds.org + * Copyright (c) 2012-, Open Perception, Inc. + * Copyright (c) 2018 Fizyr BV. - https://fizyr.com + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of the copyright holder(s) nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * This file defines compatibility wrappers for low level I/O functions. + * Implemented as inlinable functions to prevent any performance overhead. + */ + +#ifndef __PCL_IO_LOW_LEVEL_IO__ +#define __PCL_IO_LOW_LEVEL_IO__ + +#ifdef _WIN32 +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# ifndef NOMINMAX +# define NOMINMAX +# endif +# include +# include +# include +typedef SSIZE_T ssize_t; +#else +# include +# include +# include +# include +# include +#endif + +namespace pcl +{ + namespace io + { +#ifdef _WIN32 + inline int raw_open(const char * pathname, int flags, int mode) + { + return ::_open(pathname, flags, mode); + } + + inline int raw_open(const char * pathname, int flags) + { + return ::_open(pathname, flags); + } + + inline int raw_close(int fd) + { + return ::_close(fd); + } + + inline int raw_lseek(int fd, long offset, int whence) + { + return ::_lseek(fd, offset, whence); + } + + inline int raw_read(int fd, void * buffer, size_t count) + { + return ::_read(fd, buffer, count); + } + + inline int raw_write(int fd, const void * buffer, size_t count) + { + return ::_write(fd, buffer, count); + } + + inline int raw_fallocate(int fd, long len) + { + return ::_chsize(fd, len); + } +#else + inline int raw_open(const char * pathname, int flags, int mode) + { + return ::open(pathname, flags, mode); + } + + inline int raw_open(const char * pathname, int flags) + { + return ::open(pathname, flags); + } + + inline int raw_close(int fd) + { + return ::close(fd); + } + + inline off_t raw_lseek(int fd, off_t offset, int whence) + { + return ::lseek(fd, offset, whence); + } + + inline ssize_t raw_read(int fd, void * buffer, size_t count) + { + return ::read(fd, buffer, count); + } + + inline ssize_t raw_write(int fd, const void * buffer, size_t count) + { + return ::write(fd, buffer, count); + } + +# ifndef __APPLE__ + inline int raw_fallocate(int fd, off_t len) + { + return ::posix_fallocate(fd, 0, len); + } +# else + inline int raw_fallocate(int fd, off_t len) + { + // Try to allocate contiguous space first. + ::fstore_t store = {F_ALLOCATEALL | F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, len}; + if (::fcntl(fd, F_PREALLOCATE, &store) < 0) + { + // Try fragmented if that failed. + store.fst_flags = F_ALLOCATEALL; + int ret = ::fcntl(fd, F_PREALLOCATE, &store); + + // Bail if it still failed. + if (ret < 0) { + return ret; + } + } + + // File could be larger than requested, so truncate. + return ::ftruncate(fd, len); + } +# endif // __APPLE__ +#endif // _WIN32 + + } +} +#endif // __PCL_IO_LOW_LEVEL_IO__ diff --git a/io/src/lzf_image_io.cpp b/io/src/lzf_image_io.cpp index b93ec95b612..b019ad62bad 100644 --- a/io/src/lzf_image_io.cpp +++ b/io/src/lzf_image_io.cpp @@ -35,6 +35,7 @@ * */ #include +#include #include #include #include @@ -44,19 +45,6 @@ #include #include -#ifdef _WIN32 -# include -# include -# define pcl_open _open -# define pcl_close(fd) _close(fd) -# define pcl_lseek(fd,offset,origin) _lseek(fd,offset,origin) -#else -# include -# define pcl_open open -# define pcl_close(fd) close(fd) -# define pcl_lseek(fd,offset,origin) lseek(fd,offset,origin) -#endif - #define LZF_HEADER_SIZE 37 @@ -87,34 +75,34 @@ pcl::io::LZFImageWriter::saveImageBlob (const char* data, UnmapViewOfFile (map); CloseHandle (h_native_file); #else - int fd = pcl_open (filename.c_str (), O_RDWR | O_CREAT | O_TRUNC, static_cast (0600)); + int fd = raw_open (filename.c_str (), O_RDWR | O_CREAT | O_TRUNC, static_cast (0600)); if (fd < 0) return (false); // Allocate disk space for the entire file to prevent bus errors. if (::posix_fallocate (fd, 0, data_size) != 0) { - pcl_close (fd); + raw_close (fd); throw pcl::IOException ("[pcl::PCDWriter::writeBinary] Error during posix_fallocate ()!"); return (false); } - char *map = static_cast (mmap (0, data_size, PROT_WRITE, MAP_SHARED, fd, 0)); + char *map = static_cast (::mmap (0, data_size, PROT_WRITE, MAP_SHARED, fd, 0)); if (map == reinterpret_cast (-1)) // MAP_FAILED { - pcl_close (fd); + raw_close (fd); return (false); } // Copy the data memcpy (&map[0], data, data_size); - if (munmap (map, (data_size)) == -1) + if (::munmap (map, (data_size)) == -1) { - pcl_close (fd); + raw_close (fd); return (false); } - pcl_close (fd); + raw_close (fd); #endif return (true); } @@ -379,7 +367,7 @@ pcl::io::LZFImageReader::loadImageBlob (const std::string &filename, return (false); } // Open for reading - int fd = pcl_open (filename.c_str (), O_RDONLY); + int fd = raw_open (filename.c_str (), O_RDONLY); if (fd == -1) { PCL_ERROR ("[pcl::io::LZFImageReader::loadImage] Failure to open file %s\n", filename.c_str () ); @@ -387,15 +375,15 @@ pcl::io::LZFImageReader::loadImageBlob (const std::string &filename, } // Seek to the end of file to get the filesize - off_t data_size = pcl_lseek (fd, 0, SEEK_END); + long data_size = raw_lseek (fd, 0, SEEK_END); if (data_size < 0) { - pcl_close (fd); + raw_close (fd); PCL_ERROR ("[pcl::io::LZFImageReader::loadImage] lseek errno: %d strerror: %s\n", errno, strerror (errno)); PCL_ERROR ("[pcl::io::LZFImageReader::loadImage] Error during lseek ()!\n"); return (false); } - pcl_lseek (fd, 0, SEEK_SET); + raw_lseek (fd, 0, SEEK_SET); #ifdef _WIN32 // As we don't know the real size of data (compressed or not), @@ -407,15 +395,15 @@ pcl::io::LZFImageReader::loadImageBlob (const std::string &filename, if (map == NULL) { CloseHandle (fm); - pcl_close (fd); + raw_close (fd); PCL_ERROR ("[pcl::io::LZFImageReader::loadImage] Error mapping view of file, %s\n", filename.c_str ()); return (false); } #else - char *map = static_cast (mmap (0, data_size, PROT_READ, MAP_SHARED, fd, 0)); + char *map = static_cast (::mmap (0, data_size, PROT_READ, MAP_SHARED, fd, 0)); if (map == reinterpret_cast (-1)) // MAP_FAILED { - pcl_close (fd); + raw_close (fd); PCL_ERROR ("[pcl::io::LZFImageReader::loadImage] Error preparing mmap for PCLZF file.\n"); return (false); } @@ -431,7 +419,7 @@ pcl::io::LZFImageReader::loadImageBlob (const std::string &filename, UnmapViewOfFile (map); CloseHandle (fm); #else - munmap (map, data_size); + ::munmap (map, data_size); #endif return (false); } @@ -453,7 +441,7 @@ pcl::io::LZFImageReader::loadImageBlob (const std::string &filename, UnmapViewOfFile (map); CloseHandle (fm); #else - munmap (map, data_size); + ::munmap (map, data_size); #endif return (false); } @@ -467,12 +455,12 @@ pcl::io::LZFImageReader::loadImageBlob (const std::string &filename, UnmapViewOfFile (map); CloseHandle (fm); #else - if (munmap (map, data_size) == -1) + if (::munmap (map, data_size) == -1) PCL_ERROR ("[pcl::io::LZFImageReader::loadImage] Munmap failure\n"); #endif - pcl_close (fd); + raw_close (fd); - data_size = off_t (compressed_size); // We only care about this from here on + data_size = compressed_size; // We only care about this from here on return (true); } diff --git a/io/src/pcd_grabber.cpp b/io/src/pcd_grabber.cpp index 0b14e1f1cf4..c7a9ddbbbb2 100644 --- a/io/src/pcd_grabber.cpp +++ b/io/src/pcd_grabber.cpp @@ -36,24 +36,12 @@ */ #include +#include #include #include #include #include #include - -#ifdef _WIN32 -# include -# include -# define pcl_open _open -# define pcl_close(fd) _close(fd) -# define pcl_lseek(fd,offset,origin) _lseek(fd,offset,origin) -#else -# include -# define pcl_open open -# define pcl_close(fd) close(fd) -# define pcl_lseek(fd,offset,origin) lseek(fd,offset,origin) -#endif /////////////////////////////////////////////////////////////////////////////////////////// //////////////////////// GrabberImplementation ////////////////////// @@ -186,7 +174,7 @@ pcl::PCDGrabberBase::PCDGrabberImpl::readAhead () else { tar_offset_ += (tar_header_.getFileSize ()) + (512 - tar_header_.getFileSize () % 512); - int result = static_cast (pcl_lseek (tar_fd_, tar_offset_, SEEK_SET)); + int result = static_cast (io::raw_lseek (tar_fd_, tar_offset_, SEEK_SET)); if (result < 0) closeTARFile (); } @@ -209,7 +197,7 @@ pcl::PCDGrabberBase::PCDGrabberImpl::readAhead () else { tar_offset_ += (tar_header_.getFileSize ()) + (512 - tar_header_.getFileSize () % 512); - int result = static_cast (pcl_lseek (tar_fd_, tar_offset_, SEEK_SET)); + int result = static_cast (io::raw_lseek (tar_fd_, tar_offset_, SEEK_SET)); if (result < 0) closeTARFile (); } @@ -271,7 +259,7 @@ pcl::PCDGrabberBase::PCDGrabberImpl::readTARHeader () void pcl::PCDGrabberBase::PCDGrabberImpl::closeTARFile () { - pcl_close (tar_fd_); + io::raw_close (tar_fd_); tar_fd_ = -1; tar_offset_ = 0; memset (&tar_header_.file_name[0], 0, 512); @@ -281,7 +269,7 @@ pcl::PCDGrabberBase::PCDGrabberImpl::closeTARFile () int pcl::PCDGrabberBase::PCDGrabberImpl::openTARFile (const std::string &file_name) { - tar_fd_ = pcl_open (file_name.c_str (), O_RDONLY); + tar_fd_ = io::raw_open (file_name.c_str (), O_RDONLY); if (tar_fd_ == -1) return (-1); @@ -334,7 +322,7 @@ pcl::PCDGrabberBase::PCDGrabberImpl::scrapeForClouds (bool force) cloud_idx_to_file_idx_.push_back (i); // Update offset tar_offset_ += (tar_header_.getFileSize ()) + (512 - tar_header_.getFileSize () % 512); - int result = static_cast (pcl_lseek (tar_fd_, tar_offset_, SEEK_SET)); + int result = static_cast (io::raw_lseek (tar_fd_, tar_offset_, SEEK_SET)); if (result < 0) break; if (tar_fd_ == -1) diff --git a/io/src/pcd_io.cpp b/io/src/pcd_io.cpp index 514ce211759..f1ca1502b73 100644 --- a/io/src/pcd_io.cpp +++ b/io/src/pcd_io.cpp @@ -43,25 +43,14 @@ #include #include #include -#include +#include #include +#include #include #include #include -#ifdef _WIN32 -# include -# include -# define pcl_open _open -# define pcl_close(fd) _close(fd) -# define pcl_lseek(fd,offset,origin) _lseek(fd,offset,origin) -#else -# include -# define pcl_open open -# define pcl_close(fd) close(fd) -# define pcl_lseek(fd,offset,origin) lseek(fd,offset,origin) -#endif #include /////////////////////////////////////////////////////////////////////////////////////////// @@ -750,7 +739,7 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, /// We must re-open the file and read with mmap () for binary { // Open for reading - int fd = pcl_open (file_name.c_str (), O_RDONLY); + int fd = io::raw_open (file_name.c_str (), O_RDONLY); if (fd == -1) { PCL_ERROR ("[pcl::PCDReader::read] Failure to open file %s\n", file_name.c_str () ); @@ -758,17 +747,17 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, } // Infer file size - const size_t file_size = pcl_lseek (fd, 0, SEEK_END); - pcl_lseek (fd, 0, SEEK_SET); + const size_t file_size = io::raw_lseek (fd, 0, SEEK_END); + io::raw_lseek (fd, 0, SEEK_SET); size_t mmap_size = offset + data_idx; // ...because we mmap from the start of the file. if (data_type == 2) { // Seek to real start of data. - off_t result = pcl_lseek (fd, offset + data_idx, SEEK_SET); + long result = io::raw_lseek (fd, offset + data_idx, SEEK_SET); if (result < 0) { - pcl_close (fd); + io::raw_close (fd); PCL_ERROR ("[pcl::PCDReader::read] lseek errno: %d strerror: %s\n", errno, strerror (errno)); PCL_ERROR ("[pcl::PCDReader::read] Error during lseek ()!\n"); return (-1); @@ -776,10 +765,10 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, // Read compressed size to compute how much must be mapped unsigned int compressed_size = 0; - ssize_t num_read = pcl_read (fd, &compressed_size, 4); + ssize_t num_read = io::raw_read (fd, &compressed_size, 4); if (num_read < 0) { - pcl_close (fd); + io::raw_close (fd); PCL_ERROR ("[pcl::PCDReader::read] read errno: %d strerror: %s\n", errno, strerror (errno)); PCL_ERROR ("[pcl::PCDReader::read] Error during read()!\n"); return (-1); @@ -789,7 +778,7 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, mmap_size += 8; // Reset position - pcl_lseek (fd, 0, SEEK_SET); + io::raw_lseek (fd, 0, SEEK_SET); } else { @@ -798,7 +787,7 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, if (mmap_size > file_size) { - pcl_close (fd); + io::raw_close (fd); PCL_ERROR ("[pcl::PCDReader::read] Corrupted PCD file. The file is smaller than expected!\n"); return (-1); } @@ -814,15 +803,15 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, if (map == NULL) { CloseHandle (fm); - pcl_close (fd); + io::raw_close (fd); PCL_ERROR ("[pcl::PCDReader::read] Error mapping view of file, %s\n", file_name.c_str ()); return (-1); } #else - unsigned char *map = static_cast (mmap (0, mmap_size, PROT_READ, MAP_SHARED, fd, 0)); + unsigned char *map = static_cast (::mmap (0, mmap_size, PROT_READ, MAP_SHARED, fd, 0)); if (map == reinterpret_cast (-1)) // MAP_FAILED { - pcl_close (fd); + io::raw_close (fd); PCL_ERROR ("[pcl::PCDReader::read] Error preparing mmap for binary PCD file.\n"); return (-1); } @@ -835,14 +824,14 @@ pcl::PCDReader::read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, UnmapViewOfFile (map); CloseHandle (fm); #else - if (munmap (map, mmap_size) == -1) + if (::munmap (map, mmap_size) == -1) { - pcl_close (fd); + io::raw_close (fd); PCL_ERROR ("[pcl::PCDReader::read] Munmap failure\n"); return (-1); } #endif - pcl_close (fd); + io::raw_close (fd); } double total_time = tt.toc (); PCL_DEBUG ("[pcl::PCDReader::read] Loaded %s as a %s cloud in %g ms with %d points. Available dimensions: %s.\n", @@ -1272,7 +1261,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, const pcl::PCLPointCl setLockingPermissions (file_name, file_lock); #else - int fd = pcl_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int fd = io::raw_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { PCL_ERROR ("[pcl::PCDWriter::writeBinary] Error during open (%s)!\n", file_name.c_str()); @@ -1283,10 +1272,10 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, const pcl::PCLPointCl setLockingPermissions (file_name, file_lock); // Stretch the file size to the size of the data - off_t result = pcl_lseek (fd, getpagesize () + cloud.data.size () - 1, SEEK_SET); + long result = io::raw_lseek (fd, getpagesize () + cloud.data.size () - 1, SEEK_SET); if (result < 0) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinary] lseek errno: %d strerror: %s\n", errno, strerror (errno)); PCL_ERROR ("[pcl::PCDWriter::writeBinary] Error during lseek ()!\n"); @@ -1296,7 +1285,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, const pcl::PCLPointCl result = static_cast (::write (fd, "", 1)); if (result != 1) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinary] Error during write ()!\n"); return (-1); @@ -1312,7 +1301,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, const pcl::PCLPointCl char *map = static_cast (mmap (0, static_cast (data_idx + cloud.data.size ()), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); if (map == reinterpret_cast (-1)) // MAP_FAILED { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinary] Error during mmap ()!\n"); return (-1); @@ -1335,9 +1324,9 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, const pcl::PCLPointCl #ifdef _WIN32 UnmapViewOfFile (map); #else - if (munmap (map, static_cast (data_idx + cloud.data.size ())) == -1) + if (::munmap (map, static_cast (data_idx + cloud.data.size ())) == -1) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinary] Error during munmap ()!\n"); return (-1); @@ -1347,7 +1336,7 @@ pcl::PCDWriter::writeBinary (const std::string &file_name, const pcl::PCLPointCl #ifdef _WIN32 CloseHandle(h_native_file); #else - pcl_close (fd); + io::raw_close (fd); #endif resetLockingPermissions (file_name, file_lock); return (0); @@ -1481,7 +1470,7 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, const pcl:: return (-1); } #else - int fd = pcl_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + int fd = io::raw_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] Error during open (%s)!\n", file_name.c_str ()); @@ -1497,10 +1486,10 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, const pcl:: size_t page_size = getpagesize (); size_t size_pages = ostr.size () / page_size; size_t partial_pages = (size_pages * page_size < ostr.size ()) ? 1 : 0; - off_t result = pcl_lseek (fd, (size_pages + partial_pages) * page_size - 1, SEEK_SET); + long result = io::raw_lseek (fd, (size_pages + partial_pages) * page_size - 1, SEEK_SET); if (result < 0) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] lseek errno: %d strerror: %s\n", errno, strerror (errno)); PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] Error during lseek ()!\n"); @@ -1510,7 +1499,7 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, const pcl:: result = static_cast (::write (fd, "", 1)); if (result != 1) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] Error during write ()!\n"); return (-1); @@ -1524,10 +1513,10 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, const pcl:: CloseHandle (fm); #else - char *map = static_cast (mmap (0, ostr.size (), PROT_WRITE, MAP_SHARED, fd, 0)); + char *map = static_cast (::mmap (0, ostr.size (), PROT_WRITE, MAP_SHARED, fd, 0)); if (map == reinterpret_cast (-1)) // MAP_FAILED { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] Error during mmap ()!\n"); return (-1); @@ -1547,9 +1536,9 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, const pcl:: #ifdef _WIN32 UnmapViewOfFile (map); #else - if (munmap (map, ostr.size ()) == -1) + if (::munmap (map, ostr.size ()) == -1) { - pcl_close (fd); + io::raw_close (fd); resetLockingPermissions (file_name, file_lock); PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] Error during munmap ()!\n"); return (-1); @@ -1559,7 +1548,7 @@ pcl::PCDWriter::writeBinaryCompressed (const std::string &file_name, const pcl:: #ifdef _WIN32 CloseHandle (h_native_file); #else - pcl_close (fd); + io::raw_close (fd); #endif resetLockingPermissions (file_name, file_lock);