Changeset 1966
- Timestamp:
- May 6, 2005, 1:24:48 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/lib/bsd/gen/fts.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r1965 r1966 39 39 #endif /* LIBC_SCCS and not lint */ 40 40 #endif 41 #ifndef __EMX__ 42 # define HAVE_FCHDIR 43 # define NEED_STRRSLASH 44 # define IS_SLASH(ch) ( (ch) == '/' || (ch) == '\\' ) 45 #else 46 # define IS_SLASH(ch) ( (ch) == '/' ) 47 #endif 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 #ifdef HAVE_FCHDIR 77 85 #define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) 86 #else 87 #define FCHDIR(sp, rdir) (!ISSET(FTS_NOCHDIR) && chdir(rdir)) 88 #endif 78 89 79 90 /* fts_build flags */ … … 94 105 }; 95 106 107 #ifndef __EMX__ 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 #endif /* !__EMX__ */ 112 125 113 126 FTS * … … 212 225 * descriptor we run anyway, just more slowly. 213 226 */ 227 #ifdef HAVE_FCHDIR 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 #ifdef NEED_STRRSLASH 244 static char *strrslash(register char *psz) 245 { 246 register char ch; 247 char *pszLast = NULL; 248 for (; (ch = *psz); psz++) 249 switch (ch) 250 { 251 case '/': 252 case '\\': 253 case ':': 254 pszLast = psz; 255 break; 256 } 257 return pszLast; 258 } 259 #endif 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 #ifdef NEED_STRRSLASH 279 if ((cp = strrslash(p->fts_name)) && (cp != p->fts_name || cp[1])) { 280 #else 243 281 if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { 282 #endif 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 #ifdef HAVE_FCHDIR 282 322 saved_errno = fchdir(sp->fts_rfd) ? errno : 0; 283 323 (void)_close(sp->fts_rfd); 324 #else 325 saved_errno = chdir(sp->fts_rdir) ? errno : 0; 326 free(sp->fts_rdir); sp->fts_rdir = NULL; 327 #endif 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 (IS_SLASH(p->fts_path[p->fts_pathlen - 1]) \ 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 #ifdef HAVE_FCHDIR 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 #endif 348 395 } 349 396 return (p); … … 355 402 if (instr == FTS_SKIP || 356 403 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { 404 #ifdef HAVE_FCHDIR 357 405 if (p->fts_flags & FTS_SYMFOLLOW) 358 406 (void)_close(p->fts_symfd); 407 #endif 359 408 if (sp->fts_child) { 360 409 fts_lfree(sp->fts_child); … … 413 462 */ 414 463 if (p->fts_level == FTS_ROOTLEVEL) { 464 #ifdef HAVE_FCHDIR 415 465 if (FCHDIR(sp, sp->fts_rfd)) { 466 #else 467 if (FCHDIR(sp, sp->fts_rdir)) { 468 #endif 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 #ifdef HAVE_FCHDIR 433 487 if ((p->fts_symfd = 434 488 _open(".", O_RDONLY, 0)) < 0) { … … 437 491 } else 438 492 p->fts_flags |= FTS_SYMFOLLOW; 493 #endif 439 494 } 440 495 p->fts_instr = FTS_NOINSTR; … … 470 525 */ 471 526 if (p->fts_level == FTS_ROOTLEVEL) { 527 #ifdef HAVE_FCHDIR 472 528 if (FCHDIR(sp, sp->fts_rfd)) { 529 #else 530 if (FCHDIR(sp, sp->fts_rdir)) { 531 #endif 473 532 SET(FTS_STOP); 474 533 return (NULL); 475 534 } 535 #ifdef HAVE_FCHDIR 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 #else 546 (void)saved_errno; 547 #endif 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 #ifdef HAVE_FCHDIR 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 || IS_SLASH(p->fts_accpath[0]) || 572 639 ISSET(FTS_NOCHDIR)) 573 640 return (sp->fts_child = fts_build(sp, instr)); 574 641 642 #ifdef HAVE_FCHDIR 575 643 if ((fd = _open(".", O_RDONLY, 0)) < 0) 644 #else 645 if ((pszRoot = getcwd(NULL, 0)) == NULL) 646 #endif 576 647 return (NULL); 577 648 sp->fts_child = fts_build(sp, instr); 649 #ifdef HAVE_FCHDIR 578 650 if (fchdir(fd)) 579 651 return (NULL); 580 652 (void)_close(fd); 653 #else 654 rc = chdir(pszRoot); 655 free(pszRoot); 656 if (rc) 657 return NULL; 658 #endif 581 659 return (sp->fts_child); 582 660 } … … 653 731 oflag = DTF_HIDEW | DTF_NODUP | DTF_REWIND; 654 732 #else 733 (void)(oflag); 655 734 #define __opendir2(path, flag) opendir(path) 656 735 #endif … … 705 784 cderrno = 0; 706 785 if (nlinks || type == BREAD) { 786 #ifdef HAVE_FCHDIR 707 787 if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { 788 #else 789 if (fts_safe_changedir(sp, cur, dirfd(dirp), cur->fts_accpath)) { 790 #endif 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 #ifdef HAVE_FCHDIR 872 956 FCHDIR(sp, sp->fts_rfd) : 957 #else 958 FCHDIR(sp, sp->fts_rdir) : 959 #endif 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 #ifdef HAVE_FCHDIR 1174 1262 if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0) 1175 1263 return (-1); 1176 1264 if (_fstat(newfd, &sb)) { 1265 #else 1266 (void)newfd; 1267 if (_stat(path, &sb)) { 1268 #endif 1177 1269 ret = -1; 1178 1270 goto bail; … … 1183 1275 goto bail; 1184 1276 } 1277 #ifdef HAVE_FCHDIR 1185 1278 ret = fchdir(newfd); 1279 #else 1280 ret = chdir(path); 1281 #endif 1186 1282 bail: 1283 #ifdef HAVE_FCHDIR 1187 1284 oerrno = errno; 1188 1285 if (fd < 0) 1189 1286 (void)_close(newfd); 1190 1287 errno = oerrno; 1288 #else 1289 (void)oerrno; 1290 #endif 1191 1291 return (ret); 1192 1292 } … … 1202 1302 1203 1303 priv = (struct _fts_private *)sp; 1304 #ifdef __EMX__ 1305 /* we don't have reliable links */ 1306 priv->ftsp_linksreliable = 0; 1307 (void)cpp; 1308 #else 1204 1309 /* 1205 1310 * If this node's device is different from the previous, grab … … 1223 1328 } 1224 1329 } 1330 #endif 1225 1331 return (priv->ftsp_linksreliable); 1226 1332 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.