mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-23 04:46:55 +03:00
* vfs.c (mc_def_getlocalcopy): Preserve existing extension.
This commit is contained in:
parent
7f923cc9c0
commit
b1dbe77c5b
@ -1,5 +1,7 @@
|
||||
2002-08-15 Pavel Roskin <proski@gnu.org>
|
||||
|
||||
* vfs.c (mc_def_getlocalcopy): Preserve existing extension.
|
||||
|
||||
* direntry.c (vfs_s_getlocalcopy): Fix potentially dangerous
|
||||
strcpy().
|
||||
|
||||
|
15
vfs/vfs.c
15
vfs/vfs.c
@ -1090,12 +1090,25 @@ mc_def_getlocalcopy (vfs *vfs, char *filename)
|
||||
int fdin, fdout, i;
|
||||
char buffer[8192];
|
||||
struct stat mystat;
|
||||
char *ext = NULL;
|
||||
char *ptr;
|
||||
|
||||
fdin = mc_open (filename, O_RDONLY);
|
||||
if (fdin == -1)
|
||||
return NULL;
|
||||
|
||||
fdout = mc_mkstemps (&tmp, "mclocalcopy", NULL);
|
||||
/* Try to preserve existing extension */
|
||||
for (ptr = filename + strlen(filename) - 1; ptr >= filename; ptr--) {
|
||||
if (*ptr == '.') {
|
||||
ext = ptr;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isalnum((unsigned char) *ptr))
|
||||
break;
|
||||
}
|
||||
|
||||
fdout = mc_mkstemps (&tmp, "mclocalcopy", ext);
|
||||
if (fdout == -1)
|
||||
goto fail;
|
||||
while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0){
|
||||
|
Loading…
Reference in New Issue
Block a user