From: Grigory Batalov <bga@altlinux.ru>
To: devel@altlinux.ru
Subject: [devel] temporary file handling: questions
Date: Wed, 11 Jun 2003 03:14:59 +0400
Message-ID: <20030611031459.3c410e3a.bga@altlinux.ru> (raw)
In-Reply-To: <20030603081729.GB13299@basalt.office.altlinux.org>
On Tue, 3 Jun 2003 12:17:29 +0400
"Dmitry V. Levin" <ldv@altlinux.org> wrote:
> #define _GNU_SOURCE
>
> #include <stdio.h>
> #include <error.h>
> #include <errno.h>
> #include <stdlib.h>
> #include <unistd.h>
>
> ...
> char *fname;
> int fd;
> FILE *fp;
>
> if (asprintf (&fname, "%s/progname.XXXXXX", getenv ("TMPDIR") ?: P_tmpdir) < 0)
> error (EXIT_FAILURE, errno, "asprintf");
>
> if ((fd = mkstemp (fname)) < 0)
> error (EXIT_FAILURE, errno, "mkstemp: %s", fname);
>
> if (unlink (fname) < 0)
> error (EXIT_FAILURE, errno, "unlink: %s", fname);
>
> if ((fp = fdopen (fd, "w+")) == NULL)
> error (EXIT_FAILURE, errno, "fdopen: %s", fname);
>
> ...
>
> if (fclose (fp))
> error (EXIT_FAILURE, errno, "fclose: %s", fname);
>
> free (fname);
> fname = NULL;
>
> Комментарии приветствуются.
Если я правильно понимаю, fdopen/fclose используются, чтобы
"занять" файловый дескриптор потоком и предотвратить
немедленное удаление функцией unlink?
Или fdopen/fclose приведены для примера потокового
ввода/вывода, и их можно опустить (например, мне достаточно
open/close)? В этом случае "оттягивать до последнего"
нужно вызов close(fd) ?
next prev parent reply other threads:[~2003-06-10 23:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-03 8:17 [devel] I: temporary file handling: C coding guideline Dmitry V. Levin
2003-06-03 9:15 ` Stanislav Ievlev
2003-06-10 23:14 ` Grigory Batalov [this message]
2003-06-10 23:32 ` [devel] temporary file handling: questions Dmitry V. Levin
2003-06-11 7:31 ` Alexey I. Froloff
2003-06-11 8:19 ` Dmitry V. Levin
2003-06-13 10:30 ` Alexey I. Froloff
2003-06-11 8:31 ` Stanislav Ievlev
2003-06-11 14:14 ` [devel] " Alexey Tourbin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030611031459.3c410e3a.bga@altlinux.ru \
--to=bga@altlinux.ru \
--cc=devel@altlinux.ru \
/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
ALT Linux Team development discussions
This inbox may be cloned and mirrored by anyone:
git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
public-inbox-index devel
Example config snippet for mirrors.
Newsgroup available over NNTP:
nntp://lore.altlinux.org/org.altlinux.lists.devel
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git