Mercurial > gftp.yaz
changeset 402:57087926bf03
2004-2-16 Brian Masney <masneyb@gftp.org>
* src/gtk/view_dialog.c - call mkstemps() to create the temporary
file. This is so that the extension of the file will be preserved
so that syntax highlighting will still work (from
Aurelien Jarno <aurelien@aurel32.net>)
* lib/Makefile.am lib/gftp.h lib/mkstemps.c po/POTFILES.in -
added mksteps() from the GNU C Library (from
Aurelien Jarno <aurelien@aurel32.net>)
author | masneyb |
---|---|
date | Tue, 17 Feb 2004 00:49:17 +0000 |
parents | 3bb0cb1b8389 |
children | 1e838d05dde2 |
files | ChangeLog lib/Makefile.am lib/gftp.h lib/mkstemps.c po/POTFILES.in src/gtk/view_dialog.c |
diffstat | 6 files changed, 176 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Feb 17 00:04:58 2004 +0000 +++ b/ChangeLog Tue Feb 17 00:49:17 2004 +0000 @@ -1,3 +1,13 @@ +2004-2-16 Brian Masney <masneyb@gftp.org> + * src/gtk/view_dialog.c - call mkstemps() to create the temporary + file. This is so that the extension of the file will be preserved + so that syntax highlighting will still work (from + Aurelien Jarno <aurelien@aurel32.net>) + + * lib/Makefile.am lib/gftp.h lib/mkstemps.c po/POTFILES.in - + added mksteps() from the GNU C Library (from + Aurelien Jarno <aurelien@aurel32.net>) + 2004-2-16 Brian Masney <masneyb@gftp.org> * src/gtk/misc-gtk.c - compile fix for GTK+ 1.2 @@ -2205,7 +2215,7 @@ * cvsclean - added this script - * *.[ch] - added $Id: ChangeLog,v 1.223 2004/02/17 00:04:55 masneyb Exp $ tags + * *.[ch] - added $Id: ChangeLog,v 1.224 2004/02/17 00:49:15 masneyb Exp $ tags * debian/* - updated files from Debian maintainer
--- a/lib/Makefile.am Tue Feb 17 00:04:58 2004 +0000 +++ b/lib/Makefile.am Tue Feb 17 00:49:17 2004 +0000 @@ -1,7 +1,8 @@ ## Process this file with automake to produce Makefile.in noinst_LIBRARIES = libgftp.a -libgftp_a_SOURCES=bookmark.c cache.c config_file.c ftps.c https.c local.c misc.c \ - protocols.c pty.c rfc959.c rfc2068.c sshv2.c sslcommon.c +libgftp_a_SOURCES=bookmark.c cache.c config_file.c ftps.c https.c local.c \ + misc.c mkstemps.c protocols.c pty.c rfc959.c rfc2068.c \ + sshv2.c sslcommon.c INCLUDES=@GLIB_CFLAGS@ @PTHREAD_CFLAGS@ -I../intl -DSHARE_DIR=\"$(datadir)/gftp\" -DLOCALE_DIR=\"$(datadir)/locale\" noinst_HEADERS=gftp.h ftpcommon.h httpcommon.h options.h
--- a/lib/gftp.h Tue Feb 17 00:04:58 2004 +0000 +++ b/lib/gftp.h Tue Feb 17 00:49:17 2004 +0000 @@ -745,6 +745,10 @@ int gftp_get_transfer_action ( gftp_request * request, gftp_file * fle ); +/* mkstemps.c */ +int mkstemps ( char *template, + int suffix_len ); + /* protocols.c */ #define GFTP_FTP_NUM 0 #define GFTP_FTPS_NUM 1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/mkstemps.c Tue Feb 17 00:49:17 2004 +0000 @@ -0,0 +1,141 @@ +/* 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. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/types.h> +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif +#include <errno.h> +#include <stdio.h> +#include <fcntl.h> +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#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; +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; +#endif + 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]; + +#ifdef HAVE_GETTIMEOFDAY + /* Get some more or less random data. */ + gettimeofday (&tv, NULL); + value += ((gcc_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid (); +#else + value += getpid (); +#endif + + 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; +}
--- a/po/POTFILES.in Tue Feb 17 00:04:58 2004 +0000 +++ b/po/POTFILES.in Tue Feb 17 00:49:17 2004 +0000 @@ -8,6 +8,7 @@ lib/https.c lib/local.c lib/misc.c +lib/mkstemps.c lib/options.h lib/protocols.c lib/pty.c
--- a/src/gtk/view_dialog.c Tue Feb 17 00:04:58 2004 +0000 +++ b/src/gtk/view_dialog.c Tue Feb 17 00:49:17 2004 +0000 @@ -28,6 +28,7 @@ GList * templist, * filelist, * newfile; gftp_window_data * fromwdata, * towdata; gftp_file * new_fle; + char *suffix; int num; fromwdata = data; @@ -55,8 +56,21 @@ new_fle = copy_fdata (curfle); if (new_fle->destfile) g_free (new_fle->destfile); - new_fle->destfile = g_strconcat (g_get_tmp_dir (), "/gftp-view.XXXXXX", NULL); - if ((new_fle->fd = mkstemp (new_fle->destfile)) < 0) + + if ((suffix = strrchr (curfle->file, '.')) != NULL) + { + new_fle->destfile = g_strconcat (g_get_tmp_dir (), + "/gftp-view.XXXXXX", suffix, NULL); + new_fle->fd = mkstemps (new_fle->destfile, strlen (suffix)); + } + else + { + new_fle->destfile = g_strconcat (g_get_tmp_dir (), + "/gftp-view.XXXXXX", NULL); + new_fle->fd = mkstemps (new_fle->destfile, 0); + } + + if (new_fle->fd < 0) { ftp_log (gftp_logging_misc, NULL, _("Error: Cannot open %s for writing: %s\n"),