1LCHOWN(3P)                 POSIX Programmer's Manual                LCHOWN(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       lchown — change the owner and group of a symbolic link
13

SYNOPSIS

15       #include <unistd.h>
16
17       int lchown(const char *path, uid_t owner, gid_t group);
18

DESCRIPTION

20       The lchown() function shall be equivalent to  chown(),  except  in  the
21       case  where  the  named file is a symbolic link. In this case, lchown()
22       shall change the ownership of the  symbolic  link  file  itself,  while
23       chown()  changes  the  ownership  of the file or directory to which the
24       symbolic link refers.
25

RETURN VALUE

27       Upon successful completion, lchown()  shall  return  0.  Otherwise,  it
28       shall return -1 and set errno to indicate an error.
29

ERRORS

31       The lchown() function shall fail if:
32
33       EACCES Search permission is denied on a component of the path prefix of
34              path.
35
36       EINVAL The owner or group ID is not a value supported by the  implemen‐
37              tation.
38
39       ELOOP  A loop exists in symbolic links encountered during resolution of
40              the path argument.
41
42       ENAMETOOLONG
43              The  length  of  a  component  of  a  pathname  is  longer  than
44              {NAME_MAX}.
45
46       ENOENT A component of path does not name an existing file or path is an
47              empty string.
48
49       ENOTDIR
50              A component of the path prefix names an existing  file  that  is
51              neither  a  directory nor a symbolic link to a directory, or the
52              path argument contains at least one  non-<slash>  character  and
53              ends  with  one or more trailing <slash> characters and the last
54              pathname component names an existing  file  that  is  neither  a
55              directory nor a symbolic link to a directory.
56
57       EPERM  The  effective  user ID does not match the owner of the file and
58              the process does not have appropriate privileges.
59
60       EROFS  The file resides on a read-only file system.
61
62       The lchown() function may fail if:
63
64       EIO    An I/O error occurred while reading or writing to the file  sys‐
65              tem.
66
67       EINTR  A signal was caught during execution of the function.
68
69       ELOOP  More  than  {SYMLOOP_MAX} symbolic links were encountered during
70              resolution of the path argument.
71
72       ENAMETOOLONG
73              The length of a pathname exceeds {PATH_MAX}, or pathname resolu‐
74              tion  of  a symbolic link produced an intermediate result with a
75              length that exceeds {PATH_MAX}.
76
77       The following sections are informative.
78

EXAMPLES

80   Changing the Current Owner of a File
81       The following example shows how to change the ownership of the symbolic
82       link  named /modules/pass1 to the user ID associated with ``jones'' and
83       the group ID associated with ``cnd''.
84
85       The numeric value for the user ID is obtained by using  the  getpwnam()
86       function.  The  numeric value for the group ID is obtained by using the
87       getgrnam() function.
88
89
90           #include <sys/types.h>
91           #include <unistd.h>
92           #include <pwd.h>
93           #include <grp.h>
94
95           struct passwd *pwd;
96           struct group  *grp;
97           char          *path = "/modules/pass1";
98           ...
99           pwd = getpwnam("jones");
100           grp = getgrnam("cnd");
101           lchown(path, pwd->pw_uid, grp->gr_gid);
102

APPLICATION USAGE

104       On implementations which support symbolic links  as  directory  entries
105       rather than files, lchown() may fail.
106

RATIONALE

108       None.
109

FUTURE DIRECTIONS

111       None.
112

SEE ALSO

114       chown(), symlink()
115
116       The Base Definitions volume of POSIX.1‐2017, <unistd.h>
117
119       Portions  of  this text are reprinted and reproduced in electronic form
120       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
121       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
122       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
123       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
124       event of any discrepancy between this version and the original IEEE and
125       The  Open Group Standard, the original IEEE and The Open Group Standard
126       is the referee document. The original Standard can be  obtained  online
127       at http://www.opengroup.org/unix/online.html .
128
129       Any  typographical  or  formatting  errors that appear in this page are
130       most likely to have been introduced during the conversion of the source
131       files  to  man page format. To report such errors, see https://www.ker
132       nel.org/doc/man-pages/reporting_bugs.html .
133
134
135
136IEEE/The Open Group                  2017                           LCHOWN(3P)
Impressum