- Timestamp:
- May 6, 2005, 1:24:48 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/src/emx/src/lib/bsd/gen/fts.c (modified) (27 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/lib/bsd/gen/fts.c
-
Property cvs2svn:cvs-rev
changed from
1.1to1.2
r1965 r1966 39 39 #endif /* LIBC_SCCS and not lint */ 40 40 #endif 41 42 43 44 45 46 47 41 48 42 49 #include <sys/cdefs.h> 43 __FBSDID("$FreeBSD: src/lib/libc/gen/fts.c,v 1.27 2004/06/08 06:23:23 das Exp $");50 __FBSDID("$FreeBSD: src/lib/libc/gen/fts.c,v 1.27 2004/06/08 06:23:23 das Exp $"); 44 51 45 52 #include "namespace.h" … … 75 82 #define SET(opt) (sp->fts_options |= (opt)) 76 83 84 77 85 #define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) 86 87 88 78 89 79 90 /* fts_build flags */ … … 94 105 }; 95 106 107 96 108 /* 97 109 * The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it … … 110 122 0 111 123 }; 124 112 125 113 126 FTS * … … 212 225 * descriptor we run anyway, just more slowly. 213 226 */ 227 214 228 if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0) 215 SET(FTS_NOCHDIR); 229 #else 230 if (!ISSET(FTS_NOCHDIR) && (sp->fts_rdir = getcwd(NULL, 0)) != NULL) 231 #endif 232 SET(FTS_NOCHDIR); 216 233 217 234 return (sp); … … 224 241 } 225 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 226 261 static void 227 262 fts_load(sp, p) … … 241 276 len = p->fts_pathlen = p->fts_namelen; 242 277 memmove(sp->fts_path, p->fts_name, len + 1); 278 279 280 243 281 if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { 282 244 283 len = strlen(++cp); 245 284 memmove(p->fts_name, cp, len + 1); … … 280 319 /* Return to original directory, save errno if necessary. */ 281 320 if (!ISSET(FTS_NOCHDIR)) { 321 282 322 saved_errno = fchdir(sp->fts_rfd) ? errno : 0; 283 323 (void)_close(sp->fts_rfd); 324 325 326 327 284 328 285 329 /* Set errno and return. */ … … 297 341 } 298 342 343 299 344 /* 300 345 * Special case of "/" at the end of the path so that slashes aren't … … 302 347 */ 303 348 #define NAPPEND(p) \ 304 ( p->fts_path[p->fts_pathlen - 1] == '/'\349 ( \ 305 350 ? p->fts_pathlen - 1 : p->fts_pathlen) 306 351 … … 341 386 p->fts_info = fts_stat(sp, p, 1); 342 387 if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { 388 343 389 if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) { 344 390 p->fts_errno = errno; … … 346 392 } else 347 393 p->fts_flags |= FTS_SYMFOLLOW; 394 348 395 } 349 396 return (p); … … 355 402 if (instr == FTS_SKIP || 356 403 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { 404 357 405 if (p->fts_flags & FTS_SYMFOLLOW) 358 406 (void)_close(p->fts_symfd); 407 359 408 if (sp->fts_child) { 360 409 fts_lfree(sp->fts_child); … … 413 462 */ 414 463 if (p->fts_level == FTS_ROOTLEVEL) { 464 415 465 if (FCHDIR(sp, sp->fts_rfd)) { 466 467 468 416 469 SET(FTS_STOP); 417 470 return (NULL); … … 431 484 p->fts_info = fts_stat(sp, p, 1); 432 485 if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { 486 433 487 if ((p->fts_symfd = 434 488 _open(".", O_RDONLY, 0)) < 0) { … … 437 491 } else 438 492 p->fts_flags |= FTS_SYMFOLLOW; 493 439 494 } 440 495 p->fts_instr = FTS_NOINSTR; … … 470 525 */ 471 526 if (p->fts_level == FTS_ROOTLEVEL) { 527 472 528 if (FCHDIR(sp, sp->fts_rfd)) { 529 530 531 473 532 SET(FTS_STOP); 474 533 return (NULL); 475 534 } 535 476 536 } else if (p->fts_flags & FTS_SYMFOLLOW) { 477 537 if (FCHDIR(sp, p->fts_symfd)) { … … 483 543 } 484 544 (void)_close(p->fts_symfd); 545 546 547 485 548 } else if (!(p->fts_flags & FTS_DONTCHDIR) && 486 549 fts_safe_changedir(sp, p->fts_parent, -1, "..")) { … … 520 583 { 521 584 FTSENT *p; 585 522 586 int fd; 523 587 #else 588 char *pszRoot; 589 int rc; 590 #endif 524 591 if (instr != 0 && instr != FTS_NAMEONLY) { 525 592 errno = EINVAL; … … 569 636 * fts_read will work. 570 637 */ 571 if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/'||638 if (p->fts_level != FTS_ROOTLEVEL || || 572 639 ISSET(FTS_NOCHDIR)) 573 640 return (sp->fts_child = fts_build(sp, instr)); 574 641 642 575 643 if ((fd = _open(".", O_RDONLY, 0)) < 0) 644 645 646 576 647 return (NULL); 577 648 sp->fts_child = fts_build(sp, instr); 649 578 650 if (fchdir(fd)) 579 651 return (NULL); 580 652 (void)_close(fd); 653 654 655 656 657 658 581 659 return (sp->fts_child); 582 660 } … … 653 731 oflag = DTF_HIDEW | DTF_NODUP | DTF_REWIND; 654 732 #else 733 655 734 #define __opendir2(path, flag) opendir(path) 656 735 #endif … … 705 784 cderrno = 0; 706 785 if (nlinks || type == BREAD) { 786 707 787 if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { 788 789 790 708 791 if (nlinks && type == BREAD) 709 792 cur->fts_errno = errno; … … 870 953 if (descend && (type == BCHILD || !nitems) && 871 954 (cur->fts_level == FTS_ROOTLEVEL ? 955 872 956 FCHDIR(sp, sp->fts_rfd) : 957 958 959 873 960 fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { 874 961 cur->fts_info = FTS_ERR; … … 1172 1259 if (ISSET(FTS_NOCHDIR)) 1173 1260 return (0); 1261 1174 1262 if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0) 1175 1263 return (-1); 1176 1264 if (_fstat(newfd, &sb)) { 1265 1266 1267 1268 1177 1269 ret = -1; 1178 1270 goto bail; … … 1183 1275 goto bail; 1184 1276 } 1277 1185 1278 ret = fchdir(newfd); 1279 1280 1281 1186 1282 bail: 1283 1187 1284 oerrno = errno; 1188 1285 if (fd < 0) 1189 1286 (void)_close(newfd); 1190 1287 errno = oerrno; 1288 1289 1290 1191 1291 return (ret); 1192 1292 } … … 1202 1302 1203 1303 priv = (struct _fts_private *)sp; 1304 1305 1306 1307 1308 1204 1309 /* 1205 1310 * If this node's device is different from the previous, grab … … 1223 1328 } 1224 1329 } 1330 1225 1331 return (priv->ftsp_linksreliable); 1226 1332 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
