From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Using a temp file from emacs C code Date: Sun, 27 Oct 2024 08:17:38 +0200 Message-ID: <867c9uax31.fsf@gnu.org> References: <1074f1ac-3ac4-4d91-9aec-8d86f3afba2a@imayhem.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17763"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Cecilio Pardo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Oct 27 07:18:43 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 1t4wbq-0004WO-E5 for ged-emacs-devel@m.gmane-mx.org; Sun, 27 Oct 2024 07:18:42 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t4waw-0003i6-N4; Sun, 27 Oct 2024 02:17:46 -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 1t4wat-0003h0-Mq for emacs-devel@gnu.org; Sun, 27 Oct 2024 02:17:43 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t4was-0003f1-Q9; Sun, 27 Oct 2024 02:17:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=asEj0bZDVGYl9+HXMB6JAhi+FOEXiVdbX94kKdLpOX0=; b=djEWf92B5bTB DuAU6FVu9EA8jgmC9TpaOKk+fRqys3BxOj/QWVkTthffT6ifX2KmAfvqAOlZNMsTrNMyRIBlJCQfA HjaBspsQj3TwHHtd3aol7UnBzDuET70K8hTdnV6GGZoumfG9BJQzkpKF3C+o1+ZUH6UHlbRPpd6hA sREhXTWREVmmg/YnHudEmKmnl9XTmWgl08lnuWvcm90LQ/0POmj2lDUDjFp0MJ+UMFKUiO4fGYOg3 +Ba4VlfxFV8/x26Hv8fOT9g8Tb/N5bFYG8Gl1AtNGYBFeUUf+ojfeAGWBuRIHVUAvYGY+YJ9jKAL8 sjLG9UYpsLtoHmFR58VVSw==; In-Reply-To: <1074f1ac-3ac4-4d91-9aec-8d86f3afba2a@imayhem.com> (message from Cecilio Pardo on Sun, 27 Oct 2024 01:33:30 +0200) 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:324867 Archived-At: > Date: Sun, 27 Oct 2024 01:33:30 +0200 > From: Cecilio Pardo > > 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.)