From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Cecilio Pardo Newsgroups: gmane.emacs.devel Subject: Using a temp file from emacs C code Date: Sun, 27 Oct 2024 01:33:30 +0200 Message-ID: <1074f1ac-3ac4-4d91-9aec-8d86f3afba2a@imayhem.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25555"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Oct 27 01:34:31 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1t4qIg-0006Wk-RL for ged-emacs-devel@m.gmane-mx.org; Sun, 27 Oct 2024 01:34:30 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t4qHs-0006qb-KH; Sat, 26 Oct 2024 19:33:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t4qHp-0006q8-Tn for emacs-devel@gnu.org; Sat, 26 Oct 2024 19:33:37 -0400 Original-Received: from mail.imayhem.com ([82.223.54.191] helo=zealous-pike.82-223-54-191.plesk.page) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1t4qHn-0007SY-JI for emacs-devel@gnu.org; Sat, 26 Oct 2024 19:33:37 -0400 Original-Received: from [192.168.68.104] (111.red-88-21-7.staticip.rima-tde.net [88.21.7.111]) by zealous-pike.82-223-54-191.plesk.page (Postfix) with ESMTPSA id B9E2C80100 for ; Sat, 26 Oct 2024 23:33:30 +0000 (UTC) Authentication-Results: zealous-pike.82-223-54-191.plesk.page; spf=pass (sender IP is 88.21.7.111) smtp.mailfrom=cpardo@imayhem.com smtp.helo=[192.168.68.104] Received-SPF: pass (zealous-pike.82-223-54-191.plesk.page: connection is authenticated) Content-Language: es-ES Received-SPF: pass client-ip=82.223.54.191; envelope-from=cpardo@imayhem.com; helo=zealous-pike.82-223-54-191.plesk.page X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:324862 Archived-At: 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.