*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->OpenBSD man pages -> pw_dup (3)              
Title
Content
Arch
Section
 

PW_DUP(3)

Contents


NAME    [Toc]    [Back]

     pw_dup - make a copy of a struct passwd

SYNOPSIS    [Toc]    [Back]

     #include <pwd.h>

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

DESCRIPTION    [Toc]    [Back]

     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 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    [Toc]    [Back]

     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.0);
                   exit(1);
           }
           if ((pw_save = pw_dup(pw)) == NULL) {
                   fprintf(stderr, "Out of memory.0);
                   exit(1);
           }

ERRORS    [Toc]    [Back]

     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    [Toc]    [Back]

      
      
     free(3), getpwent(3), malloc(3)

HISTORY    [Toc]    [Back]

     The pw_dup() function first appeared in OpenBSD 2.9.

OpenBSD      3.6                        November     15,     2000
[ Back ]
 Similar pages
Name OS Title
acl_dup IRIX make a copy of an ACL
cap_dup IRIX make a copy of a capability
acl_from_text IRIX convert a POSIX ACL string to a struct acl or a struct acl to a POSIX ACL string
uiomove NetBSD move data described by a struct uio
uio OpenBSD move data described by a struct uio
uiomove OpenBSD move data described by a struct uio
realhostname_sa FreeBSD convert a struct sockaddr to the real host name
Class::Struct IRIX declare struct-like datatypes as Perl classes
scp FreeBSD secure copy (remote file copy program)
scp OpenBSD secure copy (remote file copy program)
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service