From 2ee8b5bb135d363d63198f92760a6ea954a5ea8d Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 20 Mar 2003 21:07:49 +0000 Subject: [PATCH] Replaced mkstemp by mkstemps from libiberty. Removed a couple of unnecessary portability functions. --- configure | 4 -- configure.ac | 2 - dlls/shell32/shelllink.c | 4 +- dlls/wsock32/protocol.c | 4 ++ include/config.h.in | 6 -- include/wine/port.h | 22 ++---- library/port.c | 59 ----------------- libs/port/Makefile.in | 2 +- libs/port/mkstemp.c | 55 --------------- libs/port/mkstemps.c | 129 ++++++++++++++++++++++++++++++++++++ programs/winedbg/gdbproxy.c | 3 +- scheduler/sysdeps.c | 42 +++--------- server/file.c | 2 +- tools/winebuild/import.c | 8 +-- tools/wpp/wpp.c | 2 +- 15 files changed, 160 insertions(+), 184 deletions(-) delete mode 100644 libs/port/mkstemp.c create mode 100644 libs/port/mkstemps.c diff --git a/configure b/configure index 801c815b13e..7b3845dd177 100755 --- a/configure +++ b/configure @@ -13078,8 +13078,6 @@ fi - - @@ -13108,12 +13106,10 @@ for ac_func in \ getprotobynumber \ getpwuid \ getservbyport \ - getsockopt \ inet_network \ lseek64 \ lstat \ memmove \ - mkstemp \ mmap \ pclose \ popen \ diff --git a/configure.ac b/configure.ac index 7493e0de30e..91437d2d6a8 100644 --- a/configure.ac +++ b/configure.ac @@ -931,12 +931,10 @@ AC_CHECK_FUNCS(\ getprotobynumber \ getpwuid \ getservbyport \ - getsockopt \ inet_network \ lseek64 \ lstat \ memmove \ - mkstemp \ mmap \ pclose \ popen \ diff --git a/dlls/shell32/shelllink.c b/dlls/shell32/shelllink.c index cde90270f2d..d317eec226d 100644 --- a/dlls/shell32/shelllink.c +++ b/dlls/shell32/shelllink.c @@ -562,8 +562,8 @@ static char *extract_icon( const char *path, int index) int fd, nodefault = 1; char *filename, tmpfn[25]; - strcpy(tmpfn,"/tmp/icon.XXXXXX"); - fd = mkstemp( tmpfn ); + strcpy(tmpfn,"/tmp/icon.XXXXXX.xpm"); + fd = mkstemps( tmpfn, 4 ); if (fd == -1) return NULL; filename = heap_strdup( tmpfn ); diff --git a/dlls/wsock32/protocol.c b/dlls/wsock32/protocol.c index 87e54137bde..d1f4abb0b7f 100644 --- a/dlls/wsock32/protocol.c +++ b/dlls/wsock32/protocol.c @@ -296,7 +296,11 @@ INT WINAPI EnumProtocolsW( LPINT lpiProtocols, LPVOID lpBuffer, */ UINT WINAPI WSOCK32_inet_network(const char *cp) { +#ifdef HAVE_INET_NETWORK return inet_network(cp); +#else + return 0; +#endif } /***************************************************************************** diff --git a/include/config.h.in b/include/config.h.in index 61893dbe119..e2ea1acdbd2 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -161,9 +161,6 @@ /* Define to 1 if you have the `getservbyport' function. */ #undef HAVE_GETSERVBYPORT -/* Define to 1 if you have the `getsockopt' function. */ -#undef HAVE_GETSOCKOPT - /* Define to 1 if you have the header file. */ #undef HAVE_GIF_LIB_H @@ -326,9 +323,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H -/* Define to 1 if you have the `mkstemp' function. */ -#undef HAVE_MKSTEMP - /* Define to 1 if you have the `mmap' function. */ #undef HAVE_MMAP diff --git a/include/wine/port.h b/include/wine/port.h index 958e8acdce4..4187c72d540 100644 --- a/include/wine/port.h +++ b/include/wine/port.h @@ -167,7 +167,7 @@ struct statfs; * Function definitions (only when using libwine) */ -#ifndef NO_LIBWINE +#ifndef NO_LIBWINE_PORT #if !defined(HAVE_CLONE) && defined(linux) int clone(int (*fn)(void *arg), void *stack, int flags, void *arg); @@ -199,22 +199,10 @@ extern int getopt_long_only (int ___argc, char *const *___argv, size_t getpagesize(void); #endif /* HAVE_GETPAGESIZE */ -#ifndef HAVE_GETSOCKOPT -int getsockopt(int socket, int level, int option_name, void *option_value, size_t *option_len); -#endif /* !defined(HAVE_GETSOCKOPT) */ - -#ifndef HAVE_INET_NETWORK -unsigned long inet_network(const char *cp); -#endif /* !defined(HAVE_INET_NETWORK) */ - #ifndef HAVE_LSTAT int lstat(const char *file_name, struct stat *buf); #endif /* HAVE_LSTAT */ -#ifndef HAVE_MKSTEMP -int mkstemp(char *tmpfn); -#endif /* HAVE_MKSTEMP */ - #ifndef HAVE_MEMMOVE void *memmove(void *dest, const void *src, size_t len); #endif /* !defined(HAVE_MEMMOVE) */ @@ -261,6 +249,8 @@ int usleep (unsigned int useconds); extern void *wine_memcpy_unaligned( void *dst, const void *src, size_t size ); #endif /* __i386__ */ +extern int mkstemps(char *template, int suffix_len); + /* Interlocked functions */ #if defined(__i386__) && defined(__GNUC__) @@ -315,14 +305,12 @@ extern long interlocked_xchg_add( long *dest, long incr ); #endif /* __i386___ && __GNUC__ */ -#else /* NO_LIBWINE */ +#else /* NO_LIBWINE_PORT */ #define __WINE_NOT_PORTABLE(func) func##_is_not_portable func##_is_not_portable #define clone __WINE_NOT_PORTABLE(clone) #define getpagesize __WINE_NOT_PORTABLE(getpagesize) -#define getsockopt __WINE_NOT_PORTABLE(getsockopt) -#define inet_network __WINE_NOT_PORTABLE(inet_network) #define lstat __WINE_NOT_PORTABLE(lstat) #define memmove __WINE_NOT_PORTABLE(memmove) #define pread __WINE_NOT_PORTABLE(pread) @@ -333,6 +321,6 @@ extern long interlocked_xchg_add( long *dest, long incr ); #define strncasecmp __WINE_NOT_PORTABLE(strncasecmp) #define usleep __WINE_NOT_PORTABLE(usleep) -#endif /* NO_LIBWINE */ +#endif /* NO_LIBWINE_PORT */ #endif /* !defined(__WINE_WINE_PORT_H) */ diff --git a/library/port.c b/library/port.c index fcaec419713..acc566063a5 100644 --- a/library/port.c +++ b/library/port.c @@ -65,65 +65,6 @@ #endif -/*********************************************************************** - * clone - */ -#if !defined(HAVE_CLONE) && defined(__linux__) -int clone( int (*fn)(void *), void *stack, int flags, void *arg ) -{ -#ifdef __i386__ - int ret; - void **stack_ptr = (void **)stack; - *--stack_ptr = arg; /* Push argument on stack */ - *--stack_ptr = fn; /* Push function pointer (popped into ebx) */ - __asm__ __volatile__( "pushl %%ebx\n\t" - "movl %2,%%ebx\n\t" - "int $0x80\n\t" - "popl %%ebx\n\t" /* Contains fn in the child */ - "testl %%eax,%%eax\n\t" - "jnz 0f\n\t" - "xorl %ebp,%ebp\n\t" /* Terminate the stack frames */ - "call *%%ebx\n\t" /* Should never return */ - "xorl %%eax,%%eax\n\t" /* Just in case it does*/ - "0:" - : "=a" (ret) - : "0" (SYS_clone), "r" (flags), "c" (stack_ptr) ); - assert( ret ); /* If ret is 0, we returned from the child function */ - if (ret > 0) return ret; - errno = -ret; - return -1; -#else - errno = EINVAL; - return -1; -#endif /* __i386__ */ -} -#endif /* !HAVE_CLONE && __linux__ */ - - -/*********************************************************************** - * getsockopt - */ -#ifndef HAVE_GETSOCKOPT -int getsockopt(int socket, int level, int option_name, - void *option_value, size_t *option_len) -{ - errno = ENOSYS; - return -1; -} -#endif /* !defined(HAVE_GETSOCKOPT) */ - -/*********************************************************************** - * inet_network - */ -#ifndef HAVE_INET_NETWORK -unsigned long inet_network(const char *cp) -{ - errno = ENOSYS; - return 0; -} -#endif /* defined(HAVE_INET_NETWORK) */ - - #if defined(__svr4__) || defined(__NetBSD__) /*********************************************************************** * try_mmap_fixed diff --git a/libs/port/Makefile.in b/libs/port/Makefile.in index e0633c1d375..d6fd5c95894 100644 --- a/libs/port/Makefile.in +++ b/libs/port/Makefile.in @@ -11,7 +11,7 @@ C_SRCS = \ getpagesize.c \ lstat.c \ memmove.c \ - mkstemp.c \ + mkstemps.c \ pread.c \ pwrite.c \ statfs.c \ diff --git a/libs/port/mkstemp.c b/libs/port/mkstemp.c deleted file mode 100644 index 17a2adc8447..00000000000 --- a/libs/port/mkstemp.c +++ /dev/null @@ -1,55 +0,0 @@ -/* - * mkstemp function - * - * Copyright 1996 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" -#include "wine/port.h" - -#include -#include -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifndef HAVE_MKSTEMP -int mkstemp(char *tmpfn) -{ - int tries; - char *xstart; - - xstart = tmpfn+strlen(tmpfn)-1; - while ((xstart > tmpfn) && (*xstart == 'X')) - xstart--; - tries = 10; - while (tries--) - { - char *newfn = mktemp(tmpfn); - int fd; - if (!newfn) /* something else broke horribly */ - return -1; - fd = open(newfn,O_CREAT|O_RDWR|O_EXCL,0600); - if (fd!=-1) - return fd; - newfn = xstart; - /* fill up with X and try again ... */ - while (*newfn) *newfn++ = 'X'; - } - return -1; -} -#endif /* HAVE_MKSTEMP */ diff --git a/libs/port/mkstemps.c b/libs/port/mkstemps.c new file mode 100644 index 00000000000..90620b8fa25 --- /dev/null +++ b/libs/port/mkstemps.c @@ -0,0 +1,129 @@ +/* Copyright (C) 1991, 1992, 1996, 1998 Free Software Foundation, Inc. + This file is derived from mkstemp.c from the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TIME_H +#include +#endif + +/* We need to provide a type for gcc_uint64_t. */ +#ifdef __GNUC__ +__extension__ typedef unsigned long long gcc_uint64_t; +#else +typedef unsigned long gcc_uint64_t; +#endif + +#ifndef TMP_MAX +#define TMP_MAX 16384 +#endif + +/* + +@deftypefn Replacement int mkstemps (char *@var{template}, int @var{suffix_len}) + +Generate a unique temporary file name from @var{template}. +@var{template} has the form: + +@example + @var{path}/ccXXXXXX@var{suffix} +@end example + +@var{suffix_len} tells us how long @var{suffix} is (it can be zero +length). The last six characters of @var{template} before @var{suffix} +must be @samp{XXXXXX}; they are replaced with a string that makes the +filename unique. Returns a file descriptor open on the file for +reading and writing. + +@end deftypefn + +*/ + +int +mkstemps (template, suffix_len) + char *template; + int suffix_len; +{ + static const char letters[] + = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static gcc_uint64_t value; + struct timeval tv; + char *XXXXXX; + size_t len; + int count; + + len = strlen (template); + + if ((int) len < 6 + suffix_len + || strncmp (&template[len - 6 - suffix_len], "XXXXXX", 6)) + { + return -1; + } + + XXXXXX = &template[len - 6 - suffix_len]; + + /* Get some more or less random data. */ + gettimeofday (&tv, NULL); + value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); + + for (count = 0; count < TMP_MAX; ++count) + { + gcc_uint64_t v = value; + int fd; + + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % 62]; + v /= 62; + XXXXXX[1] = letters[v % 62]; + v /= 62; + XXXXXX[2] = letters[v % 62]; + v /= 62; + XXXXXX[3] = letters[v % 62]; + v /= 62; + XXXXXX[4] = letters[v % 62]; + v /= 62; + XXXXXX[5] = letters[v % 62]; + +#ifdef VMS + fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600, "fop=tmd"); +#else + fd = open (template, O_RDWR|O_CREAT|O_EXCL, 0600); +#endif + if (fd >= 0) + /* The file does not exist. */ + return fd; + + /* This is a random value. It is only necessary that the next + TMP_MAX values generated by adding 7777 to VALUE are different + with (module 2^32). */ + value += 7777; + } + + /* We return the null string if we can't find a unique file name. */ + template[0] = '\0'; + return -1; +} diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index dea29dc5350..203d620bee5 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -25,6 +25,7 @@ */ #include "config.h" +#include "wine/port.h" #include #include @@ -1981,7 +1982,7 @@ static BOOL gdb_startup(struct gdb_context* gdbctx, DEBUG_EVENT* de, unsigned fl if (!(gdb_path = getenv("WINE_GDB"))) gdb_path = "gdb"; strcpy(buf,"/tmp/winegdb.XXXXXX"); - fd = mkstemp(buf); + fd = mkstemps(buf,0); if (fd == -1) return FALSE; if ((f = fdopen(fd, "w+")) == NULL) return FALSE; fprintf(f, "file %s\n", wine_path); diff --git a/scheduler/sysdeps.c b/scheduler/sysdeps.c index b792ae0f9d5..b1408537c15 100644 --- a/scheduler/sysdeps.c +++ b/scheduler/sysdeps.c @@ -41,6 +41,10 @@ #ifdef HAVE_SYS_MMAN_H #include #endif +#ifdef HAVE_SCHED_H +#include +#endif + #include "thread.h" #include "wine/server.h" #include "winbase.h" @@ -51,19 +55,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(thread); -#if defined(linux) || defined(HAVE_CLONE) -# ifdef HAVE_SCHED_H -# include -# endif -# ifndef CLONE_VM -# define CLONE_VM 0x00000100 -# define CLONE_FS 0x00000200 -# define CLONE_FILES 0x00000400 -# define CLONE_SIGHAND 0x00000800 -# define CLONE_PID 0x00001000 -# endif /* CLONE_VM */ -#endif /* linux || HAVE_CLONE */ - struct thread_cleanup_info { void *stack_base; @@ -185,18 +176,12 @@ static void SYSDEPS_StartThread( TEB *teb ) */ int SYSDEPS_SpawnThread( TEB *teb ) { -#ifdef ERRNO_LOCATION - -#if defined(linux) || defined(HAVE_CLONE) - const int flags = CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD; - if (clone( (int (*)(void *))SYSDEPS_StartThread, teb->stack_top, flags, teb ) < 0) +#ifdef HAVE_CLONE + if (clone( (int (*)(void *))SYSDEPS_StartThread, teb->stack_top, + CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, teb ) < 0) return -1; - if (!(flags & CLONE_FILES)) close( teb->request_fd ); /* close the child socket in the parent */ return 0; -#endif - -#ifdef HAVE_RFORK - const int flags = RFPROC | RFMEM; /*|RFFDG*/ +#elif defined(HAVE_RFORK) void **sp = (void **)teb->stack_top; *--sp = teb; *--sp = 0; @@ -212,13 +197,10 @@ int SYSDEPS_SpawnThread( TEB *teb ) "ret;\n" "1:\n\t" /* parent -> caller thread */ "addl $8,%%esp" : - : "r" (sp), "g" (SYS_rfork), "g" (flags) + : "r" (sp), "g" (SYS_rfork), "g" (RFPROC | RFMEM) : "eax", "edx"); - if (flags & RFFDG) close( teb->request_fd ); /* close the child socket in the parent */ return 0; -#endif - -#ifdef HAVE__LWP_CREATE +#elif defined(HAVE__LWP_CREATE) ucontext_t context; _lwp_makecontext( &context, (void(*)(void *))SYSDEPS_StartThread, teb, NULL, teb->stack_base, (char *)teb->stack_top - (char *)teb->stack_base ); @@ -227,10 +209,8 @@ int SYSDEPS_SpawnThread( TEB *teb ) return 0; #endif -#endif /* ERRNO_LOCATION */ - FIXME("CreateThread: stub\n" ); - return 0; + return -1; } diff --git a/server/file.c b/server/file.c index c14c4ee23b2..1def8cb2200 100644 --- a/server/file.c +++ b/server/file.c @@ -253,7 +253,7 @@ struct file *create_temp_file( int access ) int fd; sprintf( tmpfn, "anonmap.XXXXXX" ); /* create it in the server directory */ - fd = mkstemp(tmpfn); + fd = mkstemps( tmpfn, 0 ); if (fd == -1) { file_set_error(); diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c index 2927d8e83e1..1d34d4267a9 100644 --- a/tools/winebuild/import.c +++ b/tools/winebuild/import.c @@ -616,13 +616,13 @@ static const char *ldcombine_files( char **argv ) if (output_file_name && output_file_name[0]) { - ld_tmp_file = xmalloc( strlen(output_file_name) + 8 ); + ld_tmp_file = xmalloc( strlen(output_file_name) + 10 ); strcpy( ld_tmp_file, output_file_name ); - strcat( ld_tmp_file, ".XXXXXX" ); + strcat( ld_tmp_file, ".XXXXXX.o" ); } - else ld_tmp_file = xstrdup( "/tmp/winebuild.tmp.XXXXXX" ); + else ld_tmp_file = xstrdup( "/tmp/winebuild.tmp.XXXXXX.o" ); - if ((fd = mkstemp( ld_tmp_file ) == -1)) fatal_error( "could not generate a temp file\n" ); + if ((fd = mkstemps( ld_tmp_file, 2 ) == -1)) fatal_error( "could not generate a temp file\n" ); close( fd ); atexit( remove_ld_tmp_file ); diff --git a/tools/wpp/wpp.c b/tools/wpp/wpp.c index d2711a1d361..49c2395f424 100644 --- a/tools/wpp/wpp.c +++ b/tools/wpp/wpp.c @@ -124,7 +124,7 @@ int wpp_parse_temp( const char *input, const char *output_base, char **output_na strcpy( temp_name, output_base ); strcat( temp_name, ".XXXXXX" ); - if((fd = mkstemp( temp_name )) == -1) + if((fd = mkstemps( temp_name, 0 )) == -1) { fprintf(stderr, "Could not generate a temp name from %s\n", temp_name); exit(2);