ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: Stanislav Ievlev <inger@altlinux.org>
To: devel@altlinux.ru
Subject: Re: [devel] I: temporary file handling: C coding guideline
Date: Tue, 3 Jun 2003 13:15:06 +0400
Message-ID: <20030603091506.GB12966@basalt.office.altlinux.org> (raw)
In-Reply-To: <20030603081729.GB13299@basalt.office.altlinux.org>

On Tue, Jun 03, 2003 at 12:17:29PM +0400, Dmitry V. Levin wrote:
> Greetings!
> 
> Я планирую добавить "C coding guideline" в дополнение к нынешнему shell
> coding guideline из SPP:
> 
> #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;
> 
> Комментарии приветствуются.
Хочется man-page по asprintf.
Я тут не очень понял про коды возврата.
0 это тоже будет ошибкой в данном случае?

Ещё надо бы наверное portable вариант без gcc-змов. Это потребуется всем
мантейнерам которые захотят убедить авторов в своём патче.
> 
> 
> --
> ldv




  reply	other threads:[~2003-06-03  9:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-03  8:17 Dmitry V. Levin
2003-06-03  9:15 ` Stanislav Ievlev [this message]
2003-06-10 23:14 ` [devel] temporary file handling: questions Grigory Batalov
2003-06-10 23:32   ` 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=20030603091506.GB12966@basalt.office.altlinux.org \
    --to=inger@altlinux.org \
    --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