diff --git a/legacy/evil/ChangeLog b/legacy/evil/ChangeLog index 8248e287e9..1477665b2b 100644 --- a/legacy/evil/ChangeLog +++ b/legacy/evil/ChangeLog @@ -1,3 +1,11 @@ +2008-06-01 Vincent Torri + + * src/lib/Evil.h: + * src/lib/evil.c: + add open with several arguments + add getcwd, lstat, setenv, unsetenv and evil_homedir_get. + typo in doc + 2008-06-01 Vincent Torri * src/lib/dlfcn/dlfcn.c: diff --git a/legacy/evil/src/lib/Evil.h b/legacy/evil/src/lib/Evil.h index ba812f5b23..4cc0e58e33 100644 --- a/legacy/evil/src/lib/Evil.h +++ b/legacy/evil/src/lib/Evil.h @@ -319,12 +319,14 @@ EAPI int pipe(int *fds); # 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 open(path,...) _open((path),__VA_ARGS__) # 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) +# define getcwd(b,s) _getcwd((b),(s)) +# define lstat(f,s) _stat((f),(s)) # endif #endif @@ -361,7 +363,7 @@ EAPI char *realpath(const char *file_name, char *resolved_name); * @return 1 on success, 0 otherwise. * * Initiates the use of Windows sockets. If the function succeeds, - * it returns 1, otherwise it return 0. + * it returns 1, otherwise it returns 0. * * Conformity: Non applicable. * @@ -386,13 +388,55 @@ EAPI int evil_sockets_init(void); */ EAPI void evil_sockets_shutdown(void); +/** + * @brief Create, modify, or remove environment variables. + * + * @param name The name of the environment variable. + * @param value The value of the environment variable to set. + * @return 0 on success, -1 otherwise. + * + * Add the new environment variable @p name or modify its value if it + * exists, and set it to @p value. Environment variables define the + * environment in which a process executes. If @p value is @c NULL, the + * variable is removed (unset) and that call is equivalent to unsetenv(). + * If the function succeeds, it returns 0, otherwise it returns -1. + * + * Conformity: Non applicable. + * + * Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000, + * Windows XP. + * + * @ingroup Evil + */ +EAPI int setenv(const char *name, const char *value); + +/** + * @brief Remove environment variables. + * + * @param name The name of the environment variable. + * @return 0 on success, -1 otherwise. + * + * Remove the new environment variable @p name if it exists. That + * function is equivalent to setenv() with its second parameter to + * @c NULL. If the function succeeds, it returns 0, otherwise it + * returns -1. + * + * Conformity: Non applicable. + * + * Supported OS: Windows 95, Windows 98, Windows Me, Windows NT, Windows 2000, + * Windows XP. + * + * @ingroup Evil + */ +EAPI int unsetenv(const char *name); + /** * @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: + * the value of the following environment variables, and in that order: * - TMP * - TEMP * - USERPROFILE @@ -407,9 +451,30 @@ EAPI void evil_sockets_shutdown(void); * * @ingroup Evil */ - EAPI const char *evil_tmpdir_get(void); +/** + * @brief Return a dir to store personal files. + * + * @return The directory to store personal files. + * + * Return a directory to store personal files. The function gets + * the value of the following environment variables, and in that order: + * - HOME + * - 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_homedir_get(void); + /** * @brief Get the current directory. * diff --git a/legacy/evil/src/lib/evil.c b/legacy/evil/src/lib/evil.c index ec68421b5b..9761d30d84 100644 --- a/legacy/evil/src/lib/evil.c +++ b/legacy/evil/src/lib/evil.c @@ -388,6 +388,38 @@ evil_sockets_shutdown(void) WSACleanup(); } +int +setenv(const char *name, const char *value) +{ + char *str; + int length; + int res; + + length = strlen(name) + strlen(value) + 2; + str = (char *)malloc(length); + sprintf(str, "%s=%s", name, value); + res = _putenv(str); + free(str); + + return res; +} + +int +unsetenv(const char *name) +{ + char *str; + int length; + int res; + + length = strlen(name) + 2; + str = (char *)malloc(length); + sprintf(str, "%s=", name); + res = _putenv(str); + free(str); + + return res; +} + const char * evil_tmpdir_get(void) { @@ -402,6 +434,19 @@ evil_tmpdir_get(void) return tmpdir; } +const char * +evil_homedir_get(void) +{ + char *homedir; + + homedir = getenv("HOME"); + if (!homedir) homedir = getenv("USERPROFILE"); + if (!homedir) homedir = getenv("WINDIR"); + if (!homedir) homedir="C:\\"; + + return homedir; +} + char * evil_getcwd(char *buffer, size_t size) {