summaryrefslogtreecommitdiff
path: root/legacy/escape
diff options
context:
space:
mode:
authorYouness Alaoui <kakaroto@kakaroto.homelinux.net>2011-11-05 17:50:23 +0000
committerYouness Alaoui <kakaroto@kakaroto.homelinux.net>2011-11-05 17:50:23 +0000
commitfff15361e37f008667bf7c45db6fdc99d89e2ef4 (patch)
tree07094e1c4faf63a8c5c288aaf268be9238692436 /legacy/escape
parentaeb68dfc9289657071bef0e4d6e298b358bde91f (diff)
Escape: ecrustified
SVN revision: 64786
Diffstat (limited to 'legacy/escape')
-rw-r--r--legacy/escape/src/lib/Escape.h3
-rw-r--r--legacy/escape/src/lib/escape_libgen.c9
-rw-r--r--legacy/escape/src/lib/escape_libgen.h3
-rw-r--r--legacy/escape/src/lib/escape_mman.c62
-rw-r--r--legacy/escape/src/lib/escape_unistd.c149
-rw-r--r--legacy/escape/src/lib/escape_unistd.h22
-rw-r--r--legacy/escape/src/lib/sys/mman.h30
7 files changed, 137 insertions, 141 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 @@
18#undef CLOCK_PROCESS_CPUTIME_ID 18#undef CLOCK_PROCESS_CPUTIME_ID
19#endif 19#endif
20 20
21
22/** 21/**
23 * @mainpage Escape 22 * @mainpage Escape
24 * @image html e_big.png 23 * @image html e_big.png
@@ -44,7 +43,7 @@
44extern "C" { 43extern "C" {
45#endif 44#endif
46 45
47 /* Nothing to see here */ 46/* Nothing to see here */
48 47
49#ifdef __cplusplus 48#ifdef __cplusplus
50} 49}
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)
36 p2 = p1 + (length - 1); 36 p2 = p1 + (length - 1);
37 if (*p2 == '/') 37 if (*p2 == '/')
38 { 38 {
39 while (*p2 == '/') 39 while (*p2 == '/')
40 p2--; 40 p2--;
41 } 41 }
42 *(p2 + 1) = '\0'; 42 *(p2 + 1) = '\0';
43 43
@@ -74,8 +74,8 @@ escape_dirname(char *path)
74 p2 = p1 + (length - 1); 74 p2 = p1 + (length - 1);
75 if (*p2 == '/') 75 if (*p2 == '/')
76 { 76 {
77 while (*p2 == '/') 77 while (*p2 == '/')
78 p2--; 78 p2--;
79 } 79 }
80 *(p2 + 1) = '\0'; 80 *(p2 + 1) = '\0';
81 81
@@ -87,3 +87,4 @@ escape_dirname(char *path)
87 87
88 return _escape_dirname_buf; 88 return _escape_dirname_buf;
89} 89}
90
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 @@
1#ifndef __ESCAPE_LIBGEN_H__ 1#ifndef __ESCAPE_LIBGEN_H__
2#define __ESCAPE_LIBGEN_H__ 2#define __ESCAPE_LIBGEN_H__
3 3
4
5/** 4/**
6 * @file escape_libgen.h 5 * @file escape_libgen.h
7 * @brief The file that provides functions ported from Unix in libgen.h. 6 * @brief The file that provides functions ported from Unix in libgen.h.
@@ -26,10 +25,8 @@ EAPI char *escape_dirname(char *path);
26#endif 25#endif
27#define dirname(p) escape_dirname(p) 26#define dirname(p) escape_dirname(p)
28 27
29
30/** 28/**
31 * @} 29 * @}
32 */ 30 */
33 31
34
35#endif /* __ESCAPE_LIBGEN_H__ */ 32#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 @@
11 11
12/***** API *****/ 12/***** API *****/
13 13
14
15void * 14void *
16mmap(void *addr __UNUSED__, 15mmap(void *addr __UNUSED__,
17 size_t len, 16 size_t len,
@@ -20,48 +19,49 @@ mmap(void *addr __UNUSED__,
20 int fd, 19 int fd,
21 off_t offset) 20 off_t offset)
22{ 21{
23 void *data; 22 void *data;
24 size_t size; 23 size_t size;
25 24
26 data = malloc(len); 25 data = malloc(len);
27 if (!data) 26 if (!data)
28 { 27 {
29 fprintf (stderr, "[Escape] [mmap] malloc failed\n"); 28 fprintf (stderr, "[Escape] [mmap] malloc failed\n");
30 return MAP_FAILED; 29 return MAP_FAILED;
31 } 30 }
32 31
33 size = read(fd, data, len); 32 size = read(fd, data, len);
34 if (size != len) 33 if (size != len)
35 { 34 {
36 fprintf (stderr, "[Escape] [mmap] read failed\n"); 35 fprintf (stderr, "[Escape] [mmap] read failed\n");
37 free(data); 36 free(data);
38 return MAP_FAILED; 37 return MAP_FAILED;
39 } 38 }
40 39
41 if (lseek(fd, -len, SEEK_CUR) == -1) 40 if (lseek(fd, -len, SEEK_CUR) == -1)
42 { 41 {
43 fprintf (stderr, "[Escape] [mmap] lseek failed\n"); 42 fprintf (stderr, "[Escape] [mmap] lseek failed\n");
44 free(data); 43 free(data);
45 return MAP_FAILED; 44 return MAP_FAILED;
46 } 45 }
47 46
48 return data; 47 return data;
49} 48}
50 49
51int 50int
52munmap(void *addr, 51munmap(void *addr,
53 size_t len __UNUSED__) 52 size_t len __UNUSED__)
54{ 53{
55 if (addr && (addr != MAP_FAILED)) 54 if (addr && (addr != MAP_FAILED))
56 free(addr); 55 free(addr);
57 56
58 return 0; 57 return 0;
59} 58}
60 59
61 60int
62int madvise(void *addr __UNUSED__, 61madvise(void *addr __UNUSED__,
63 size_t length __UNUSED__, 62 size_t length __UNUSED__,
64 int advice __UNUSED__) 63 int advice __UNUSED__)
65{ 64{
66 return 0; 65 return 0;
67} 66}
67
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 @@
6#include <errno.h> 6#include <errno.h>
7#endif /* HAVE_ERRNO_H */ 7#endif /* HAVE_ERRNO_H */
8 8
9#include <sys/types.h> /* See NOTES */ 9#include <sys/types.h> /* See NOTES */
10#include <sys/socket.h> 10#include <sys/socket.h>
11#include <net/socket.h> 11#include <net/socket.h>
12#include <netinet/in.h> 12#include <netinet/in.h>
@@ -16,75 +16,79 @@
16#include <libiberty.h> 16#include <libiberty.h>
17#include <sys/stat.h> 17#include <sys/stat.h>
18 18
19
20#include "Escape.h" 19#include "Escape.h"
21 20
22char *escape_realpath(const char *path, char *resolved_path) 21char *
22escape_realpath(const char *path, char *resolved_path)
23{ 23{
24 char *real = lrealpath (path); 24 char *real = lrealpath (path);
25 25
26 if (real) 26 if (real)
27 { 27 {
28 if (resolved_path) 28 if (resolved_path)
29 { 29 {
30 memcpy (resolved_path, real, PATH_MAX); 30 memcpy (resolved_path, real, PATH_MAX);
31 free (real); 31 free (real);
32 return resolved_path; 32 return resolved_path;
33 } 33 }
34 else 34 else
35 { 35 {
36 return real; 36 return real;
37 } 37 }
38 } 38 }
39 39
40 return NULL; 40 return NULL;
41} 41}
42 42
43 43int
44 44escape_access(const char *pathname, int mode)
45int escape_access(const char *pathname, int mode)
46{ 45{
47 struct stat stat_buf; 46 struct stat stat_buf;
48 47
49 if (stat(pathname, &stat_buf) != 0) 48 if (stat(pathname, &stat_buf) != 0)
50 return -1; 49 return -1;
51 50
52 if (mode == F_OK) 51 if (mode == F_OK)
53 return 0; 52 return 0;
54 if (mode == R_OK) { 53 if (mode == R_OK)
55 if (stat_buf.st_mode & S_IRUSR) 54 {
56 return 0; 55 if (stat_buf.st_mode & S_IRUSR)
57 errno = EACCES; 56 return 0;
58 return -1; 57 errno = EACCES;
59 } 58 return -1;
60 if (mode == W_OK) { 59 }
61 if (stat_buf.st_mode & S_IWUSR) 60 if (mode == W_OK)
62 return 0; 61 {
63 errno = EROFS; 62 if (stat_buf.st_mode & S_IWUSR)
64 return -1; 63 return 0;
65 } 64 errno = EROFS;
66 if (mode == X_OK) { 65 return -1;
67 if (stat_buf.st_mode & S_IXUSR) 66 }
68 return 0; 67 if (mode == X_OK)
69 errno = EACCES; 68 {
70 return -1; 69 if (stat_buf.st_mode & S_IXUSR)
71 } 70 return 0;
72 71 errno = EACCES;
73 return 0; 72 return -1;
73 }
74
75 return 0;
74} 76}
75 77
76EAPI ssize_t escape_readlink(const char *path, 78EAPI ssize_t
77 char * buf, 79escape_readlink(const char *path,
78 size_t bufsize) 80 char *buf,
81 size_t bufsize)
79{ 82{
80 errno = EINVAL; 83 errno = EINVAL;
81 return -1; 84 return -1;
82} 85}
83 86
84EAPI int escape_symlink(const char *path1, const char *path2) 87EAPI int
88escape_symlink(const char *path1, const char *path2)
85{ 89{
86 errno = EINVAL; 90 errno = EINVAL;
87 return -1; 91 return -1;
88} 92}
89 93
90/* 94/*
@@ -95,12 +99,12 @@ int
95escape_pipe(int *fds) 99escape_pipe(int *fds)
96{ 100{
97 struct sockaddr_in saddr; 101 struct sockaddr_in saddr;
98 int temp; 102 int temp;
99 int socket1 = -1; 103 int socket1 = -1;
100 int socket2 = -1; 104 int socket2 = -1;
101 fd_set read_set; 105 fd_set read_set;
102 fd_set write_set; 106 fd_set write_set;
103 int len; 107 int len;
104 108
105 temp = socket (AF_INET, SOCK_STREAM, 0); 109 temp = socket (AF_INET, SOCK_STREAM, 0);
106 110
@@ -127,8 +131,7 @@ escape_pipe(int *fds)
127 if (socket1 == -1) 131 if (socket1 == -1)
128 goto out0; 132 goto out0;
129 133
130 134 if ((connect (socket1, (struct sockaddr *)&saddr, len) == -1) &&
131 if ((connect (socket1, (struct sockaddr *)&saddr, len) == -1) &&
132 (errno != EAGAIN)) 135 (errno != EAGAIN))
133 goto out1; 136 goto out1;
134 137
@@ -141,7 +144,7 @@ escape_pipe(int *fds)
141 if (!FD_ISSET (temp, &read_set)) 144 if (!FD_ISSET (temp, &read_set))
142 goto out1; 145 goto out1;
143 146
144 socket2 = accept (temp, (struct sockaddr *) &saddr, &len); 147 socket2 = accept (temp, (struct sockaddr *)&saddr, &len);
145 if (socket2 == -1) 148 if (socket2 == -1)
146 goto out1; 149 goto out1;
147 150
@@ -161,11 +164,11 @@ escape_pipe(int *fds)
161 164
162 return 0; 165 return 0;
163 166
164 out2: 167out2:
165 closesocket (socket2); 168 closesocket (socket2);
166 out1: 169out1:
167 closesocket (socket1); 170 closesocket (socket1);
168 out0: 171out0:
169 closesocket (temp); 172 closesocket (temp);
170 173
171 fds[0] = -1; 174 fds[0] = -1;
@@ -175,7 +178,9 @@ escape_pipe(int *fds)
175} 178}
176 179
177#undef access 180#undef access
178int access(const char *pathname, int mode) 181int
182access(const char *pathname, int mode)
179{ 183{
180 return escape_access (pathname, mode); 184 return escape_access (pathname, mode);
181} 185}
186
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 @@
1#ifndef __ESCAPE_UNISTD_H__ 1#ifndef __ESCAPE_UNISTD_H__
2#define __ESCAPE_UNISTD_H__ 2#define __ESCAPE_UNISTD_H__
3 3
4
5/** 4/**
6 * @file escape_unistd.h 5 * @file escape_unistd.h
7 * @brief The file that provides functions ported from Unix in unistd.h. 6 * @brief The file that provides functions ported from Unix in unistd.h.
@@ -14,7 +13,6 @@
14 13
15#include <sys/syslimits.h> 14#include <sys/syslimits.h>
16 15
17
18/* Path function */ 16/* Path function */
19/** 17/**
20 * @brief return the canonicalized absolute pathname 18 * @brief return the canonicalized absolute pathname
@@ -41,21 +39,22 @@ EAPI char *escape_realpath(const char *path, char *resolved_path);
41#endif 39#endif
42#define realpath escape_realpath 40#define realpath escape_realpath
43 41
44EAPI ssize_t escape_readlink(const char * path, 42EAPI ssize_t
45 char * buf, 43escape_readlink(const char *path,
46 size_t bufsize); 44 char *buf,
45 size_t bufsize);
47#ifdef readlink 46#ifdef readlink
48#undef readlink 47#undef readlink
49#endif 48#endif
50#define readlink escape_readlink 49#define readlink escape_readlink
51 50
52EAPI int escape_symlink(const char *path1, const char *path2); 51EAPI int
52escape_symlink(const char *path1, const char *path2);
53#ifdef symlink 53#ifdef symlink
54#undef symlink 54#undef symlink
55#endif 55#endif
56#define symlink escape_symlink 56#define symlink escape_symlink
57 57
58
59/** 58/**
60 * @brief check real user's permissions for a file 59 * @brief check real user's permissions for a file
61 * 60 *
@@ -71,7 +70,8 @@ EAPI int escape_symlink(const char *path1, const char *path2);
71 * and execute permissions, respectively. 70 * and execute permissions, respectively.
72 * 71 *
73 */ 72 */
74EAPI int escape_access(const char *pathname, int mode); 73EAPI int
74escape_access(const char *pathname, int mode);
75#ifdef access 75#ifdef access
76#undef access 76#undef access
77#endif 77#endif
@@ -88,7 +88,8 @@ EAPI int escape_access(const char *pathname, int mode);
88 * 88 *
89 * Conformity: Not applicable. 89 * Conformity: Not applicable.
90 */ 90 */
91EAPI int escape_pipe(int *fds); 91EAPI int
92escape_pipe(int *fds);
92 93
93/** 94/**
94 * @def pipe(fds) 95 * @def pipe(fds)
@@ -97,13 +98,10 @@ EAPI int escape_pipe(int *fds);
97 */ 98 */
98#define pipe(fds) escape_pipe(fds) 99#define pipe(fds) escape_pipe(fds)
99 100
100
101//#define sync() 101//#define sync()
102 102
103
104/** 103/**
105 * @} 104 * @}
106 */ 105 */
107 106
108
109#endif /* __ESCAPE_UNISTD_H__ */ 107#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 @@
3 3
4#include <Escape.h> 4#include <Escape.h>
5 5
6
7#ifdef __cplusplus 6#ifdef __cplusplus
8extern "C" { 7extern "C" {
9#endif 8#endif
10 9
11
12/** 10/**
13 * @def PROT_NONE 11 * @def PROT_NONE
14 * Data can not be accessed. 12 * Data can not be accessed.
@@ -58,8 +56,7 @@ extern "C" {
58#define MAP_PRIVATE 0x0002 56#define MAP_PRIVATE 0x0002
59#define MAP_FIXED 0x0010 57#define MAP_FIXED 0x0010
60 58
61#define MAP_FAILED ((void *)-1) 59#define MAP_FAILED ((void *)-1)
62
63 60
64/** 61/**
65 * @file mman.h 62 * @file mman.h
@@ -106,12 +103,12 @@ extern "C" {
106 * 103 *
107 * @ingroup Mman 104 * @ingroup Mman
108 */ 105 */
109EAPI void *mmap(void *addr, 106EAPI void *mmap(void *addr,
110 size_t len, 107 size_t len,
111 int prot, 108 int prot,
112 int flags, 109 int flags,
113 int fd, 110 int fd,
114 off_t offset); 111 off_t offset);
115 112
116/** 113/**
117 * Unmaps a mapped view of a file from the calling process's 114 * Unmaps a mapped view of a file from the calling process's
@@ -130,9 +127,9 @@ EAPI void *mmap(void *addr,
130 * 127 *
131 * @ingroup Mman 128 * @ingroup Mman
132 */ 129 */
133EAPI int munmap(void *addr, 130EAPI int
134 size_t len); 131munmap(void *addr,
135 132 size_t len);
136 133
137# define MADV_NORMAL 0 /* No further special treatment. */ 134# define MADV_NORMAL 0 /* No further special treatment. */
138# define MADV_RANDOM 1 /* Expect random page references. */ 135# define MADV_RANDOM 1 /* Expect random page references. */
@@ -169,15 +166,14 @@ EAPI int munmap(void *addr,
169 * 166 *
170 * @ingroup Mman 167 * @ingroup Mman
171 */ 168 */
172EAPI int madvise(void *addr, 169EAPI int
173 size_t length, 170madvise(void *addr,
174 int advice); 171 size_t length,
175 172 int advice);
176 173
177#ifdef __cplusplus 174#ifdef __cplusplus
178} 175}
179#endif 176#endif
180 177
181
182#endif /* __ESCAPE_SYS_MMAN_H__ */ 178#endif /* __ESCAPE_SYS_MMAN_H__ */
183 179