files: add the original file's suffix to the name of a temporary file
This allows 'aspell' to recognize a C file and thus spell check only the comments and strings. This fulfills https://savannah.gnu.org/bugs/?61056.master
parent
083bbae0e4
commit
f429ebe34d
13
src/files.c
13
src/files.c
|
@ -1451,6 +1451,7 @@ char *safe_tempfile(FILE **stream)
|
||||||
{
|
{
|
||||||
const char *env_dir = getenv("TMPDIR");
|
const char *env_dir = getenv("TMPDIR");
|
||||||
char *tempdir = NULL, *tempfile_name = NULL;
|
char *tempdir = NULL, *tempfile_name = NULL;
|
||||||
|
char *extension;
|
||||||
int descriptor;
|
int descriptor;
|
||||||
|
|
||||||
/* Get the absolute path for the first directory among $TMPDIR
|
/* Get the absolute path for the first directory among $TMPDIR
|
||||||
|
@ -1464,10 +1465,16 @@ char *safe_tempfile(FILE **stream)
|
||||||
if (tempdir == NULL)
|
if (tempdir == NULL)
|
||||||
tempdir = copy_of("/tmp/");
|
tempdir = copy_of("/tmp/");
|
||||||
|
|
||||||
tempfile_name = nrealloc(tempdir, strlen(tempdir) + 12);
|
extension = strrchr(openfile->filename, '.');
|
||||||
strcat(tempfile_name, "nano.XXXXXX");
|
|
||||||
|
|
||||||
descriptor = mkstemp(tempfile_name);
|
if (!extension)
|
||||||
|
extension = openfile->filename + strlen(openfile->filename);
|
||||||
|
|
||||||
|
tempfile_name = nrealloc(tempdir, strlen(tempdir) + 12 + strlen(extension));
|
||||||
|
strcat(tempfile_name, "nano.XXXXXX");
|
||||||
|
strcat(tempfile_name, extension);
|
||||||
|
|
||||||
|
descriptor = mkstemps(tempfile_name, strlen(extension));
|
||||||
|
|
||||||
*stream = (descriptor > 0) ? fdopen(descriptor, "r+b") : NULL;
|
*stream = (descriptor > 0) ? fdopen(descriptor, "r+b") : NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue