From: Eli Zaretskii <eliz@gnu.org>
To: Cecilio Pardo <cpardo@imayhem.com>
Cc: emacs-devel@gnu.org
Subject: Re: Using a temp file from emacs C code
Date: Sun, 27 Oct 2024 08:17:38 +0200 [thread overview]
Message-ID: <867c9uax31.fsf@gnu.org> (raw)
In-Reply-To: <1074f1ac-3ac4-4d91-9aec-8d86f3afba2a@imayhem.com> (message from Cecilio Pardo on Sun, 27 Oct 2024 01:33:30 +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.)
next prev parent reply other threads:[~2024-10-27 6:17 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 [this message]
2024-10-27 8:22 ` Cecilio Pardo
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=867c9uax31.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=cpardo@imayhem.com \
--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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.