update doc, add init/shutdown functions for the socket system, add Tor Lillqvist as author and other miscellaneous fixes

SVN revision: 33870
This commit is contained in:
doursse 2008-02-29 22:42:14 +00:00 committed by doursse
parent 08bfdacdee
commit 73cf6fe558
9 changed files with 323 additions and 88 deletions

View File

@ -1,3 +1,4 @@
Main Authors:
Vincent Torri <vtorri at univ-evry dot fr>
Tor Lillqvist <tml at iki dot fi>
ashikase

View File

@ -1,3 +1,25 @@
2008-02-29 Vincent Torri <doursse at users dot sf dot net>
* AUTHORS:
Add Tor Lillqvist as author as he kindly gave me
the right to use his code for pipe(). Thanks a lot !
* src/bin/test_dlfcn.c (main):
read module and symbol from command line
* src/bin/test_pipe.c (thread), (main):
change output
* src/lib/Evil.h:
* src/lib/dlfcn/dlfcn.h:
* src/lib/evil.c (mkstemp), (realpath), (evil_sockets_init),
(evil_sockets_shutdown):
* src/lib/mman/sys/mman.h:
update documentation, add unlink() function, realpath()
becomes a function instead of a macro, add functions to
init / shutdown the socket system of Windows, undef EAPI
at the end of each header files.
2008-02-27 Vincent Torri <doursse at users dot sf dot net>
* initial release

View File

@ -1,13 +1,19 @@
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
Foundation, Inc.
Installation Instructions
*************************
This file is free documentation; the Free Software Foundation gives
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006, 2007 Free Software Foundation, Inc.
This file is free documentation; the Free Software Foundation gives
unlimited permission to copy, distribute and modify it.
Basic Installation
==================
These are generic installation instructions.
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
@ -20,9 +26,9 @@ debugging `configure').
It can also use an optional file (typically called `config.cache'
and enabled with `--cache-file=config.cache' or simply `-C') that saves
the results of its tests to speed up reconfiguring. (Caching is
the results of its tests to speed up reconfiguring. Caching is
disabled by default to prevent problems with accidental use of stale
cache files.)
cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
@ -32,20 +38,17 @@ some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You only need
`configure.ac' if you want to change it or regenerate `configure' using
a newer version of `autoconf'.
`configure' by a program called `autoconf'. You need `configure.ac' if
you want to change it or regenerate `configure' using a newer version
of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
`./configure' to configure the package for your system. If you're
using `csh' on an old version of System V, you might need to type
`sh ./configure' instead to prevent `csh' from trying to execute
`configure' itself.
`./configure' to configure the package for your system.
Running `configure' takes awhile. While running, it prints some
messages telling which features it is checking for.
Running `configure' might take a while. While running, it prints
some messages telling which features it is checking for.
2. Type `make' to compile the package.
@ -64,54 +67,55 @@ The simplest way to compile this package is:
all sorts of other programs in order to regenerate files that came
with the distribution.
6. Often, you can also type `make uninstall' to remove the installed
files again.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
Some systems require unusual options for compilation or linking that the
`configure' script does not know about. Run `./configure --help' for
details on some of the pertinent environment variables.
You can give `configure' initial values for configuration parameters
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
./configure CC=c99 CFLAGS=-g LIBS=-lposix
*Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
own directory. To do this, you must use a version of `make' that
supports the `VPATH' variable, such as GNU `make'. `cd' to the
own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not support the `VPATH'
variable, you have to compile the package for one architecture at a
time in the source code directory. After you have installed the
package for one architecture, use `make distclean' before reconfiguring
for another architecture.
With a non-GNU `make', it is safer to compile the package for one
architecture at a time in the source code directory. After you have
installed the package for one architecture, use `make distclean' before
reconfiguring for another architecture.
Installation Names
==================
By default, `make install' will install the package's files in
`/usr/local/bin', `/usr/local/man', etc. You can specify an
installation prefix other than `/usr/local' by giving `configure' the
option `--prefix=PATH'.
By default, `make install' installs the package's commands under
`/usr/local/bin', include files under `/usr/local/include', etc. You
can specify an installation prefix other than `/usr/local' by giving
`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
give `configure' the option `--exec-prefix=PATH', the package will use
PATH as the prefix for installing programs and libraries.
Documentation and other data files will still use the regular prefix.
pass the option `--exec-prefix=PREFIX' to `configure', the package uses
PREFIX as the prefix for installing programs and libraries.
Documentation and other data files still use the regular prefix.
In addition, if you use an unusual directory layout you can give
options like `--bindir=PATH' to specify different values for particular
options like `--bindir=DIR' to specify different values for particular
kinds of files. Run `configure --help' for a list of the directories
you can set and what kinds of files go in them.
@ -122,7 +126,7 @@ option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
Optional Features
=================
Some packages pay attention to `--enable-FEATURE' options to
Some packages pay attention to `--enable-FEATURE' options to
`configure', where FEATURE indicates an optional part of the package.
They may also pay attention to `--with-PACKAGE' options, where PACKAGE
is something like `gnu-as' or `x' (for the X Window System). The
@ -137,11 +141,11 @@ you can use the `configure' options `--x-includes=DIR' and
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
There may be some features `configure' cannot figure out automatically,
but needs to determine by the type of machine the package will run on.
Usually, assuming the package is built to be run on the _same_
architectures, `configure' can figure that out, but if it prints a
message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
@ -156,7 +160,7 @@ where SYSTEM can have one of these forms:
need to know the machine type.
If you are _building_ compiler tools for cross-compiling, you should
use the `--target=TYPE' option to select the type of system they will
use the option `--target=TYPE' to select the type of system they will
produce code for.
If you want to _use_ a cross compiler, that generates code for a
@ -167,9 +171,9 @@ eventually be run) with `--host=TYPE'.
Sharing Defaults
================
If you want to set default values for `configure' scripts to share,
you can create a site shell script called `config.site' that gives
default values for variables like `CC', `cache_file', and `prefix'.
If you want to set default values for `configure' scripts to share, you
can create a site shell script called `config.site' that gives default
values for variables like `CC', `cache_file', and `prefix'.
`configure' looks for `PREFIX/share/config.site' if it exists, then
`PREFIX/etc/config.site' if it exists. Or, you can set the
`CONFIG_SITE' environment variable to the location of the site script.
@ -178,7 +182,7 @@ A warning: not all `configure' scripts look for a site script.
Defining Variables
==================
Variables not defined in a site shell script can be set in the
Variables not defined in a site shell script can be set in the
environment passed to `configure'. However, some packages may run
configure again during the build, and the customized values of these
variables may be lost. In order to avoid this problem, you should set
@ -186,14 +190,18 @@ them in the `configure' command line, using `VAR=value'. For example:
./configure CC=/usr/local2/bin/gcc
will cause the specified gcc to be used as the C compiler (unless it is
causes the specified `gcc' to be used as the C compiler (unless it is
overridden in the site shell script).
Unfortunately, this technique does not work for `CONFIG_SHELL' due to
an Autoconf bug. Until the bug is fixed you can use this workaround:
CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
`configure' Invocation
======================
`configure' recognizes the following options to control how it
operates.
`configure' recognizes the following options to control how it operates.
`--help'
`-h'

View File

@ -9,46 +9,44 @@
int
main()
main(int argc, char *argv[])
{
struct timeval tv;
void *module;
double t1 = 0.0;
double t2 = 0.0;
void *module;
void *symbol;
int (*time)(struct timeval *tv, void *tz);
if (argc < 3)
{
printf ("Usage: %s file.dll symbol\n\n", argv[0]);
return EXIT_FAILURE;
}
module = dlopen("d:\\msys\\1.0\\local\\bin\\libevil-0.dll", 0);
printf ("opening module %s\n", argv[1]);
module = dlopen(argv[1], 0);
if (!module)
{
printf ("%s\n", dlerror());
return EXIT_FAILURE;
}
printf ("opening module %s successful\n", argv[1]);
time = dlsym(module, "gettimeofday");
if (!time)
printf ("getting symbol %s\n", argv[2]);
symbol = dlsym(module, argv[2]);
if (!symbol)
{
printf ("%s\n", dlerror());
if (dlclose(module))
printf ("%s\n", dlerror());
return EXIT_FAILURE;
}
printf ("getting symbol %s successful\n", argv[2]);
if (time(&tv, NULL) == 0)
t1 = tv.tv_sec + tv.tv_usec / 1000000.0;
Sleep(3000);
if (time(&tv, NULL) == 0)
t2 = tv.tv_sec + tv.tv_usec / 1000000.0;
printf ("3 seconds ? %f\n", t2 - t1);
printf ("closing module %s\n", argv[1]);
if (dlclose(module))
{
printf ("%s\n", dlerror());
return EXIT_FAILURE;
}
printf ("closing module %s successful\n", argv[1]);
return EXIT_SUCCESS;
}

View File

@ -25,9 +25,7 @@ thread (void *param)
Sleep (2 * 1000);
d = (data *)param;
buf[0] = d;
printf ("writing...\n");
send(d->fd_write, (char *)buf, sizeof(buf), 0);
printf ("end of writing...\n");
return 0;
}
@ -60,13 +58,11 @@ main (int argc, char *argv[])
d = (data *)malloc(sizeof (data));
d->val = 14;
d->fd_write = sockets[FDWRITE];
printf (" pointeur 0 : %p\n", d);
printf (" pointeur sent........: %p\n", d);
h = CreateThread (NULL, 0, thread, d, 0, &thread_id);
printf (" * select : %d %d\n", sockets[0], sockets[1]);
ret = select(sockets[FDREAD] + 1, &rfds, NULL, NULL, &t);
printf (" * select : ret %d\n", ret);
if (ret < 0) return -1;
@ -81,16 +77,14 @@ main (int argc, char *argv[])
int j = 0;
void *buf[1];
printf ("bon \n");
while ((len = recv(sockets[FDREAD], (char *)buf, sizeof(buf), 0)) > 0)
{
printf ("len : %d\n", len);
if (len == sizeof(buf))
{
d = buf[0];
printf (" pointeur 1 : %p\n", d);
printf (" pointeur received....: %p\n", d);
j = d->val;
printf ("reussite : %d\n", j);
printf (" value (should be 14) : %d\n", j);
}
}
}

View File

@ -20,6 +20,8 @@ extern "C" {
/**
* @mainpage Evil
* @author Vincent Torri
* @date 2008
*
* @section intro_sec Introduction
*
@ -52,6 +54,7 @@ extern "C" {
#include <stdlib.h>
#include <sys/time.h>
#include <limits.h>
#ifndef __CEGCC__
@ -87,6 +90,21 @@ extern "C" {
# define F_SETLK 6
# define F_SETLKW 7
/**
* @def F_RDLCK
* Read (or shared) lock
*/
/**
* @def F_WRLCK
* Write (or exclusive) lock
*/
/**
* @def F_UNLCK
* Remove lock
*/
# ifndef F_RDLCK
# define F_RDLCK 0
# define F_WRLCK 1
@ -157,6 +175,7 @@ EAPI int fcntl(int fd, int cmd, ...);
* On success, the function returns the file descriptor of the
* temporary file. Otherwise, it returns -1 and errno is set to the
* following values:
* - EINVAL: @p template has an invalid format.
* - EACCESS: Given path is a directory, or file is read-only, but an
* open-for-writing operation was attempted.
* - EEXISTS: File name already exists.
@ -229,6 +248,23 @@ EAPI int symlink(const char *oldpath, const char *newpath);
*/
EAPI ssize_t readlink(const char *path, char *buf, size_t bufsiz);
/**
* @brief Create a pair of sockets.
*
* @param fds A pointer that contains two sockets.
*
* Create a pair of sockets that can be use with select().
* Hence, evil_sockets_init() must have been caled at least
* once before. Contrary to Unix, that functions does not
* create a pair of file descriptors.
*
* Conformity: Not applicable.
*
* Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
* Windows XP.
*
* @ingroup Evil
*/
EAPI int pipe(int *fds);
#endif /* ! __CEGCC__ */
@ -236,21 +272,109 @@ EAPI int pipe(int *fds);
#if defined(__MSDOS__) || defined(__EMX__) || \
(defined(_WIN32) && !defined(_UWIN) && !defined(__CYGWIN__) && !defined(__CEGCC__))
# if defined(_MSC_VER) || defined(__MINGW32__)
# define open(path,flag,mode) EAPI _open((path),(flag),(mode))
# define close(fd) EAPI _close(fd)
# define read(fd,buffer,count) EAPI _read((fd),(buffer),(count))
# define write(fd,buffer,count) EAPI _write((fd),(buffer),(count))
# define mkdir(p,m) EAPI _mkdir(p)
# define S_IRGRP S_IRUSR
# define S_IROTH S_IRUSR
# define S_IWGRP S_IWUSR
# define S_IWOTH S_IWUSR
# define S_IXGRP S_IXUSR
# define S_IXOTH S_IXUSR
# define open(path,flag,mode) _open((path),(flag),(mode))
# define close(fd) _close(fd)
# define read(fd,buffer,count) _read((fd),(buffer),(count))
# define write(fd,buffer,count) _write((fd),(buffer),(count))
# define unlink(filename) _unlink((filename))
# define mkdir(p,m) _mkdir(p)
# endif
#endif
#define realpath(file_name, resolved_name) EAPI _fullpath((resolved_name), (file_name), PATH_MAX)
/**
* @brief Return aan absolute or full path name for a specified relative path name.
*
* @param file_name The absolute path name.
* @param resolved_name The relative path name.
* @return @c NULL on failure, a pointer to the absolute path name otherwise.
*
* The function expands the relative path name @p file_name to its
* fully qualified or absolute path and store it in the buffer pointed
* by @p resolved_name. The buffer is at most @c PATH_MAX bytes long.
* If @p resolved_name is @c NULL, malloc() is used to allocate a
* buffer of sufficient length to hold the path name. In that case, it
* is the responsability of the caller to free this buffer with free().
*
* That function can be used to obtain the absolute path name for
* relative paths (relPath) that include "./" or "../" in their names.
*
* Conformity: None.
*
* Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
* Windows XP.
*
* @ingroup Evil
*/
EAPI char *realpath(const char *file_name, char *resolved_name);
EAPI char *evil_tmpdir_get(void);
/**
* @brief Initiates the use of Windows sockets.
*
* @return 1 on success, 0 otherwise.
*
* Initiates the use of Windows sockets. If the function succeeds,
* it returns 1, otherwise it return 0.
*
* Conformity: Non applicable.
*
* Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
* Windows XP.
*
* @ingroup Evil
*/
EAPI int evil_sockets_init(void);
/**
* @brief Shutdown the Windows socket system.
*
* Shutdown the Windows socket system.
*
* Conformity: Non applicable.
*
* Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
* Windows XP.
*
* @ingroup Evil
*/
EAPI void evil_sockets_shutdown(void);
/**
* @brief Return a dir to store temporary files.
*
* @return The directory to store temporary files.
*
* Return a directory to store temporary files. The function gets
* the value of the followig environment variables, and in that order:
* - TMP
* - TEMP
* - USERPROFILE
* - WINDIR
* and returns its value if it exists. If none exists, the function
* returns "C:\".
*
* Conformity: Non applicable.
*
* Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000,
* Windows XP.
*
* @ingroup Evil
*/
EAPI const char *evil_tmpdir_get(void);
#ifdef __cplusplus
}
#endif
#ifdef _WIN32
# undef EAPI
# define EAPI
#endif /* _WIN32 */
#endif /* __E_WIN32_H__ */

View File

@ -17,6 +17,20 @@
extern "C" {
#endif
/**
* @def RTLD_LAZY
* Lazy function call binding
*/
/**
* @def RTLD_NOW
* Immediate function call binding
*/
/**
* @def RTLD_GLOBAL
* Symbols in this dlopen'ed obj are visible to other dlopen'ed objs
*/
# define RTLD_LAZY 1 /* lazy function call binding */
# define RTLD_NOW 2 /* immediate function call binding */
@ -171,4 +185,9 @@ EAPI char *dlerror (void);
}
#endif
#ifdef _WIN32
# undef EAPI
# define EAPI
#endif /* _WIN32 */
#endif /* __E_WIN32_DLFCN_H__ */

View File

@ -93,14 +93,19 @@ int fcntl(int fd, int cmd, ...)
int
mkstemp(char *template)
{
char *filename;
int fd;
filename = _mktemp(template);
if (!filename)
#ifdef __MINGW32__
if (!_mktemp(template))
return -1;
fd = _sopen(filename, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _SH_DENYNO, _S_IREAD | _S_IWRITE);
fd = _sopen(template, _O_RDWR | _O_BINARY | _O_CREAT | _O_EXCL, _SH_DENYNO, _S_IREAD | _S_IWRITE);
#else
if (_mktemp_s(template, _MAX_PATH) != 0)
return -1;
_sopen_s(&fd, template, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE);
#endif /* ! __MINGW32__ */
return fd;
}
@ -224,6 +229,10 @@ readlink(const char *path, char *buf, size_t bufsiz)
return -1;
}
/*
* The code of the following functions has been kindly offered
* by Tor Lillqvist.
*/
int
pipe(int *fds)
{
@ -333,6 +342,26 @@ pipe(int *fds)
#endif /* ! __CEGCC__ */
char *
realpath(const char *file_name, char *resolved_name)
{
return _fullpath(resolved_name, file_name, PATH_MAX);
}
int
evil_sockets_init(void)
{
WSADATA wsa_data;
return (WSAStartup(MAKEWORD( 2, 2 ), &wsa_data) == 0) ? 1 : 0;
}
void
evil_sockets_shutdown(void)
{
WSACleanup();
}
const char *
evil_tmpdir_get(void)
{
char *tmpdir;

View File

@ -18,11 +18,46 @@ extern "C" {
#endif
/**
* @def PROT_NONE
* Data can not be accessed.
*/
/**
* @def PROT_READ
* Data can be read.
*/
/**
* @def PROT_WRITE
* Data can be written.
*/
/**
* @def PROT_EXEC
* Data can be executed.
*/
#define PROT_NONE 0x00
#define PROT_READ 0x01
#define PROT_WRITE 0x02
#define PROT_EXEC 0x04
/**
* @def MAP_SHARED
* Changes are shared.
*/
/**
* @def MAP_PRIVATE
* Changes are private.
*/
/**
* @def MAP_FIXED
* Interpret the address (addr) exactly.
*/
#define MAP_SHARED 0x0001
#define MAP_PRIVATE 0x0002
#define MAP_FIXED 0x0010
@ -111,5 +146,10 @@ EAPI int munmap(void *addr,
}
#endif
#ifdef _WIN32
# undef EAPI
# define EAPI
#endif /* _WIN32 */
#endif /* __E_WIN32_SYS_MMAN_H__ */