From: Cecilio Pardo <cpardo@imayhem.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Using a temp file from emacs C code
Date: Sun, 27 Oct 2024 09:22:53 +0100 [thread overview]
Message-ID: <fa328fa2-8318-40d8-9540-276a24924e4b@imayhem.com> (raw)
In-Reply-To: <867c9uax31.fsf@gnu.org>
On 27/10/2024 7:17, Eli Zaretskii wrote:
>> 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 promise.
>> 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?
Sorry, I oversimplified. I'm calling a winapi function that writes the file.
> 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.)
Thanks. Not this time.
prev parent reply other threads:[~2024-10-27 8:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-26 23:33 Using a temp file from emacs C code Cecilio Pardo
2024-10-27 6:17 ` Eli Zaretskii
2024-10-27 8:22 ` Cecilio Pardo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fa328fa2-8318-40d8-9540-276a24924e4b@imayhem.com \
--to=cpardo@imayhem.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).