From fff15361e37f008667bf7c45db6fdc99d89e2ef4 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Sat, 5 Nov 2011 17:50:23 +0000 Subject: [PATCH] Escape: ecrustified SVN revision: 64786 --- legacy/escape/src/lib/Escape.h | 3 +- legacy/escape/src/lib/escape_libgen.c | 9 +- legacy/escape/src/lib/escape_libgen.h | 3 - legacy/escape/src/lib/escape_mman.c | 62 ++++++------ legacy/escape/src/lib/escape_unistd.c | 139 +++++++++++++------------- legacy/escape/src/lib/escape_unistd.h | 22 ++-- legacy/escape/src/lib/sys/mman.h | 30 +++--- 7 files changed, 132 insertions(+), 136 deletions(-) diff --git a/legacy/escape/src/lib/Escape.h b/legacy/escape/src/lib/Escape.h index 28b5fca7fe..ca728b50b7 100644 --- a/legacy/escape/src/lib/Escape.h +++ b/legacy/escape/src/lib/Escape.h @@ -18,7 +18,6 @@ #undef CLOCK_PROCESS_CPUTIME_ID #endif - /** * @mainpage Escape * @image html e_big.png @@ -44,7 +43,7 @@ extern "C" { #endif - /* Nothing to see here */ +/* Nothing to see here */ #ifdef __cplusplus } diff --git a/legacy/escape/src/lib/escape_libgen.c b/legacy/escape/src/lib/escape_libgen.c index 1e63a363b6..796708978e 100644 --- a/legacy/escape/src/lib/escape_libgen.c +++ b/legacy/escape/src/lib/escape_libgen.c @@ -36,8 +36,8 @@ escape_basename(char *path) p2 = p1 + (length - 1); if (*p2 == '/') { - while (*p2 == '/') - p2--; + while (*p2 == '/') + p2--; } *(p2 + 1) = '\0'; @@ -74,8 +74,8 @@ escape_dirname(char *path) p2 = p1 + (length - 1); if (*p2 == '/') { - while (*p2 == '/') - p2--; + while (*p2 == '/') + p2--; } *(p2 + 1) = '\0'; @@ -87,3 +87,4 @@ escape_dirname(char *path) return _escape_dirname_buf; } + diff --git a/legacy/escape/src/lib/escape_libgen.h b/legacy/escape/src/lib/escape_libgen.h index 8bdde7c7e9..0c23a76821 100644 --- a/legacy/escape/src/lib/escape_libgen.h +++ b/legacy/escape/src/lib/escape_libgen.h @@ -1,7 +1,6 @@ #ifndef __ESCAPE_LIBGEN_H__ #define __ESCAPE_LIBGEN_H__ - /** * @file escape_libgen.h * @brief The file that provides functions ported from Unix in libgen.h. @@ -26,10 +25,8 @@ EAPI char *escape_dirname(char *path); #endif #define dirname(p) escape_dirname(p) - /** * @} */ - #endif /* __ESCAPE_LIBGEN_H__ */ diff --git a/legacy/escape/src/lib/escape_mman.c b/legacy/escape/src/lib/escape_mman.c index 7b52804328..995c72e7f4 100644 --- a/legacy/escape/src/lib/escape_mman.c +++ b/legacy/escape/src/lib/escape_mman.c @@ -11,7 +11,6 @@ /***** API *****/ - void * mmap(void *addr __UNUSED__, size_t len, @@ -20,48 +19,49 @@ mmap(void *addr __UNUSED__, int fd, off_t offset) { - void *data; - size_t size; + void *data; + size_t size; - data = malloc(len); - if (!data) - { - fprintf (stderr, "[Escape] [mmap] malloc failed\n"); - return MAP_FAILED; - } + data = malloc(len); + if (!data) + { + fprintf (stderr, "[Escape] [mmap] malloc failed\n"); + return MAP_FAILED; + } - size = read(fd, data, len); - if (size != len) - { - fprintf (stderr, "[Escape] [mmap] read failed\n"); - free(data); - return MAP_FAILED; - } + size = read(fd, data, len); + if (size != len) + { + fprintf (stderr, "[Escape] [mmap] read failed\n"); + free(data); + return MAP_FAILED; + } - if (lseek(fd, -len, SEEK_CUR) == -1) - { - fprintf (stderr, "[Escape] [mmap] lseek failed\n"); - free(data); - return MAP_FAILED; - } + if (lseek(fd, -len, SEEK_CUR) == -1) + { + fprintf (stderr, "[Escape] [mmap] lseek failed\n"); + free(data); + return MAP_FAILED; + } - return data; + return data; } int munmap(void *addr, size_t len __UNUSED__) { - if (addr && (addr != MAP_FAILED)) - free(addr); + if (addr && (addr != MAP_FAILED)) + free(addr); - return 0; + return 0; } - -int madvise(void *addr __UNUSED__, - size_t length __UNUSED__, - int advice __UNUSED__) +int +madvise(void *addr __UNUSED__, + size_t length __UNUSED__, + int advice __UNUSED__) { - return 0; + return 0; } + diff --git a/legacy/escape/src/lib/escape_unistd.c b/legacy/escape/src/lib/escape_unistd.c index d7106eceef..5dbbb18634 100644 --- a/legacy/escape/src/lib/escape_unistd.c +++ b/legacy/escape/src/lib/escape_unistd.c @@ -6,7 +6,7 @@ #include #endif /* HAVE_ERRNO_H */ -#include /* See NOTES */ +#include /* See NOTES */ #include #include #include @@ -16,75 +16,79 @@ #include #include - #include "Escape.h" -char *escape_realpath(const char *path, char *resolved_path) +char * +escape_realpath(const char *path, char *resolved_path) { - char *real = lrealpath (path); + char *real = lrealpath (path); - if (real) - { - if (resolved_path) - { - memcpy (resolved_path, real, PATH_MAX); - free (real); - return resolved_path; - } - else - { - return real; - } - } + if (real) + { + if (resolved_path) + { + memcpy (resolved_path, real, PATH_MAX); + free (real); + return resolved_path; + } + else + { + return real; + } + } - return NULL; + return NULL; } - - -int escape_access(const char *pathname, int mode) +int +escape_access(const char *pathname, int mode) { - struct stat stat_buf; + struct stat stat_buf; - if (stat(pathname, &stat_buf) != 0) - return -1; + if (stat(pathname, &stat_buf) != 0) + return -1; - if (mode == F_OK) - return 0; - if (mode == R_OK) { - if (stat_buf.st_mode & S_IRUSR) - return 0; - errno = EACCES; - return -1; - } - if (mode == W_OK) { - if (stat_buf.st_mode & S_IWUSR) - return 0; - errno = EROFS; - return -1; - } - if (mode == X_OK) { - if (stat_buf.st_mode & S_IXUSR) - return 0; - errno = EACCES; - return -1; - } + if (mode == F_OK) + return 0; + if (mode == R_OK) + { + if (stat_buf.st_mode & S_IRUSR) + return 0; + errno = EACCES; + return -1; + } + if (mode == W_OK) + { + if (stat_buf.st_mode & S_IWUSR) + return 0; + errno = EROFS; + return -1; + } + if (mode == X_OK) + { + if (stat_buf.st_mode & S_IXUSR) + return 0; + errno = EACCES; + return -1; + } - return 0; + return 0; } -EAPI ssize_t escape_readlink(const char *path, - char * buf, - size_t bufsize) +EAPI ssize_t +escape_readlink(const char *path, + char *buf, + size_t bufsize) { - errno = EINVAL; - return -1; + errno = EINVAL; + return -1; } -EAPI int escape_symlink(const char *path1, const char *path2) +EAPI int +escape_symlink(const char *path1, const char *path2) { - errno = EINVAL; - return -1; + errno = EINVAL; + return -1; } /* @@ -95,12 +99,12 @@ int escape_pipe(int *fds) { struct sockaddr_in saddr; - int temp; - int socket1 = -1; - int socket2 = -1; - fd_set read_set; - fd_set write_set; - int len; + int temp; + int socket1 = -1; + int socket2 = -1; + fd_set read_set; + fd_set write_set; + int len; temp = socket (AF_INET, SOCK_STREAM, 0); @@ -127,8 +131,7 @@ escape_pipe(int *fds) if (socket1 == -1) goto out0; - - if ((connect (socket1, (struct sockaddr *)&saddr, len) == -1) && + if ((connect (socket1, (struct sockaddr *)&saddr, len) == -1) && (errno != EAGAIN)) goto out1; @@ -141,7 +144,7 @@ escape_pipe(int *fds) if (!FD_ISSET (temp, &read_set)) goto out1; - socket2 = accept (temp, (struct sockaddr *) &saddr, &len); + socket2 = accept (temp, (struct sockaddr *)&saddr, &len); if (socket2 == -1) goto out1; @@ -161,11 +164,11 @@ escape_pipe(int *fds) return 0; - out2: +out2: closesocket (socket2); - out1: +out1: closesocket (socket1); - out0: +out0: closesocket (temp); fds[0] = -1; @@ -175,7 +178,9 @@ escape_pipe(int *fds) } #undef access -int access(const char *pathname, int mode) +int +access(const char *pathname, int mode) { - return escape_access (pathname, mode); + return escape_access (pathname, mode); } + diff --git a/legacy/escape/src/lib/escape_unistd.h b/legacy/escape/src/lib/escape_unistd.h index e18e623554..0e96d3f3cb 100644 --- a/legacy/escape/src/lib/escape_unistd.h +++ b/legacy/escape/src/lib/escape_unistd.h @@ -1,7 +1,6 @@ #ifndef __ESCAPE_UNISTD_H__ #define __ESCAPE_UNISTD_H__ - /** * @file escape_unistd.h * @brief The file that provides functions ported from Unix in unistd.h. @@ -14,7 +13,6 @@ #include - /* Path function */ /** * @brief return the canonicalized absolute pathname @@ -41,21 +39,22 @@ EAPI char *escape_realpath(const char *path, char *resolved_path); #endif #define realpath escape_realpath -EAPI ssize_t escape_readlink(const char * path, - char * buf, - size_t bufsize); +EAPI ssize_t +escape_readlink(const char *path, + char *buf, + size_t bufsize); #ifdef readlink #undef readlink #endif #define readlink escape_readlink -EAPI int escape_symlink(const char *path1, const char *path2); +EAPI int +escape_symlink(const char *path1, const char *path2); #ifdef symlink #undef symlink #endif #define symlink escape_symlink - /** * @brief check real user's permissions for a file * @@ -71,7 +70,8 @@ EAPI int escape_symlink(const char *path1, const char *path2); * and execute permissions, respectively. * */ -EAPI int escape_access(const char *pathname, int mode); +EAPI int +escape_access(const char *pathname, int mode); #ifdef access #undef access #endif @@ -88,7 +88,8 @@ EAPI int escape_access(const char *pathname, int mode); * * Conformity: Not applicable. */ -EAPI int escape_pipe(int *fds); +EAPI int +escape_pipe(int *fds); /** * @def pipe(fds) @@ -97,13 +98,10 @@ EAPI int escape_pipe(int *fds); */ #define pipe(fds) escape_pipe(fds) - //#define sync() - /** * @} */ - #endif /* __ESCAPE_UNISTD_H__ */ diff --git a/legacy/escape/src/lib/sys/mman.h b/legacy/escape/src/lib/sys/mman.h index e60bb45d4b..98ef7fa5fc 100644 --- a/legacy/escape/src/lib/sys/mman.h +++ b/legacy/escape/src/lib/sys/mman.h @@ -3,12 +3,10 @@ #include - #ifdef __cplusplus extern "C" { #endif - /** * @def PROT_NONE * Data can not be accessed. @@ -58,8 +56,7 @@ extern "C" { #define MAP_PRIVATE 0x0002 #define MAP_FIXED 0x0010 -#define MAP_FAILED ((void *)-1) - +#define MAP_FAILED ((void *)-1) /** * @file mman.h @@ -106,12 +103,12 @@ extern "C" { * * @ingroup Mman */ -EAPI void *mmap(void *addr, +EAPI void *mmap(void *addr, size_t len, - int prot, - int flags, - int fd, - off_t offset); + int prot, + int flags, + int fd, + off_t offset); /** * Unmaps a mapped view of a file from the calling process's @@ -130,9 +127,9 @@ EAPI void *mmap(void *addr, * * @ingroup Mman */ -EAPI int munmap(void *addr, - size_t len); - +EAPI int +munmap(void *addr, + size_t len); # define MADV_NORMAL 0 /* No further special treatment. */ # define MADV_RANDOM 1 /* Expect random page references. */ @@ -169,15 +166,14 @@ EAPI int munmap(void *addr, * * @ingroup Mman */ -EAPI int madvise(void *addr, - size_t length, - int advice); - +EAPI int +madvise(void *addr, + size_t length, + int advice); #ifdef __cplusplus } #endif - #endif /* __ESCAPE_SYS_MMAN_H__ */