MCPcopy Create free account
hub / github.com/coreutils/coreutils / follow_fstatat

Function follow_fstatat

src/copy.c:186–213  ·  view source on GitHub ↗

Act like fstat (DIRFD, FILENAME, ST, FLAGS), except when following symbolic links on Solaris-like systems, treat any character-special device like /dev/fd/0 as if it were the file it is open on. */

Source from the content-addressed store, hash-verified

184 symbolic links on Solaris-like systems, treat any character-special
185 device like /dev/fd/0 as if it were the file it is open on. */
186static int
187follow_fstatat (int dirfd, char const *filename, struct stat *st, int flags)
188{
189 int result = fstatat (dirfd, filename, st, flags);
190
191 if (DEV_FD_MIGHT_BE_CHR && result == 0 && !(flags & AT_SYMLINK_NOFOLLOW)
192 && S_ISCHR (st->st_mode))
193 {
194 static dev_t stdin_rdev;
195 static signed char stdin_rdev_status;
196 if (stdin_rdev_status == 0)
197 {
198 struct stat stdin_st;
199 if (stat ("/dev/stdin", &stdin_st) == 0 && S_ISCHR (stdin_st.st_mode)
200 && minor (stdin_st.st_rdev) == STDIN_FILENO)
201 {
202 stdin_rdev = stdin_st.st_rdev;
203 stdin_rdev_status = 1;
204 }
205 else
206 stdin_rdev_status = -1;
207 }
208 if (0 < stdin_rdev_status && major (stdin_rdev) == major (st->st_rdev))
209 result = fstat (minor (st->st_rdev), st);
210 }
211
212 return result;
213}
214
215/* Whether an errno value ERR, set by FICLONE or copy_file_range,
216 indicates that the copying operation has terminally failed, even

Callers 1

copy_internalFunction · 0.85

Calls 1

statClass · 0.70

Tested by

no test coverage detected