Enlightenment CVS committal Author : raster Project : e17 Module : libs/embryo
Dir : e17/libs/embryo/src/bin Modified Files: embryo_cc_prefix.c embryo_cc_sc1.c Log Message: patches applied as per emails :) =================================================================== RCS file: /cvs/e/e17/libs/embryo/src/bin/embryo_cc_prefix.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- embryo_cc_prefix.c 6 Sep 2006 07:11:31 -0000 1.4 +++ embryo_cc_prefix.c 10 Feb 2007 17:23:05 -0000 1.5 @@ -11,17 +11,217 @@ #include <sys/stat.h> #include <sys/time.h> #include <sys/param.h> -#include <dlfcn.h> #include <math.h> #include <fnmatch.h> #include <limits.h> #include <ctype.h> #include <time.h> #include <dirent.h> +#ifdef WIN32 +#include <windows.h> +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> +#else +#include <dlfcn.h> /* dlopen,dlclose,etc */ #include <pwd.h> #include <grp.h> #include <glob.h> +#endif /* WIN32 */ + #include "embryo_cc_prefix.h" + +/* FIXME: that hack is a temporary one. That code will be in MinGW soon */ +#ifdef WIN32 + +#define RTLD_LAZY 1 /* lazy function call binding */ +#define RTLD_NOW 2 /* immediate function call binding */ +#define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible + to other dlopen'ed objs */ + +static char *dlerr_ptr; +static char dlerr_data[80]; + +void *dlopen (const char *file, int mode) +{ + HMODULE hmodule; + + hmodule = LoadLibrary(file); + if (hmodule == NULL) { + int error; + + error = GetLastError(); + sprintf(dlerr_data, "LoadLibraryEx returned %d.", error); + dlerr_ptr = dlerr_data; + } + return hmodule; +} + +int dlclose (void *handle) +{ + if (FreeLibrary(handle)) { + return 0; + } + else { + int error; + + error = GetLastError(); + sprintf(dlerr_data, "FreeLibrary returned %d.", error); + dlerr_ptr = dlerr_data; + return -1; + } +} + +void *dlsym (void *handle, const char *name) +{ + FARPROC fp; + + fp = GetProcAddress(handle, name); + if (fp == NULL) { + int error; + + error = GetLastError(); + sprintf(dlerr_data, "GetProcAddress returned %d.", error); + dlerr_ptr = dlerr_data; + } + return fp; +} + +char *dlerror (void) +{ + if (dlerr_ptr != NULL) { + dlerr_ptr = NULL; + return dlerr_data; + } + else { + return NULL; + } +} + +char *realpath(const char *path, char resolved_path[PATH_MAX]) +{ + char *return_path = 0; + + if (path) //Else EINVAL + { + if (resolved_path) + { + return_path = resolved_path; + } + else + { + //Non standard extension that glibc uses + return_path = malloc(PATH_MAX); + } + + if (return_path) //Else EINVAL + { + //This is a Win32 API function similar to what realpath() is supposed to do + size_t size = GetFullPathNameA(path, PATH_MAX, return_path, 0); + + //GetFullPathNameA() returns a size larger than buffer if buffer is too small + if (size > PATH_MAX) + { + if (return_path != resolved_path) //Malloc'd buffer - Unstandard extension retry + { + size_t new_size; + + free(return_path); + return_path = malloc(size); + + if (return_path) + { + new_size = GetFullPathNameA(path, size, return_path, 0); //Try again + + if (new_size > size) //If it's still too large, we have a problem, don't try again + { + free(return_path); + return_path = 0; + errno = ENAMETOOLONG; + } + else + { + size = new_size; + } + } + else + { + //I wasn't sure what to return here, but the standard does say to return EINVAL + //if resolved_path is null, and in this case we couldn't malloc large enough buffer + errno = EINVAL; + } + } + else //resolved_path buffer isn't big enough + { + return_path = 0; + errno = ENAMETOOLONG; + } + } + + //GetFullPathNameA() returns 0 if some path resolve problem occured + if (!size) + { + if (return_path != resolved_path) //Malloc'd buffer + { + free(return_path); + } + + return_path = 0; + + //Convert MS errors into standard errors + switch (GetLastError()) + { + case ERROR_FILE_NOT_FOUND: + errno = ENOENT; + break; + + case ERROR_PATH_NOT_FOUND: case ERROR_INVALID_DRIVE: + errno = ENOTDIR; + break; + + case ERROR_ACCESS_DENIED: + errno = EACCES; + break; + + default: //Unknown Error + errno = EIO; + break; + } + } + + //If we get to here with a valid return_path, we're still doing good + if (return_path) + { + struct stat stat_buffer; + + //Make sure path exists, stat() returns 0 on success + if (stat(return_path, &stat_buffer)) + { + if (return_path != resolved_path) + { + free(return_path); + } + + return_path = 0; + //stat() will set the correct errno for us + } + //else we succeeded! + } + } + else + { + errno = EINVAL; + } + } + else + { + errno = EINVAL; + } + + return return_path; +} + +#endif /* WIN32 */ /* local subsystem functions */ static int _e_prefix_share_hunt(void); =================================================================== RCS file: /cvs/e/e17/libs/embryo/src/bin/embryo_cc_sc1.c,v retrieving revision 1.32 retrieving revision 1.33 diff -u -3 -r1.32 -r1.33 --- embryo_cc_sc1.c 10 Jul 2006 18:31:18 -0000 1.32 +++ embryo_cc_sc1.c 10 Feb 2007 17:23:05 -0000 1.33 @@ -21,7 +21,7 @@ * must not be misrepresented as being the original software. * 3. This notice may not be removed or altered from any source * distribution. - * Version: $Id: embryo_cc_sc1.c,v 1.32 2006/07/10 18:31:18 raster Exp $ + * Version: $Id: embryo_cc_sc1.c,v 1.33 2007/02/10 17:23:05 raster Exp $ */ #ifdef HAVE_CONFIG_H @@ -36,6 +36,12 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#ifdef WIN32 +#include <sys/stat.h> +#include <errno.h> +#include <fcntl.h> +#endif /* WIN32 */ + #include "embryo_cc_osdefs.h" #include "embryo_cc_sc.h" #include "embryo_cc_prefix.h" @@ -314,7 +320,16 @@ if (!tmpdir) tmpdir = "/tmp"; snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir); +#ifndef WIN32 fd_out = mkstemp(outfname); +#else + if (mktemp (outfname)) + do + fd_out = open (outfname, O_CREAT | O_EXCL, S_IREAD | S_IWRITE); + while (!(fd_out == -1 && errno == EEXIST) && mktemp (outfname)); + else + fd_out = -1; +#endif /* WIN32 */ if (fd_out < 0) error(101, outfname); ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs