unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Cecilio Pardo <cpardo@imayhem.com>
To: emacs-devel <emacs-devel@gnu.org>
Subject: Using a temp file from emacs C code
Date: Sun, 27 Oct 2024 01:33:30 +0200	[thread overview]
Message-ID: <1074f1ac-3ac4-4d91-9aec-8d86f3afba2a@imayhem.com> (raw)

Hello,

How should I create and use a temp file from emacs' C code?

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
- Call lisp function delete-file (funcall)

   const char *prefix = "prefix";
   Lisp_Object tmp_file =
     CALLN (Ffuncall,
	   intern_c_string ("make-temp-file"),
	   make_string (prefix, strlen (prefix)),
	   Qnil, Qnil, Qnil);
   tmp_file = ENCODE_FILE (tmp_file);
   WCHAR wide_filename[MAX_PATH];
   filename_to_utf16 (SDATA (tmp_file), wide_filename);

   // write things to the file..., then read back:
	
   FILE *fp = emacs_fopen (SDATA (tmp_file), "rb");
   if (fp != NULL)
     {
       // ...
       fclose (fp);
     }

   CALLN (Ffuncall, intern_c_string("delete-file"), tmp_file, Qnil);



Thanks.



             reply	other threads:[~2024-10-26 23:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-26 23:33 Cecilio Pardo [this message]
2024-10-27  6:17 ` Using a temp file from emacs C code Eli Zaretskii
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

  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=1074f1ac-3ac4-4d91-9aec-8d86f3afba2a@imayhem.com \
    --to=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 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).