MCPcopy Create free account
hub / github.com/catboost/catboost / fts_safe_changedir

Function fts_safe_changedir

util/folder/fts.cpp:1360–1390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1358
1359#ifndef _win_
1360static int
1361fts_safe_changedir(FTS* sp, FTSENT* p, int fd, const char* path)
1362{
1363 int ret, oerrno, newfd;
1364 stat_struct sb;
1365
1366 newfd = fd;
1367 if (ISSET(FTS_NOCHDIR)) {
1368 return (0);
1369 }
1370 if (fd < 0 && (newfd = open(path, O_RDONLY, 0)) < 0) {
1371 return (-1);
1372 }
1373 if (fstat(newfd, &sb)) {
1374 ret = -1;
1375 goto bail;
1376 }
1377 if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) {
1378 errno = ENOENT; /* disinformation */
1379 ret = -1;
1380 goto bail;
1381 }
1382 ret = fchdir(newfd);
1383bail:
1384 oerrno = errno;
1385 if (fd < 0) {
1386 (void)close(newfd);
1387 }
1388 errno = oerrno;
1389 return (ret);
1390}
1391#else
1392static int
1393fts_safe_changedir(FTS* sp, FTSENT* p, int /*fd*/, const char* path)

Callers 2

yfts_readFunction · 0.85
fts.cppFile · 0.85

Calls 4

chdir_dirdFunction · 0.85
openFunction · 0.50
fstatFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected