ALT Linux Team development discussions
 help / color / mirror / Atom feed
* [devel] Нужно ли вызывать endpwent() после использования getpwuid() ?
@ 2007-02-26 13:32 Slava Semushin
  2007-02-26 13:44 ` Mikhail Gusarov
  0 siblings, 1 reply; 5+ messages in thread
From: Slava Semushin @ 2007-02-26 13:32 UTC (permalink / raw)
  To: ALT Devel discussion list

Здравствуйте!

Листал тут на работе книжку от O'Reilly "Secure Programming Book for C
and C++" и увидел такой пример:

%%
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>

int main(int argc, char *argv[]) {
  uid_t uid;
  struct passwd *pwd;

  uid = getuid();
  printf("User's UID is %d.\n", (int)uid);
  if ( ! (pwd = getpwuid(uid))) {
    printf("Unable to get user's password file record!\n");
    endpwent();
    return 1;
  }

  printf("User's home directory is %s\n", pwd->pw_dir);
  endpwent();

  return 0;
}
%%

Собственно, привлёк внимание факт вызова endpwent(). Почитал ман к
Линуксу, к Нетке, ещё каких-то в интернете и не очень понял,
действительно ли нужно после вызова getpwuid() вызывать endpwent().

Пожалуйста, разъясните этот момент, ведь если я правильно понял, то
невызов endpwent() чреват утечкой файлового дескриптора.

Заранее спасибо!

-- 
+ Slava Semushin | slava.semushin @ gmail.com
+ ALT Linux Team | php-coder @ altlinux.ru

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-02-26 13:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-26 13:32 [devel] Нужно ли вызывать endpwent() после использования getpwuid() ? Slava Semushin
2007-02-26 13:44 ` Mikhail Gusarov
2007-02-26 13:49   ` Damir Shayhutdinov
2007-02-26 13:52   ` [devel] [SUMMARY][OFF]Re: " Slava Semushin
2007-02-26 13:56   ` [devel] " Dmitry V. Levin

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