1link(2)                          System Calls                          link(2)
2
3
4

NAME

6       link - link to a file
7

SYNOPSIS

9       #include <unistd.h>
10
11       int link(const char *existing, const char *new);
12
13

DESCRIPTION

15       The link() function creates a new link (directory entry) for the exist‐
16       ing file and increments its link count by one.  The  existing  argument
17       points to a path name naming an existing file.  The new argument points
18       to a pathname naming the new directory entry to be created.
19
20
21       To create hard links, both files must be on the same file system.  Both
22       the  old and the new link share equal access and rights to the underly‐
23       ing object. Privileged processes can make multiple links  to  a  direc‐
24       tory.  Unless the caller is privileged, the file named by existing must
25       not be a directory.
26
27
28       Upon successful completion, link() marks for update the st_ctime  field
29       of  the  file.  Also, the st_ctime and st_mtime fields of the directory
30       that contains the new entry are marked for update.
31

RETURN VALUES

33       Upon successful completion, 0 is returned. Otherwise, −1  is  returned,
34       no link is created, and errno is set to indicate the error.
35

ERRORS

37       The link() function will fail if:
38
39       EACCES          A component of either path prefix denies search permis‐
40                       sion, or the  requested  link  requires  writing  in  a
41                       directory with a mode that denies write permission.
42
43
44       EDQUOT          The directory where the entry for the new link is being
45                       placed cannot be extended because the user's  quota  of
46                       disk blocks on that file system has been exhausted.
47
48
49       EEXIST          The link named by new exists.
50
51
52       EFAULT          The  existing  or  new  argument  points  to an illegal
53                       address.
54
55
56       EILSEQ          The path argument includes non-UTF8 characters and  the
57                       file  system  accepts only file names where all charac‐
58                       ters are part of the UTF-8 character codeset.
59
60
61       EINTR           A signal was caught during the execution of the  link()
62                       function.
63
64
65       ELOOP           Too many symbolic links were encountered in translating
66                       path.
67
68
69       EMLINK          The  maximum  number  of  links  to  a  file  would  be
70                       exceeded.
71
72
73       ENAMETOOLONG    The  length  of  the  existing  or new argument exceeds
74                       PATH_MAX, or the length of a existing or new  component
75                       exceeds NAME_MAX while _POSIX_NO_TRUNC is in effect.
76
77
78       ENOENT          The existing or new argument is a null pathname; a com‐
79                       ponent of either path prefix does  not  exist;  or  the
80                       file named by existing does not exist.
81
82
83       ENOLINK         The existing or new argument points to a remote machine
84                       and the link to that machine is no longer active.
85
86
87       ENOSPC          The directory that would contain  the  link  cannot  be
88                       extended.
89
90
91       ENOTDIR         A component of either path prefix is not a directory.
92
93
94       EPERM           The  file  named  by  existing  is  a directory and the
95                       {PRIV_SYS_LINKDIR} privilege is  not  asserted  in  the
96                       effective set of the calling process.
97
98                       The  effective  user ID does not match the owner of the
99                       file and  the  {PRIV_FILE_LINK_ANY}  privilege  is  not
100                       asserted in the effective set of the calling process.
101
102
103       EROFS           The requested link requires writing in a directory on a
104                       read-only file system.
105
106
107       EXDEV           The link named by new and the file  named  by  existing
108                       are on different logical devices (file systems).
109
110

ATTRIBUTES

112       See attributes(5) for descriptions of the following attributes:
113
114
115
116
117       ┌─────────────────────────────┬─────────────────────────────┐
118       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
119       ├─────────────────────────────┼─────────────────────────────┤
120       │Interface Stability          │Standard                     │
121       ├─────────────────────────────┼─────────────────────────────┤
122       │MT-Level                     │Async-Signal-Safe            │
123       └─────────────────────────────┴─────────────────────────────┘
124

SEE ALSO

126       symlink(2), unlink(2), attributes(5), privileges(5), standards(5)
127
128
129
130SunOS 5.11                        18 May 2007                          link(2)
Impressum