pw_dup man page on OpenBSD

Man page or keyword search:  
man Server   11362 pages
apropos Keyword Search (all sections)
Output format
OpenBSD logo
[printable version]

PW_DUP(3)		  OpenBSD Programmer's Manual		     PW_DUP(3)

NAME
     pw_dup - make a copy of a struct passwd

SYNOPSIS
     #include <pwd.h>

     struct passwd *
     pw_dup(const struct passwd *pw);

DESCRIPTION
     The pw_dup() function allocates sufficient memory for a copy of the
     struct passwd pw, does the copy, and returns a pointer to it.  This is
     useful as subsequent calls to getpwent(), getpwnam(), and getpwuid() will
     overwrite the data they returned from previous calls.

     The returned pointer may be deallocated by a single call to free(3).
     Since pw_dup() allocates space for the copy in one chunk, it is not
     necessary to free the individual strings contained in the returned struct
     passwd.

     If insufficient memory is available, NULL is returned.

EXAMPLES
     The following will make a copy of the struct passwd for root and store it
     in "pw_save":

	   struct passwd *pw, *pw_save;

	   if ((pw = getpwnam("root")) == NULL) {
		   fprintf(stderr, "Cannot find root in the password file.\n");
		   exit(1);
	   }
	   if ((pw_save = pw_dup(pw)) == NULL) {
		   fprintf(stderr, "Out of memory.\n");
		   exit(1);
	   }

ERRORS
     pw_dup() function may fail and set the external variable errno for any of
     the errors specified for the library function malloc(3).

SEE ALSO
     free(3), getpwent(3), malloc(3)

HISTORY
     The pw_dup() function first appeared in OpenBSD 2.9.

OpenBSD 4.9			 May 31, 2007			   OpenBSD 4.9
[top]

List of man pages available for OpenBSD

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net