emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using a temp file from emacs C code


From: Eli Zaretskii
Subject: Re: Using a temp file from emacs C code
Date: Sun, 27 Oct 2024 08:17:38 +0200

> Date: Sun, 27 Oct 2024 01:33:30 +0200
> From: Cecilio Pardo <cpardo@imayhem.com>
> 
> How should I create and use a temp file from emacs' C code?

By first trying to avoid it, and do it from Lisp instead ;-)

But if you absolutely have no other way, then...

> I got this working but it doesn't look right:
> 
> - Call lisp function make-temp-file, trough funcall
> - Convert the returned string to utf-16 (because of Windows)
> - Then to read the file use emacs_fopen

I don't understand: if you create the file, why do you need to read it
back? why not simply pass whatever you write to the file to the code
which needs to read it, as a string or a temp buffer?

Anyway, you could use Fmake_temp_file_internal instead.  You can see
an example of that in the implementation of native-elisp-load.  And
for reading a file (if you really need it; see above) use
Finsert_file_contents, it will handle the issues with encoding the
file name etc. for you.  (But beware of hidden rocks if you do this in
code that needs to be run early during Emacs bootstrap.)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]