emacs-devel
[Top][All Lists]
Advanced

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

Using a temp file from emacs C code


From: Cecilio Pardo
Subject: Using a temp file from emacs C code
Date: Sun, 27 Oct 2024 01:33:30 +0200
User-agent: Mozilla Thunderbird

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 via email to

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