parent
aeb68dfc92
commit
fff15361e3
|
@ -18,7 +18,6 @@
|
||||||
#undef CLOCK_PROCESS_CPUTIME_ID
|
#undef CLOCK_PROCESS_CPUTIME_ID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mainpage Escape
|
* @mainpage Escape
|
||||||
* @image html e_big.png
|
* @image html e_big.png
|
||||||
|
@ -44,7 +43,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Nothing to see here */
|
/* Nothing to see here */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,3 +87,4 @@ escape_dirname(char *path)
|
||||||
|
|
||||||
return _escape_dirname_buf;
|
return _escape_dirname_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef __ESCAPE_LIBGEN_H__
|
#ifndef __ESCAPE_LIBGEN_H__
|
||||||
#define __ESCAPE_LIBGEN_H__
|
#define __ESCAPE_LIBGEN_H__
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file escape_libgen.h
|
* @file escape_libgen.h
|
||||||
* @brief The file that provides functions ported from Unix in 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
|
#endif
|
||||||
#define dirname(p) escape_dirname(p)
|
#define dirname(p) escape_dirname(p)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#endif /* __ESCAPE_LIBGEN_H__ */
|
#endif /* __ESCAPE_LIBGEN_H__ */
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
/***** API *****/
|
/***** API *****/
|
||||||
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
mmap(void *addr __UNUSED__,
|
mmap(void *addr __UNUSED__,
|
||||||
size_t len,
|
size_t len,
|
||||||
|
@ -58,10 +57,11 @@ munmap(void *addr,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
int madvise(void *addr __UNUSED__,
|
madvise(void *addr __UNUSED__,
|
||||||
size_t length __UNUSED__,
|
size_t length __UNUSED__,
|
||||||
int advice __UNUSED__)
|
int advice __UNUSED__)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
#include <libiberty.h>
|
#include <libiberty.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Escape.h"
|
#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);
|
||||||
|
|
||||||
|
@ -40,9 +40,8 @@ char *escape_realpath(const char *path, char *resolved_path)
|
||||||
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;
|
||||||
|
|
||||||
|
@ -51,19 +50,22 @@ int escape_access(const char *pathname, int mode)
|
||||||
|
|
||||||
if (mode == F_OK)
|
if (mode == F_OK)
|
||||||
return 0;
|
return 0;
|
||||||
if (mode == R_OK) {
|
if (mode == R_OK)
|
||||||
|
{
|
||||||
if (stat_buf.st_mode & S_IRUSR)
|
if (stat_buf.st_mode & S_IRUSR)
|
||||||
return 0;
|
return 0;
|
||||||
errno = EACCES;
|
errno = EACCES;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (mode == W_OK) {
|
if (mode == W_OK)
|
||||||
|
{
|
||||||
if (stat_buf.st_mode & S_IWUSR)
|
if (stat_buf.st_mode & S_IWUSR)
|
||||||
return 0;
|
return 0;
|
||||||
errno = EROFS;
|
errno = EROFS;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (mode == X_OK) {
|
if (mode == X_OK)
|
||||||
|
{
|
||||||
if (stat_buf.st_mode & S_IXUSR)
|
if (stat_buf.st_mode & S_IXUSR)
|
||||||
return 0;
|
return 0;
|
||||||
errno = EACCES;
|
errno = EACCES;
|
||||||
|
@ -73,15 +75,17 @@ int escape_access(const char *pathname, int mode)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI ssize_t escape_readlink(const char *path,
|
EAPI ssize_t
|
||||||
char * buf,
|
escape_readlink(const char *path,
|
||||||
|
char *buf,
|
||||||
size_t bufsize)
|
size_t bufsize)
|
||||||
{
|
{
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI int escape_symlink(const char *path1, const char *path2)
|
EAPI int
|
||||||
|
escape_symlink(const char *path1, const char *path2)
|
||||||
{
|
{
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -127,7 +131,6 @@ escape_pipe(int *fds)
|
||||||
if (socket1 == -1)
|
if (socket1 == -1)
|
||||||
goto out0;
|
goto out0;
|
||||||
|
|
||||||
|
|
||||||
if ((connect (socket1, (struct sockaddr *)&saddr, len) == -1) &&
|
if ((connect (socket1, (struct sockaddr *)&saddr, len) == -1) &&
|
||||||
(errno != EAGAIN))
|
(errno != EAGAIN))
|
||||||
goto out1;
|
goto out1;
|
||||||
|
@ -141,7 +144,7 @@ escape_pipe(int *fds)
|
||||||
if (!FD_ISSET (temp, &read_set))
|
if (!FD_ISSET (temp, &read_set))
|
||||||
goto out1;
|
goto out1;
|
||||||
|
|
||||||
socket2 = accept (temp, (struct sockaddr *) &saddr, &len);
|
socket2 = accept (temp, (struct sockaddr *)&saddr, &len);
|
||||||
if (socket2 == -1)
|
if (socket2 == -1)
|
||||||
goto out1;
|
goto out1;
|
||||||
|
|
||||||
|
@ -161,11 +164,11 @@ escape_pipe(int *fds)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
out2:
|
out2:
|
||||||
closesocket (socket2);
|
closesocket (socket2);
|
||||||
out1:
|
out1:
|
||||||
closesocket (socket1);
|
closesocket (socket1);
|
||||||
out0:
|
out0:
|
||||||
closesocket (temp);
|
closesocket (temp);
|
||||||
|
|
||||||
fds[0] = -1;
|
fds[0] = -1;
|
||||||
|
@ -175,7 +178,9 @@ escape_pipe(int *fds)
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef access
|
#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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef __ESCAPE_UNISTD_H__
|
#ifndef __ESCAPE_UNISTD_H__
|
||||||
#define __ESCAPE_UNISTD_H__
|
#define __ESCAPE_UNISTD_H__
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file escape_unistd.h
|
* @file escape_unistd.h
|
||||||
* @brief The file that provides functions ported from Unix in unistd.h.
|
* @brief The file that provides functions ported from Unix in unistd.h.
|
||||||
|
@ -14,7 +13,6 @@
|
||||||
|
|
||||||
#include <sys/syslimits.h>
|
#include <sys/syslimits.h>
|
||||||
|
|
||||||
|
|
||||||
/* Path function */
|
/* Path function */
|
||||||
/**
|
/**
|
||||||
* @brief return the canonicalized absolute pathname
|
* @brief return the canonicalized absolute pathname
|
||||||
|
@ -41,21 +39,22 @@ EAPI char *escape_realpath(const char *path, char *resolved_path);
|
||||||
#endif
|
#endif
|
||||||
#define realpath escape_realpath
|
#define realpath escape_realpath
|
||||||
|
|
||||||
EAPI ssize_t escape_readlink(const char * path,
|
EAPI ssize_t
|
||||||
char * buf,
|
escape_readlink(const char *path,
|
||||||
|
char *buf,
|
||||||
size_t bufsize);
|
size_t bufsize);
|
||||||
#ifdef readlink
|
#ifdef readlink
|
||||||
#undef readlink
|
#undef readlink
|
||||||
#endif
|
#endif
|
||||||
#define readlink escape_readlink
|
#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
|
#ifdef symlink
|
||||||
#undef symlink
|
#undef symlink
|
||||||
#endif
|
#endif
|
||||||
#define symlink escape_symlink
|
#define symlink escape_symlink
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief check real user's permissions for a file
|
* @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.
|
* and execute permissions, respectively.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
EAPI int escape_access(const char *pathname, int mode);
|
EAPI int
|
||||||
|
escape_access(const char *pathname, int mode);
|
||||||
#ifdef access
|
#ifdef access
|
||||||
#undef access
|
#undef access
|
||||||
#endif
|
#endif
|
||||||
|
@ -88,7 +88,8 @@ EAPI int escape_access(const char *pathname, int mode);
|
||||||
*
|
*
|
||||||
* Conformity: Not applicable.
|
* Conformity: Not applicable.
|
||||||
*/
|
*/
|
||||||
EAPI int escape_pipe(int *fds);
|
EAPI int
|
||||||
|
escape_pipe(int *fds);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def pipe(fds)
|
* @def pipe(fds)
|
||||||
|
@ -97,13 +98,10 @@ EAPI int escape_pipe(int *fds);
|
||||||
*/
|
*/
|
||||||
#define pipe(fds) escape_pipe(fds)
|
#define pipe(fds) escape_pipe(fds)
|
||||||
|
|
||||||
|
|
||||||
//#define sync()
|
//#define sync()
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#endif /* __ESCAPE_UNISTD_H__ */
|
#endif /* __ESCAPE_UNISTD_H__ */
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
|
|
||||||
#include <Escape.h>
|
#include <Escape.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def PROT_NONE
|
* @def PROT_NONE
|
||||||
* Data can not be accessed.
|
* Data can not be accessed.
|
||||||
|
@ -60,7 +58,6 @@ extern "C" {
|
||||||
|
|
||||||
#define MAP_FAILED ((void *)-1)
|
#define MAP_FAILED ((void *)-1)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file mman.h
|
* @file mman.h
|
||||||
* @brief The file that provides the memory map functions
|
* @brief The file that provides the memory map functions
|
||||||
|
@ -130,10 +127,10 @@ EAPI void *mmap(void *addr,
|
||||||
*
|
*
|
||||||
* @ingroup Mman
|
* @ingroup Mman
|
||||||
*/
|
*/
|
||||||
EAPI int munmap(void *addr,
|
EAPI int
|
||||||
|
munmap(void *addr,
|
||||||
size_t len);
|
size_t len);
|
||||||
|
|
||||||
|
|
||||||
# define MADV_NORMAL 0 /* No further special treatment. */
|
# define MADV_NORMAL 0 /* No further special treatment. */
|
||||||
# define MADV_RANDOM 1 /* Expect random page references. */
|
# define MADV_RANDOM 1 /* Expect random page references. */
|
||||||
# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
|
# define MADV_SEQUENTIAL 2 /* Expect sequential page references. */
|
||||||
|
@ -169,15 +166,14 @@ EAPI int munmap(void *addr,
|
||||||
*
|
*
|
||||||
* @ingroup Mman
|
* @ingroup Mman
|
||||||
*/
|
*/
|
||||||
EAPI int madvise(void *addr,
|
EAPI int
|
||||||
|
madvise(void *addr,
|
||||||
size_t length,
|
size_t length,
|
||||||
int advice);
|
int advice);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* __ESCAPE_SYS_MMAN_H__ */
|
#endif /* __ESCAPE_SYS_MMAN_H__ */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue