diff options
author | lloyd <[email protected]> | 2007-12-24 20:54:30 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2007-12-24 20:54:30 +0000 |
commit | 769e503fd8e4cf0f3072e04afffb61db5b48d777 (patch) | |
tree | b5d5c5e88bcfa0c3790571c82cde222bec1addb3 | |
parent | cf2f188f4ad96abb26400e2dc62e2012826d10e7 (diff) |
Qualify (some) calls to functions in the global namespace using an
explicit :: (it is unfortunate that there is no good way to detect all
of such calls in an automated manner). Also use new-style casts in parts
of the zlib code.
-rw-r--r-- | modules/alloc_mmap/mmap_mem.cpp | 38 | ||||
-rw-r--r-- | modules/comp_zlib/zlib.cpp | 16 | ||||
-rw-r--r-- | modules/es_dev/es_dev.cpp | 4 | ||||
-rw-r--r-- | modules/es_egd/es_egd.cpp | 14 | ||||
-rw-r--r-- | modules/es_ftw/es_ftw.cpp | 18 | ||||
-rw-r--r-- | modules/es_unix/es_unix.cpp | 26 | ||||
-rw-r--r-- | modules/es_unix/unix_cmd.cpp | 34 | ||||
-rw-r--r-- | modules/tm_posix/tm_posix.cpp | 4 | ||||
-rw-r--r-- | modules/tm_unix/tm_unix.cpp | 4 |
9 files changed, 78 insertions, 80 deletions
diff --git a/modules/alloc_mmap/mmap_mem.cpp b/modules/alloc_mmap/mmap_mem.cpp index 2ca73b4b7..b40d24ca0 100644 --- a/modules/alloc_mmap/mmap_mem.cpp +++ b/modules/alloc_mmap/mmap_mem.cpp @@ -59,15 +59,15 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n) filepath = new char[path.length() + 1]; std::strcpy(filepath, path.c_str()); - mode_t old_umask = umask(077); - fd = mkstemp(filepath); - umask(old_umask); + mode_t old_umask = ::umask(077); + fd = ::mkstemp(filepath); + ::umask(old_umask); } ~TemporaryFile() { delete[] filepath; - if(fd != -1 && close(fd) == -1) + if(fd != -1 && ::close(fd) == -1) throw MemoryMapping_Failed("Could not close file"); } private: @@ -80,15 +80,15 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n) if(file.get_fd() == -1) throw MemoryMapping_Failed("Could not create file"); - if(unlink(file.path().c_str())) - throw MemoryMapping_Failed("Could not unlink file " + file.path()); + if(::unlink(file.path().c_str())) + throw MemoryMapping_Failed("Could not unlink file '" + file.path() + "'"); - lseek(file.get_fd(), n-1, SEEK_SET); - if(write(file.get_fd(), "\0", 1) != 1) + ::lseek(file.get_fd(), n-1, SEEK_SET); + if(::write(file.get_fd(), "\0", 1) != 1) throw MemoryMapping_Failed("Could not write to file"); - void* ptr = mmap(0, n, PROT_READ | PROT_WRITE, MAP_SHARED, - file.get_fd(), 0); + void* ptr = ::mmap(0, n, PROT_READ | PROT_WRITE, MAP_SHARED, + file.get_fd(), 0); if(ptr == static_cast<void*>(MAP_FAILED)) throw MemoryMapping_Failed("Could not map file"); @@ -101,23 +101,21 @@ void* MemoryMapping_Allocator::alloc_block(u32bit n) *************************************************/ void MemoryMapping_Allocator::dealloc_block(void* ptr, u32bit n) { - if(ptr == 0) return; + if(ptr == 0) + return; - const u32bit OVERWRITE_PASSES = 12; const byte PATTERNS[] = { 0x00, 0xFF, 0xAA, 0x55, 0x73, 0x8C, 0x5F, 0xA0, - 0x6E, 0x91, 0x30, 0xCF, 0xD3, 0x2C, 0xAC, 0x53 }; + 0x6E, 0x91, 0x30, 0xCF, 0xD3, 0x2C, 0xAC, 0x00 }; - for(u32bit j = 0; j != OVERWRITE_PASSES; j++) + for(u32bit j = 0; j != sizeof(PATTERNS); j++) { - std::memset(ptr, PATTERNS[j % sizeof(PATTERNS)], n); - if(msync(ptr, n, MS_SYNC)) + std::memset(ptr, PATTERNS[j], n); + + if(::msync(ptr, n, MS_SYNC)) throw MemoryMapping_Failed("Sync operation failed"); } - std::memset(ptr, 0, n); - if(msync(ptr, n, MS_SYNC)) - throw MemoryMapping_Failed("Sync operation failed"); - if(munmap(ptr, n)) + if(::munmap(ptr, n)) throw MemoryMapping_Failed("Could not unmap file"); } diff --git a/modules/comp_zlib/zlib.cpp b/modules/comp_zlib/zlib.cpp index 4bb014b69..59f8e88c4 100644 --- a/modules/comp_zlib/zlib.cpp +++ b/modules/comp_zlib/zlib.cpp @@ -97,12 +97,12 @@ void Zlib_Compression::start_msg() *************************************************/ void Zlib_Compression::write(const byte input[], u32bit length) { - zlib->stream.next_in = (Bytef*)input; + zlib->stream.next_in = static_cast<Bytef*>(input); zlib->stream.avail_in = length; while(zlib->stream.avail_in != 0) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin()); zlib->stream.avail_out = buffer.size(); deflate(&(zlib->stream), Z_NO_FLUSH); send(buffer.begin(), buffer.size() - zlib->stream.avail_out); @@ -120,7 +120,7 @@ void Zlib_Compression::end_msg() int rc = Z_OK; while(rc != Z_STREAM_END) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin()); zlib->stream.avail_out = buffer.size(); rc = deflate(&(zlib->stream), Z_FINISH); send(buffer.begin(), buffer.size() - zlib->stream.avail_out); @@ -138,7 +138,7 @@ void Zlib_Compression::flush() while(true) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin()); zlib->stream.avail_out = buffer.size(); deflate(&(zlib->stream), Z_FULL_FLUSH); send(buffer.begin(), buffer.size() - zlib->stream.avail_out); @@ -188,12 +188,12 @@ void Zlib_Decompression::write(const byte input[], u32bit length) { if(length) no_writes = false; - zlib->stream.next_in = (Bytef*)input; + zlib->stream.next_in = static_cast<Bytef*>(input; zlib->stream.avail_in = length; while(zlib->stream.avail_in != 0) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin(); zlib->stream.avail_out = buffer.size(); int rc = inflate(&(zlib->stream), Z_SYNC_FLUSH); @@ -213,7 +213,7 @@ void Zlib_Decompression::write(const byte input[], u32bit length) { u32bit read_from_block = length - zlib->stream.avail_in; start_msg(); - zlib->stream.next_in = (Bytef*)input + read_from_block; + zlib->stream.next_in = static_cast<Bytef*>(input + read_from_block; zlib->stream.avail_in = length - read_from_block; input += read_from_block; length -= read_from_block; @@ -233,7 +233,7 @@ void Zlib_Decompression::end_msg() int rc = Z_OK; while(rc != Z_STREAM_END) { - zlib->stream.next_out = (Bytef*)buffer.begin(); + zlib->stream.next_out = static_cast<Bytef*>(buffer.begin(); zlib->stream.avail_out = buffer.size(); rc = inflate(&(zlib->stream), Z_SYNC_FLUSH); if(rc != Z_OK && rc != Z_STREAM_END) diff --git a/modules/es_dev/es_dev.cpp b/modules/es_dev/es_dev.cpp index 7a61a48af..61127388a 100644 --- a/modules/es_dev/es_dev.cpp +++ b/modules/es_dev/es_dev.cpp @@ -24,7 +24,7 @@ class Device_Reader typedef int fd_type; Device_Reader(fd_type device_fd) : fd(device_fd) {} - ~Device_Reader() { close(fd); } + ~Device_Reader() { ::close(fd); } u32bit get(byte out[], u32bit length); static fd_type open(const std::string& pathname); @@ -49,7 +49,7 @@ u32bit Device_Reader::get(byte out[], u32bit length) FD_ZERO(&read_set); FD_SET(fd, &read_set); - struct timeval timeout; + struct ::timeval timeout; timeout.tv_sec = 0; timeout.tv_usec = READ_WAIT_MS * 1000; diff --git a/modules/es_egd/es_egd.cpp b/modules/es_egd/es_egd.cpp index 2c377b387..2fbd03598 100644 --- a/modules/es_egd/es_egd.cpp +++ b/modules/es_egd/es_egd.cpp @@ -52,25 +52,25 @@ u32bit EGD_EntropySource::do_poll(byte output[], u32bit length, throw Exception("EGD_EntropySource: Socket path is too long"); std::strcpy(addr.sun_path, path.c_str()); - int fd = socket(addr.sun_family, SOCK_STREAM, 0); + int fd = ::socket(addr.sun_family, SOCK_STREAM, 0); if(fd == -1) return 0; int len = sizeof(addr.sun_family) + std::strlen(addr.sun_path) + 1; - if(connect(fd, reinterpret_cast<struct sockaddr*>(&addr), len)) - { close(fd); return 0; } + if(::connect(fd, reinterpret_cast<struct ::sockaddr*>(&addr), len)) + { ::close(fd); return 0; } byte buffer[2]; buffer[0] = 1; buffer[1] = static_cast<byte>(length); - if(write(fd, buffer, 2) != 2) { close(fd); return 0; } - if(read(fd, buffer, 1) != 1) { close(fd); return 0; } + if(::write(fd, buffer, 2) != 2) { ::close(fd); return 0; } + if(::read(fd, buffer, 1) != 1) { ::close(fd); return 0; } - ssize_t count = read(fd, output, buffer[0]); + ssize_t count = ::read(fd, output, buffer[0]); if(count == -1) { close(fd); return 0; } - close(fd); + ::close(fd); return count; } diff --git a/modules/es_ftw/es_ftw.cpp b/modules/es_ftw/es_ftw.cpp index 412a95f57..63531eb53 100644 --- a/modules/es_ftw/es_ftw.cpp +++ b/modules/es_ftw/es_ftw.cpp @@ -56,32 +56,32 @@ void FTW_EntropySource::gather_from_dir(const std::string& dirname) if(dirname == "" || files_read >= max_read) return; - DIR* dir = opendir(dirname.c_str()); + DIR* dir = ::opendir(dirname.c_str()); if(dir == 0) return; std::vector<std::string> subdirs; - dirent* entry = readdir(dir); + dirent* entry = ::readdir(dir); while(entry && (files_read < max_read)) { if((std::strcmp(entry->d_name, ".") == 0) || (std::strcmp(entry->d_name, "..") == 0)) - { entry = readdir(dir); continue; } + { entry = ::readdir(dir); continue; } const std::string filename = dirname + '/' + entry->d_name; - struct stat stat_buf; - if(lstat(filename.c_str(), &stat_buf) == -1) - { entry = readdir(dir); continue; } + struct ::stat stat_buf; + if(::lstat(filename.c_str(), &stat_buf) == -1) + { entry = ::readdir(dir); continue; } if(S_ISREG(stat_buf.st_mode)) gather_from_file(filename); else if(S_ISDIR(stat_buf.st_mode)) subdirs.push_back(filename); - entry = readdir(dir); + entry = ::readdir(dir); } - closedir(dir); + ::closedir(dir); for(u32bit j = 0; j != subdirs.size(); j++) gather_from_dir(subdirs[j]); @@ -98,7 +98,7 @@ void FTW_EntropySource::gather_from_file(const std::string& filename) SecureVector<byte> read_buf(1024); ssize_t got = ::read(fd, read_buf.begin(), read_buf.size()); - close(fd); + ::close(fd); if(got > 0) { diff --git a/modules/es_unix/es_unix.cpp b/modules/es_unix/es_unix.cpp index d534db2ab..40be78e22 100644 --- a/modules/es_unix/es_unix.cpp +++ b/modules/es_unix/es_unix.cpp @@ -51,30 +51,30 @@ void Unix_EntropySource::do_fast_poll() for(u32bit j = 0; STAT_TARGETS[j]; j++) { - struct stat statbuf; + struct ::stat statbuf; clear_mem(&statbuf, 1); - stat(STAT_TARGETS[j], &statbuf); + ::stat(STAT_TARGETS[j], &statbuf); add_bytes(&statbuf, sizeof(statbuf)); } - add_bytes(getpid()); - add_bytes(getppid()); + add_bytes(::getpid()); + add_bytes(::getppid()); - add_bytes(getuid()); - add_bytes(getgid()); - add_bytes(geteuid()); - add_bytes(getegid()); + add_bytes(::getuid()); + add_bytes(::getgid()); + add_bytes(::geteuid()); + add_bytes(::getegid()); - add_bytes(getpgrp()); - add_bytes(getsid(0)); + add_bytes(::getpgrp()); + add_bytes(::getsid(0)); - struct rusage usage; + struct ::rusage usage; clear_mem(&usage, 1); - getrusage(RUSAGE_SELF, &usage); + ::getrusage(RUSAGE_SELF, &usage); add_bytes(&usage, sizeof(usage)); - getrusage(RUSAGE_CHILDREN, &usage); + ::getrusage(RUSAGE_CHILDREN, &usage); add_bytes(&usage, sizeof(usage)); } diff --git a/modules/es_unix/unix_cmd.cpp b/modules/es_unix/unix_cmd.cpp index dbefc7e3e..65def8c74 100644 --- a/modules/es_unix/unix_cmd.cpp +++ b/modules/es_unix/unix_cmd.cpp @@ -41,7 +41,7 @@ void do_exec(const std::vector<std::string>& arg_list, { const std::string full_path = paths[j] + "/" + arg_list[0]; const char* fsname = full_path.c_str(); - execl(fsname, fsname, arg1, arg2, arg3, arg4, 0); + ::execl(fsname, fsname, arg1, arg2, arg3, arg4, 0); } } @@ -69,12 +69,12 @@ u32bit DataSource_Command::read(byte buf[], u32bit length) FD_ZERO(&set); FD_SET(pipe->fd, &set); - struct timeval tv; + struct ::timeval tv; tv.tv_sec = 0; tv.tv_usec = MAX_BLOCK_USECS; ssize_t got = 0; - if(select(pipe->fd + 1, &set, 0, 0, &tv) == 1) + if(::select(pipe->fd + 1, &set, 0, 0, &tv) == 1) { if(FD_ISSET(pipe->fd, &set)) got = ::read(pipe->fd, buf, length); @@ -136,7 +136,7 @@ void DataSource_Command::create_pipe(const std::string& path) for(u32bit j = 0; j != paths.size(); j++) { const std::string full_path = paths[j] + "/" + arg_list[0]; - if(access(full_path.c_str(), X_OK) == 0) + if(::access(full_path.c_str(), X_OK) == 0) { found_something = true; break; @@ -149,31 +149,31 @@ void DataSource_Command::create_pipe(const std::string& path) if(::pipe(pipe_fd) != 0) return; - pid_t pid = fork(); + pid_t pid = ::fork(); if(pid == -1) { - close(pipe_fd[0]); - close(pipe_fd[1]); + ::close(pipe_fd[0]); + ::close(pipe_fd[1]); } else if(pid > 0) { pipe = new pipe_wrapper; pipe->fd = pipe_fd[0]; pipe->pid = pid; - close(pipe_fd[1]); + ::close(pipe_fd[1]); } else { if(dup2(pipe_fd[1], STDOUT_FILENO) == -1) - exit(127); + ::exit(127); if(close(pipe_fd[0]) != 0 || close(pipe_fd[1]) != 0) - exit(127); + ::exit(127); if(close(STDERR_FILENO) != 0) - exit(127); + ::exit(127); do_exec(arg_list, paths); - exit(127); + ::exit(127); } } @@ -190,23 +190,23 @@ void DataSource_Command::shutdown_pipe() { kill(pipe->pid, SIGTERM); - struct timeval tv; + struct ::timeval tv; tv.tv_sec = 0; tv.tv_usec = KILL_WAIT; select(0, 0, 0, 0, &tv); - reaped = waitpid(pipe->pid, 0, WNOHANG); + reaped = ::waitpid(pipe->pid, 0, WNOHANG); if(reaped == 0) { - kill(pipe->pid, SIGKILL); + ::kill(pipe->pid, SIGKILL); do - reaped = waitpid(pipe->pid, 0, 0); + reaped = ::waitpid(pipe->pid, 0, 0); while(reaped == -1); } } - close(pipe->fd); + ::close(pipe->fd); delete pipe; pipe = 0; } diff --git a/modules/tm_posix/tm_posix.cpp b/modules/tm_posix/tm_posix.cpp index 7a6b667c4..e5e1f3f93 100644 --- a/modules/tm_posix/tm_posix.cpp +++ b/modules/tm_posix/tm_posix.cpp @@ -23,8 +23,8 @@ namespace Botan { *************************************************/ u64bit POSIX_Timer::clock() const { - struct timespec tv; - clock_gettime(CLOCK_REALTIME, &tv); + struct ::timespec tv; + ::clock_gettime(CLOCK_REALTIME, &tv); return combine_timers(tv.tv_sec, tv.tv_nsec, 1000000000); } diff --git a/modules/tm_unix/tm_unix.cpp b/modules/tm_unix/tm_unix.cpp index cb9a8431f..51224a7d2 100644 --- a/modules/tm_unix/tm_unix.cpp +++ b/modules/tm_unix/tm_unix.cpp @@ -14,8 +14,8 @@ namespace Botan { *************************************************/ u64bit Unix_Timer::clock() const { - struct timeval tv; - gettimeofday(&tv, 0); + struct ::timeval tv; + ::gettimeofday(&tv, 0); return combine_timers(tv.tv_sec, tv.tv_usec, 1000000); } |