1
1

* src/ext.c (exec_extension): Use mc_mkstemps().

* src/user.c (execute_menu_command): Use mc_mkstemps().
* src/util.c (mc_mkstemps): New function - safely create and
open temporary file. Return the handle and the name.
* src/util.h: Declarations for init_tmpdir() and mc_mkstemps().
Define TMPDIR_DEFAULT and SCRIPT_SUFFIX.
* vfs/direntry.c (vfs_s_open): Use mc_mkstemps. Create and close
temporary file to reserve its name on the filesystem.
(vfs_s_retrieve_file): Use mc_mkstemps().
(g_tempnam): Remove.
* vfs/extfs.c (extfs_open): Use mc_mkstemps().
* vfs/sfs.c (redirect): Likewise.
* vfs/shared_ftp_fish.c (_get_file_entry): Likewise.
(retrieve_file): Likewise.
* vfs/vfs.c (mc_def_getlocalcopy): Likewise.
* vfs/xdirentry.h: Remove declaration of g_tempnam().
Этот коммит содержится в:
Pavel Roskin 2001-05-21 16:21:07 +00:00
родитель f501a07de8
Коммит bea09b932d
12 изменённых файлов: 224 добавлений и 139 удалений

Просмотреть файл

@ -1,3 +1,12 @@
2001-05-21 Pavel Roskin <proski@gnu.org>
* src/ext.c (exec_extension): Use mc_mkstemps().
* src/user.c (execute_menu_command): Use mc_mkstemps().
* src/util.c (mc_mkstemps): New function - safely create and
open temporary file. Return the handle and the name.
* src/util.h: Declarations for init_tmpdir() and mc_mkstemps().
Define TMPDIR_DEFAULT and SCRIPT_SUFFIX.
2001-05-18 Pavel Roskin <proski@gnu.org> 2001-05-18 Pavel Roskin <proski@gnu.org>
* TODO: Remove Tk-related entries. * TODO: Remove Tk-related entries.
@ -497,10 +506,10 @@
2000-02-04 "David H.Martin" <dmartina@usa.net> 2000-02-04 "David H.Martin" <dmartina@usa.net>
* src/widget.c (input_new): Change NULL to empty strings and avoid * src/widget.c (input_new): Change NULL to empty strings and avoid
crashing when string functions are called. crashing when string functions are called.
* src/boxes.c (configure_vfs): Remove local change to empty string. * src/boxes.c (configure_vfs): Remove local change to empty string.
* src/setup.c (load setup): Load anonymous password * src/setup.c (load setup): Load anonymous password
2000-02-03 Andrew V. Samoilov <sav@bcs.zp.ua> 2000-02-03 Andrew V. Samoilov <sav@bcs.zp.ua>
@ -2237,10 +2246,10 @@ Tue Sep 15 01:02:34 1998 Paul Sheer <psheer@obsidian.co.za>
1998-09-14 Norbert Warmuth <k3190@fh-sw.de> 1998-09-14 Norbert Warmuth <k3190@fh-sw.de>
* file.c (move_dir_dir): Fixed severe bug reported by Andrew Pechenov * file.c (move_dir_dir): Fixed severe bug reported by Andrew Pechenov
<zx80@demo.ru> (losing files when moving directories cross filesystem <zx80@demo.ru> (losing files when moving directories cross filesystem
boundaries): make sure erase_list is emptied always not only when we boundaries): make sure erase_list is emptied always not only when we
deleted files. deleted files.
Sat Sep 12 02:59:43 1998 Timur Bakeyev <mc@bat.ru> Sat Sep 12 02:59:43 1998 Timur Bakeyev <mc@bat.ru>
@ -3310,10 +3319,10 @@ Sat Feb 21 16:46:49 1998 Stas Maximov <stmax@u213.srcc.msu.su>
Mon Mar 16 13:03:45 1998 Pavel Roskin <pavel_roskin@geocities.com> Mon Mar 16 13:03:45 1998 Pavel Roskin <pavel_roskin@geocities.com>
* cmd.c: Internal edit is used by default. vi may be * cmd.c: Internal edit is used by default. vi may be
confusing for some users. confusing for some users.
* tree.c: tree_rmdir_cmd() should not return any value, * tree.c: tree_rmdir_cmd() should not return any value,
because it is not analyzed for errors. because it is not analyzed for errors.
* main.c: NT code: use O_BINARY instead of _O_BINARY * main.c: NT code: use O_BINARY instead of _O_BINARY
@ -3423,42 +3432,42 @@ Tue Mar 10 20:41:45 1998 Miguel de Icaza <miguel@nuclecu.unam.mx>
Sat Mar 7 14:33:38 1998 Pavel Roskin <pavel_roskin@geocities.com> Sat Mar 7 14:33:38 1998 Pavel Roskin <pavel_roskin@geocities.com>
* src/complete.c: obsolete hack for OS/2 and NT removed. * src/complete.c: obsolete hack for OS/2 and NT removed.
Completion works for NT now (not very good) Completion works for NT now (not very good)
* src/main.c: HOME variable is respected by NT and OS/2 * src/main.c: HOME variable is respected by NT and OS/2
versions. If it is missing, we use LIBDIR on OS2_NT and "/" versions. If it is missing, we use LIBDIR on OS2_NT and "/"
on Unix. on Unix.
* src/key.h: SHIFT_PRESSED is set to 0x0010 on NT. This value * src/key.h: SHIFT_PRESSED is set to 0x0010 on NT. This value
doesn't conflict with definitions for ALT and CTRL, but it is doesn't conflict with definitions for ALT and CTRL, but it is
SDK-compatible. SDK-compatible.
* vfs/vfs.h: Minor changes for OS/2. EMX defines mkdir with * vfs/vfs.h: Minor changes for OS/2. EMX defines mkdir with
2 arguments 2 arguments
* vfs/tcputil,c, vfs/utilvfs.c: signal.h was includes twice. * vfs/tcputil,c, vfs/utilvfs.c: signal.h was includes twice.
* vfs/Makefile.in: undelfs.h is not used and should disapper * vfs/Makefile.in: undelfs.h is not used and should disapper
* slang/slos2tty.c: new file, copied from SLang-0.99.38, * slang/slos2tty.c: new file, copied from SLang-0.99.38,
needed for OS/2 port needed for OS/2 port
* slang/Makefile.in: added slos2tty.c * slang/Makefile.in: added slos2tty.c
* vfs/extfs/README: annoying spell errors corrected * vfs/extfs/README: annoying spell errors corrected
* src/main.c: --termcap disabled for OS2_NT because it doesn't * src/main.c: --termcap disabled for OS2_NT because it doesn't
(and cannot) work. ARCH_FLAGS is not needed anymore. (and cannot) work. ARCH_FLAGS is not needed anymore.
* src/text.c: most includes removed. Added a warning is someone * src/text.c: most includes removed. Added a warning is someone
compiles this file with HAVE_X. Improved color scheme for compiles this file with HAVE_X. Improved color scheme for
consoles with 16 background colors (e.g. OS/2). Hack for OS/2 consoles with 16 background colors (e.g. OS/2). Hack for OS/2
removed. removed.
* src/util.c, src/util.h: STRCOMP and MC_ARCH_FLAGS are moved * src/util.c, src/util.h: STRCOMP and MC_ARCH_FLAGS are moved
to util.h. It may be useful to use them for filenames' completion to util.h. It may be useful to use them for filenames' completion
on OS2_NT on OS2_NT
Fri Mar 6 19:29:54 1998 Miguel de Icaza <miguel@nuclecu.unam.mx> Fri Mar 6 19:29:54 1998 Miguel de Icaza <miguel@nuclecu.unam.mx>
@ -3559,10 +3568,10 @@ Fri Feb 13 19:59:39 1998 Alexander Savelyev <fano@VCom.kiev.ua>
Wed Feb 11 20:08:50 1998 Norbert Warmuth <k3190@fh-sw.de> Wed Feb 11 20:08:50 1998 Norbert Warmuth <k3190@fh-sw.de>
* user.c (execute_menu_command): Extented the syntax of %-macros * user.c (execute_menu_command): Extented the syntax of %-macros
used in the user menu in order to switch quoting on (default) and used in the user menu in order to switch quoting on (default) and
off, e.g. %0f means don't quote the expanded macro, %f and %1f mean off, e.g. %0f means don't quote the expanded macro, %f and %1f mean
quote the expanded macro. quote the expanded macro.
Fri Jan 30 16:43:47 1998 Miguel de Icaza <miguel@nuclecu.unam.mx> Fri Jan 30 16:43:47 1998 Miguel de Icaza <miguel@nuclecu.unam.mx>
@ -3582,49 +3591,49 @@ Fri Jan 23 07:28:54 1998 Peter Daum <gator@cs.tu-berlin.de>
Fri Jan 23 07:19:18 1998 Pavel Roskin <pavel_roskin@geocities.com> Fri Jan 23 07:19:18 1998 Pavel Roskin <pavel_roskin@geocities.com>
* edit/edit.h: mc_mkdir requires 2 arguments for any operation * edit/edit.h: mc_mkdir requires 2 arguments for any operation
system. Obsolete #ifdef's removed. system. Obsolete #ifdef's removed.
* edit/editwidget.c: ansi standard violation removed * edit/editwidget.c: ansi standard violation removed
* nt/Makefile.NT: default SLang directory is now ../slang. Most * nt/Makefile.NT: default SLang directory is now ../slang. Most
of SLang sources are no more compiled for MC. of SLang sources are no more compiled for MC.
* nt/drive.h: new file. Copied from os2/drive.h with minor changes * nt/drive.h: new file. Copied from os2/drive.h with minor changes
* nt/ket.nt.c: new way for handling conflicting SHIFT_PRESSED * nt/ket.nt.c: new way for handling conflicting SHIFT_PRESSED
definitions. get_event can work without blocking. Copy, move definitions. get_event can work without blocking. Copy, move
and delete operations work normally. and delete operations work normally.
* nt/slint.nt.c: SLang_getkey2 and Slang_input_pending2 are * nt/slint.nt.c: SLang_getkey2 and Slang_input_pending2 are
copied from src/slint.c copied from src/slint.c
* nt/sys/param.h: annoying warnings temporaly suppressed. * nt/sys/param.h: annoying warnings temporaly suppressed.
* slang/slvideo.c, slang/slw32tty.c: new files. They contain * slang/slvideo.c, slang/slw32tty.c: new files. They contain
changes by Alexander Dong. changes by Alexander Dong.
* src/myslang.h: definitions for acsii symbols removed, since * src/myslang.h: definitions for acsii symbols removed, since
they are available in slang.h. Double lines are not used anymore. they are available in slang.h. Double lines are not used anymore.
* src/panelize.c: sys/wait.h is included only if HAVE_SYS_WAIT_H * src/panelize.c: sys/wait.h is included only if HAVE_SYS_WAIT_H
is defined is defined
* nt/Makefile.NT: text.c is added * nt/Makefile.NT: text.c is added
* nt/Makefile.VC4: "-debug" switch for linker is not used for * nt/Makefile.VC4: "-debug" switch for linker is not used for
release version release version
* src/screen.c (show_dir): double lines are no more used by NT and * src/screen.c (show_dir): double lines are no more used by NT and
OS/2 ports. OS/2 ports.
* src/wtools.c (real_input_dialog_help): layout of input dialog for * src/wtools.c (real_input_dialog_help): layout of input dialog for
XView port is corrected XView port is corrected
* edit/edit.h: mc_mkdir requires 2 arguments for any operation * edit/edit.h: mc_mkdir requires 2 arguments for any operation
system. Obsolete #ifdef's removed. system. Obsolete #ifdef's removed.
* edit/editwidget.c: ansi standard violation removed * edit/editwidget.c: ansi standard violation removed
Wed Jan 21 14:01:29 1998 Miguel de Icaza <miguel@nuclecu.unam.mx> Wed Jan 21 14:01:29 1998 Miguel de Icaza <miguel@nuclecu.unam.mx>
@ -3638,8 +3647,8 @@ Wed Jan 21 11:58:39 1998 Sung-Hyun Nam <namsh@lgic.co.kr>
* ftpfs.c (retrieve_dir): Avoid compiler warning by testing * ftpfs.c (retrieve_dir): Avoid compiler warning by testing
explicitly the value. explicitly the value.
screen.c (format_file): color not initialized when we met screen.c (format_file): color not initialized when we met
empty_line. empty_line.
Wed Jan 21 11:28:21 1998 Alex Tkachenko <alex@bcs.zp.ua> Wed Jan 21 11:28:21 1998 Alex Tkachenko <alex@bcs.zp.ua>
@ -3692,9 +3701,9 @@ Fri Jan 16 13:47:13 1998 Pavel Roskin <pavel_roskin@geocities.com>
Fri Jan 16 12:47:39 1998 Norbert Warmuth <k3190@fh-sw.de> Fri Jan 16 12:47:39 1998 Norbert Warmuth <k3190@fh-sw.de>
* vfs/ftpfs.c (command): Don't log passwords when the dialog between * vfs/ftpfs.c (command): Don't log passwords when the dialog between
server and client is logged to a file (mc -l logfile). server and client is logged to a file (mc -l logfile).
* vfs/ftpfs.c (resolve_symlink, retrieve_dir): When a directory * vfs/ftpfs.c (resolve_symlink, retrieve_dir): When a directory
contains spaces send two commands ("CWD path" and "LIST .") instead of contains spaces send two commands ("CWD path" and "LIST .") instead of
one command ("LIST path") in order to get directory listings. one command ("LIST path") in order to get directory listings.

Просмотреть файл

@ -139,14 +139,10 @@ exec_extension (const char *filename, const char *data, char **drops, int *move_
else else
do_local_copy = 0; do_local_copy = 0;
if ((file_name = tempnam (NULL, "mcext")) == 0) { cmd_file_fd = mc_mkstemps(&file_name, "mcext", SCRIPT_SUFFIX);
message (1, MSG_ERROR, _(" Can't generate unique filename \n %s "),
unix_error_string (errno));
return;
}
/* #warning FIXME: this is ugly */ /* #warning FIXME: this is ugly */
if ((cmd_file_fd = open (file_name, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600)) == -1){ if (cmd_file_fd == -1){
message (1, MSG_ERROR, _(" Can't create temporary command file \n %s "), message (1, MSG_ERROR, _(" Can't create temporary command file \n %s "),
unix_error_string (errno)); unix_error_string (errno));
free (file_name); free (file_name);

Просмотреть файл

@ -540,19 +540,9 @@ execute_menu_command (char *commands)
return; return;
} }
if ((file_name = tempnam (NULL, "mcusr")) == 0) { cmd_file_fd = mc_mkstemps(&file_name, "mcusr", SCRIPT_SUFFIX);
message (1, MSG_ERROR, _(" Can't generate unique filename \n %s "),
unix_error_string (errno));
return;
}
#ifdef OS2_NT if (cmd_file_fd == -1){
/* OS/2 and NT requires the command to end in .cmd */
p = file_name;
file_name = g_strconcat (file_name, ".cmd", NULL);
free (p);
#endif
if ((cmd_file_fd = open (file_name, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600)) == -1){
message (1, MSG_ERROR, _(" Can't create temporary command file \n %s "), message (1, MSG_ERROR, _(" Can't create temporary command file \n %s "),
unix_error_string (errno)); unix_error_string (errno));
free (file_name); free (file_name);

Просмотреть файл

@ -1272,3 +1272,96 @@ concat_dir_and_file (const char *dir, const char *file)
return g_strconcat (dir, PATH_SEP_STR, file, NULL); return g_strconcat (dir, PATH_SEP_STR, file, NULL);
} }
/* Following code heavily borrows from libiberty, mkstemps.c */
/* Use 64-bit "enthropy" if available */
#ifdef __GNUC__
__extension__ typedef unsigned long long gcc_uint64_t;
#else
typedef unsigned long gcc_uint64_t;
#endif
/* Number of attempts to create a temporary file */
#ifndef TMP_MAX
#define TMP_MAX 16384
#endif
/*
* Arguments:
* pname - if not NULL, put the filename here.
* prefix - filename only, temporary directory is prepended.
* suffix - if not NULL, appended after the random part.
*
* Result:
* handle of the open file or -1 if couldn't open any.
*/
int mc_mkstemps(char **pname, const char *prefix, const char *suffix)
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
static gcc_uint64_t value;
struct timeval tv;
char *tmpdir;
char *tmpbase;
char *tmpname;
char *XXXXXX;
int count;
tmpdir = getenv("TMPDIR");
if (!tmpdir) {
tmpdir = TMPDIR_DEFAULT;
}
/* Add prefix first to find the position of XXXXXX */
tmpbase = concat_dir_and_file (tmpdir, prefix);
tmpname = g_strconcat (tmpbase, "XXXXXX", suffix, NULL);
if (pname)
*pname = tmpname;
XXXXXX = &tmpname[strlen (tmpbase)];
g_free(tmpbase);
/* Get some more or less random data. */
gettimeofday (&tv, NULL);
value += (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];
fd = open (tmpname, O_RDWR|O_CREAT|O_EXCL, 0600);
if (fd >= 0) {
/* Successfully created. */
if (!pname)
g_free (tmpname);
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.
Of course, only if the caller wants any string. */
if (!pname)
g_free (tmpname);
else
tmpname[0] = '\0';
return -1;
}

Просмотреть файл

@ -146,6 +146,10 @@ void remove_dash (void);
extern char app_text []; extern char app_text [];
/* Creating temporary files safely */
void init_tmpdir(void);
int mc_mkstemps(char **pname, const char *prefix, const char *suffix);
enum { enum {
ISGUNZIPABLE_GUNZIP, ISGUNZIPABLE_GUNZIP,
ISGUNZIPABLE_BZIP, ISGUNZIPABLE_BZIP,
@ -179,6 +183,8 @@ int max_open_files (void);
# define PATH_SEP '\\' # define PATH_SEP '\\'
# define PATH_SEP_STR "\\" # define PATH_SEP_STR "\\"
# define PATH_ENV_SEP ';' # define PATH_ENV_SEP ';'
# define TMPDIR_DEFAULT "c:\\temp"
# define SCRIPT_SUFFIX ".cmd"
# define OS_SORT_CASE_SENSITIVE_DEFAULT 0 # define OS_SORT_CASE_SENSITIVE_DEFAULT 0
# define STRCOMP stricmp # define STRCOMP stricmp
# define STRNCOMP strnicmp # define STRNCOMP strnicmp
@ -190,6 +196,8 @@ int max_open_files (void);
# define PATH_SEP '/' # define PATH_SEP '/'
# define PATH_SEP_STR "/" # define PATH_SEP_STR "/"
# define PATH_ENV_SEP ':' # define PATH_ENV_SEP ':'
# define TMPDIR_DEFAULT "/tmp"
# define SCRIPT_SUFFIX ""
# define get_default_editor() "vi" # define get_default_editor() "vi"
# define OS_SORT_CASE_SENSITIVE_DEFAULT 1 # define OS_SORT_CASE_SENSITIVE_DEFAULT 1
# define STRCOMP strcmp # define STRCOMP strcmp

Просмотреть файл

@ -1,3 +1,16 @@
2001-05-21 Pavel Roskin <proski@gnu.org>
* vfs/direntry.c (vfs_s_open): Use mc_mkstemps. Create and close
temporary file to reserve its name on the filesystem.
(vfs_s_retrieve_file): Use mc_mkstemps().
(g_tempnam): Remove.
* vfs/extfs.c (extfs_open): Use mc_mkstemps().
* vfs/sfs.c (redirect): Likewise.
* vfs/shared_ftp_fish.c (_get_file_entry): Likewise.
(retrieve_file): Likewise.
* vfs/vfs.c (mc_def_getlocalcopy): Likewise.
* vfs/xdirentry.h: Remove declaration of g_tempnam().
2001-05-18 Pavel Roskin <proski@gnu.org> 2001-05-18 Pavel Roskin <proski@gnu.org>
* vfs.c (vfs_addstamp): Rename st1 to last_stamp. Initialize it * vfs.c (vfs_addstamp): Rename st1 to last_stamp. Initialize it
@ -921,7 +934,7 @@ Wed Apr 21 21:59:50 1999 Norbert Warmuth <nwarmuth@privat.circular.de>
1999-03-31 Serge Winitzki <swinitzk@hotmail.com> 1999-03-31 Serge Winitzki <swinitzk@hotmail.com>
* added copy_in capability to mtools filesystem * added copy_in capability to mtools filesystem
1999-03-30 Federico Mena Quintero <federico@nuclecu.unam.mx> 1999-03-30 Federico Mena Quintero <federico@nuclecu.unam.mx>
@ -975,7 +988,7 @@ Mon Mar 22 02:00:16 1999 Valery Kornienkov <vlk@st.simbirsk.su>
1999-03-09 Shooby Ban <bansz@szif.hu> 1999-03-09 Shooby Ban <bansz@szif.hu>
* extfs/extfs.ini: Corrected rpms -> rpms: * extfs/extfs.ini: Corrected rpms -> rpms:
by Balazs Nagy <julian7@kva.hu> by Balazs Nagy <julian7@kva.hu>
1999-03-09 Miguel de Icaza <miguel@nuclecu.unam.mx> 1999-03-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
@ -1871,8 +1884,8 @@ Fri Jan 23 07:27:37 1998 Peter Daum <gator@cs.tu-berlin.de>
1997-12-21 Yuri Kuzmenko <Yuri.Kuzmenko@f169.n463.z2.fidonet.org> 1997-12-21 Yuri Kuzmenko <Yuri.Kuzmenko@f169.n463.z2.fidonet.org>
* tar.c: fix the bug which core dumps when trying to view tar file * tar.c: fix the bug which core dumps when trying to view tar file
with many files (over 60000). with many files (over 60000).
Mon Jul 21 18:47:37 1997 Miguel de Icaza <miguel@athena.nuclecu.unam.mx> Mon Jul 21 18:47:37 1997 Miguel de Icaza <miguel@athena.nuclecu.unam.mx>
@ -1888,9 +1901,9 @@ Mon Jun 9 19:00:30 1997 Norbert Warmuth <k3190@fh-sw.de>
* vfs/vfs.c (vfs_canon): Fix for the 'cd a:/somedir/..' problem * vfs/vfs.c (vfs_canon): Fix for the 'cd a:/somedir/..' problem
* vfs/vfs.c (vfs_add_non_current_stamps): when leaving a mtools fs * vfs/vfs.c (vfs_add_non_current_stamps): when leaving a mtools fs
free the extfs buffers immediatly instead of waiting for the vfs- free the extfs buffers immediatly instead of waiting for the vfs-
timeout timeout
Thu May 29 14:50:41 1997 Miguel de Icaza <miguel@athena.nuclecu.unam.mx> Thu May 29 14:50:41 1997 Miguel de Icaza <miguel@athena.nuclecu.unam.mx>
@ -1927,9 +1940,9 @@ Mon Mar 17 12:03:50 1997 Norbert Warmuth <k3190@fh-sw.de>
* configure.in (--with-hsc): fix. * configure.in (--with-hsc): fix.
* vfs/ftpfs.c (ftpfs_get_proxy_host_and_port): Fixed wrong parameter * vfs/ftpfs.c (ftpfs_get_proxy_host_and_port): Fixed wrong parameter
passing (HSC_DEFAULT_PORT was passed as pointer to char instead of passing (HSC_DEFAULT_PORT was passed as pointer to char instead of
passing it as integer) passing it as integer)
Tue Feb 25 20:21:00 1997 Joseph M. Hinkle <jhinkle@rockisland.com> Tue Feb 25 20:21:00 1997 Joseph M. Hinkle <jhinkle@rockisland.com>

Просмотреть файл

@ -754,6 +754,7 @@ vfs_s_open (vfs *me, char *file, int flags, int mode)
char *dirname, *name, *save; char *dirname, *name, *save;
vfs_s_entry *ent; vfs_s_entry *ent;
vfs_s_inode *dir; vfs_s_inode *dir;
int tmp_handle;
if (!(flags & O_CREAT)) if (!(flags & O_CREAT))
return NULL; return NULL;
@ -766,7 +767,10 @@ vfs_s_open (vfs *me, char *file, int flags, int mode)
ent = vfs_s_generate_entry (me, name, dir, 0755); ent = vfs_s_generate_entry (me, name, dir, 0755);
ino = ent->ino; ino = ent->ino;
vfs_s_insert_entry (me, dir, ent); vfs_s_insert_entry (me, dir, ent);
ino->localname = g_tempnam (NULL, me->name); tmp_handle = mc_mkstemps (&ino->localname, me->name, NULL);
if (tmp_handle == -1)
return NULL;
close (tmp_handle);
was_changed = 1; was_changed = 1;
} }
@ -935,9 +939,8 @@ vfs_s_retrieve_file(vfs *me, struct vfs_s_inode *ino)
memset(&fh, 0, sizeof(fh)); memset(&fh, 0, sizeof(fh));
fh.ino = ino; fh.ino = ino;
if (!(ino->localname = g_tempnam (NULL, me->name))) ERRNOR (ENOMEM, 0);
handle = open(ino->localname, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600); handle = mc_mkstemps (&ino->localname, me->name, NULL);
if (handle == -1) { if (handle == -1) {
me->verrno = errno; me->verrno = errno;
goto error_4; goto error_4;
@ -1185,20 +1188,3 @@ vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd)
buffer [size-1] = 0; buffer [size-1] = 0;
return 0; return 0;
} }
/* Roland: on most non-GNU/Linux platforms malloc()!=g_malloc() which
* may cause crashes. This wrapper ensures that memory from tempnam
* can safely free'ed with g_free()
*/
char *
g_tempnam( const char *dir, const char *prefix )
{
char *tmp = (char *)tempnam( dir, prefix );
char *name;
name = g_strdup( tmp );
free( tmp );
return( name );
}

Просмотреть файл

@ -603,11 +603,10 @@ static void *extfs_open (vfs *me, char *file, int flags, int mode)
char *cmd; char *cmd;
char *archive_name, *p; char *archive_name, *p;
entry->inode->local_filename = g_tempnam (NULL, "extfs");
{ {
int handle; int handle;
handle = mc_mkstemps (&entry->inode->local_filename, "extfs", NULL);
handle = open(entry->inode->local_filename, O_RDWR | O_CREAT | O_EXCL, 0600);
if (handle == -1) if (handle == -1)
return NULL; return NULL;
close(handle); close(handle);

Просмотреть файл

@ -126,8 +126,8 @@ redirect (vfs *me, char *name)
cur = cur->next; cur = cur->next;
} }
cache = tempnam (NULL, "sfs"); handle = mc_mkstemps (&cache, "sfs", NULL);
handle = open (cache, O_RDWR | O_CREAT | O_EXCL, 0600);
if (handle == -1) { if (handle == -1) {
g_free (cache); g_free (cache);
return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US"; return "/SOMEONE_PLAYING_DIRTY_TMP_TRICKS_ON_US";

Просмотреть файл

@ -330,9 +330,7 @@ _get_file_entry(struct connection *bucket, char *file_name,
ent->local_filename = NULL; ent->local_filename = NULL;
} }
if (flags & O_TRUNC) { if (flags & O_TRUNC) {
ent->local_filename = g_tempnam (NULL, X "fs"); handle = mc_mkstemps (&ent->local_filename, X "fs", NULL);
if (ent->local_filename == NULL) ERRNOR (ENOMEM, NULL);
handle = open(ent->local_filename, O_CREAT | O_TRUNC | O_RDWR | O_EXCL, 0600);
if (handle < 0) ERRNOR (EIO, NULL); if (handle < 0) ERRNOR (EIO, NULL);
close(handle); close(handle);
if (stat (ent->local_filename, &ent->local_stat) < 0) if (stat (ent->local_filename, &ent->local_stat) < 0)
@ -368,12 +366,8 @@ _get_file_entry(struct connection *bucket, char *file_name,
ent->bucket = bucket; ent->bucket = bucket;
ent->name = g_strdup(p); ent->name = g_strdup(p);
ent->remote_filename = g_strdup(file_name); ent->remote_filename = g_strdup(file_name);
ent->local_filename = g_tempnam (NULL, X "fs");
if (!ent->name || !ent->remote_filename || !ent->local_filename) { handle = mc_mkstemps (&ent->local_filename, X "fs", NULL);
direntry_destructor(ent);
ERRNOR (ENOMEM, NULL);
}
handle = open (ent->local_filename, O_CREAT | O_EXCL | O_RDWR | O_TRUNC, 0700);
if (handle == -1) { if (handle == -1) {
my_errno = EIO; my_errno = EIO;
goto error; goto error;
@ -841,10 +835,9 @@ static int retrieve_file(struct direntry *fe)
if (fe->local_filename) if (fe->local_filename)
return 1; return 1;
if (!(fe->local_filename = g_tempnam (NULL, X))) ERRNOR (ENOMEM, 0);
fe->local_is_temp = 1; fe->local_is_temp = 1;
local_handle = open(fe->local_filename, O_RDWR | O_CREAT | O_TRUNC | O_EXCL, 0600); local_handle = mc_mkstemps (&fe->local_filename, X, NULL);
if (local_handle == -1) { if (local_handle == -1) {
my_errno = EIO; my_errno = EIO;
goto error_4; goto error_4;

Просмотреть файл

@ -1062,8 +1062,8 @@ mc_def_getlocalcopy (vfs *vfs, char *filename)
fdin = mc_open (filename, O_RDONLY); fdin = mc_open (filename, O_RDONLY);
if (fdin == -1) if (fdin == -1)
return NULL; return NULL;
tmp = g_tempnam (NULL, "mclocalcopy");
fdout = open (tmp, O_CREAT|O_WRONLY|O_TRUNC|O_EXCL, 0600); fdout = mc_mkstemps (&tmp, "mclocalcopy", NULL);
if (fdout == -1) if (fdout == -1)
goto fail; goto fail;
while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0){ while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0){

Просмотреть файл

@ -254,8 +254,6 @@ int vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd);
/* misc */ /* misc */
int vfs_s_retrieve_file (vfs *me, struct vfs_s_inode *ino); int vfs_s_retrieve_file (vfs *me, struct vfs_s_inode *ino);
/* alloc temp name which can be safely free'd with g_free() */
char *g_tempnam( const char *dir, const char *prefix );
#if 0 #if 0
/* If non-null, FREE */ /* If non-null, FREE */