From 70900ef16d38f9ebbfb33f98df9f35fd06acdc4e Mon Sep 17 00:00:00 2001 From: Robin Rowe Date: Sun, 28 Oct 2018 22:36:18 -0700 Subject: [PATCH] Fixed poll.h *readerCount++ error reported by TankorSmash --- test/mman/mman_client.cpp | 16 ++-------------- test/mman/mman_server.cpp | 6 +----- unistd/more/shm_more.h | 24 ++++++++++++++++++++++++ unistd/poll.h | 8 ++++---- 4 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 unistd/more/shm_more.h diff --git a/test/mman/mman_client.cpp b/test/mman/mman_client.cpp index c1db5d6..6dca223 100644 --- a/test/mman/mman_client.cpp +++ b/test/mman/mman_client.cpp @@ -10,25 +10,13 @@ #include #include #include - -#ifndef _WIN32 -#define shm_close close -#define shm_flush(fd) - -int shm_size(int fd) -{ struct stat sb; - fstat(fd, &sb); - off_t length = sb.st_size; - return int(length); -} -#endif +#include int main(int argc, char **argv) { int oflags=O_RDWR; - int i; char *name = "/mmanjunk"; int fd = shm_open(name, oflags, 0644 ); - fprintf(stderr,"Shared Mem Descriptor: fd=%d\n", fd); + printf("Shared Mem Descriptor: fd=%d\n", fd); assert (fd>0); size_t length = shm_size(fd); char* p = (char *) mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); diff --git a/test/mman/mman_server.cpp b/test/mman/mman_server.cpp index cc34b3d..bf7fc83 100644 --- a/test/mman/mman_server.cpp +++ b/test/mman/mman_server.cpp @@ -10,11 +10,7 @@ #include #include #include - -#ifndef _WIN32 -#define shm_close close -#define shm_ftruncate ftruncate -#endif +#include int main(int argc, char **argv) { int oflags=O_RDWR; diff --git a/unistd/more/shm_more.h b/unistd/more/shm_more.h new file mode 100644 index 0000000..16c1e36 --- /dev/null +++ b/unistd/more/shm_more.h @@ -0,0 +1,24 @@ +// unistd/more/shm_more.h +// 2018/10/28 Robin.Rowe@CinePaint.org + +#ifndef shm_more_h +#define shm_more_h + +#ifndef _WIN32 + +#include +#include + +#define shm_close close +#define shm_ftruncate ftruncate +#define shm_flush(fd) + +int shm_size(int fd) +{ struct stat sb; + fstat(fd, &sb); + off_t length = sb.st_size; + return int(length); +} +#endif + +#endif diff --git a/unistd/poll.h b/unistd/poll.h index 9ee39a4..0dc9551 100644 --- a/unistd/poll.h +++ b/unistd/poll.h @@ -26,21 +26,21 @@ int poll(struct pollfd *fds, nfds_t nfds, int mille_timeout) if(!fd) { return -1; } - u_int* readerCount=&fd[0].fd_count; + u_int* const readerCount=&fd[0].fd_count; *readerCount=0; SOCKET* fdReader=fd[0].fd_array; int writer=nfds; - u_int* writerCount=&fd[nfds].fd_count; + u_int* const writerCount=&fd[nfds].fd_count; *writerCount=0; SOCKET* fdWriter=fd[nfds].fd_array; for(int i=0;i