unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Using a temp file from emacs C code
@ 2024-10-26 23:33 Cecilio Pardo
  2024-10-27  6:17 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Cecilio Pardo @ 2024-10-26 23:33 UTC (permalink / raw)
  To: emacs-devel

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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-27  8:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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).