1 /* 2 * 3 * Copyright (c) International Business Machines Corp., 2002 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /* 10/31/2002 Port to LTP robbiew (at) us.ibm.com */ 21 /* 06/30/2001 Port to Linux nsharoff (at) us.ibm.com */ 22 23 /* 24 * NAME 25 * nftw.c - Test of nftw() 26 */ 27 28 #include <pwd.h> 29 #include "nftw.h" 30 31 void setup(void); 32 void blenter(void); 33 void blexit(void); 34 void anyfail(void); 35 36 char progname[] = "nftw.c"; 37 38 /** LTP Port **/ 39 #define FAILED 0 40 #define PASSED 1 41 42 int local_flag = PASSED; 43 int block_number; 44 45 FILE *temp; 46 char *TCID = "nftw01"; 47 int TST_TOTAL = 10; 48 49 struct passwd *ltpuser; /* password struct for ltpuser */ 50 /**************/ 51 52 /* Used for error return for some library routines */ 53 int s2; 54 55 /* error messages formatted here. */ 56 char ebuf[ERR_BUF_SIZ]; 57 58 /* 59 * Local data declarations. 60 */ 61 char *dirlist[NDIRLISTENTS]; 62 63 int visit; 64 int next_fd[4]; 65 66 pathdata pathdat[] = { 67 { 68 "./tmp/data", 69 S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH, 70 DIR, ""}, { 71 "./tmp/byebye", 72 S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH, 73 REG, "byebye!\n"}, { 74 "./tmp/data/d333", 75 S_IRWXU | S_IRWXG | S_IRWXO, 76 DIR, ""}, { 77 "./tmp/data/d666", 78 S_IRWXU | S_IRWXG | S_IRWXO, 79 DIR, ""}, { 80 "./tmp/data/d777", 81 S_IRWXU | S_IRWXG 82 | S_IRWXO, 83 DIR, ""}, { 84 "./tmp/data/dirg", 85 S_IRWXU 86 | 87 S_IRWXG 88 | 89 S_IROTH 90 | 91 S_IWOTH, 92 DIR, 93 ""}, { 94 "./tmp/data/dirh", 95 S_IRWXU 96 | 97 S_IRWXG 98 | 99 S_IROTH 100 | 101 S_IWOTH, 102 DIR, 103 ""}, 104 { 105 "./tmp/data/dirl", 106 S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH, 107 DIR, ""}, { 108 "./tmp/data/d333/errs", 109 S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH, 110 REG, "Do not eat yellow snow!\n"}, { 111 "./tmp/data/d666/errs", 112 S_IRWXU | S_IRWXG | 113 S_IROTH | S_IWOTH, 114 REG, 115 "Do not eat yellow snow!\n"}, 116 { 117 "./tmp/data/d777/errs", 118 S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH, 119 REG, "Do not eat yellow snow!\n"}, { 120 "./tmp/data/dirg/filebad", 121 S_IRUSR | S_IWUSR | S_IRGRP | 122 S_IROTH, 123 REG, ""}, { 124 "./tmp/data/dirg/fileok", 125 S_IRUSR | S_IWUSR | 126 S_IRGRP | S_IROTH, 127 REG, ""}, { 128 "./tmp/data/dirg/symlink", 129 S_IRWXU | 130 S_IRWXG | 131 S_IRWXO, 132 SYM, 133 "../../byebye"}, 134 { 135 "./tmp/data/dirg/dir_left.1", 136 S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH, 137 DIR, ""}, { 138 "./tmp/data/dirg/dir_left.1/dir_left.2", 139 S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH, 140 DIR, ""}, { 141 "./tmp/data/dirg/dir_right.1", 142 S_IRWXU | S_IRWXG | S_IRWXO, 143 DIR, ""}, { 144 "./tmp/data/dirg/dir_left.1/dir_left.2/left.3", 145 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP 146 | S_IROTH, 147 REG, ""}, { 148 "./tmp/data/dirh/dir_left.1", 149 S_IRWXU | S_IRWXG | S_IROTH 150 | S_IWOTH, 151 DIR, ""}, { 152 "./tmp/data/dirh/dir_right.1", 153 S_IRWXU | 154 S_IRWXG | 155 S_IROTH | 156 S_IWOTH, 157 DIR, ""}, { 158 "./tmp/data/dirh/dir_left.1/dir_left.2", 159 S_IRWXU 160 | 161 S_IRWXG 162 | 163 S_IROTH 164 | 165 S_IWOTH, 166 DIR, 167 ""}, 168 { 169 "./tmp/data/dirh/dir_left.1/dir_left.2/left.3", 170 S_IRWXU | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH, 171 REG, "left leaf\n"}, { 172 "./tmp/data/dirh/dir_right.1/dir_right.2", 173 S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH, 174 DIR, ""}, { 175 "./tmp/data/dirh/dir_right.1/dir_right.2/right.3", 176 S_IRWXU | S_IRGRP | S_IWGRP | S_IROTH 177 | S_IWOTH, 178 REG, "right leaf\n"}, { 179 "./tmp/data/dirl/dir_left.1", 180 S_IRWXU | 181 S_IRWXG | 182 S_IROTH | 183 S_IWOTH, 184 DIR, ""}, { 185 "./tmp/data/dirl/dir_left.1/dir_left.2", 186 S_IRWXU 187 | 188 S_IRWXG 189 | 190 S_IROTH 191 | 192 S_IWOTH, 193 DIR, 194 ""}, 195 { 196 "./tmp/data/dirl/dir_left.1/dir_left.2/left.3", 197 0, 198 SYM, "../../../dirh"}, { 199 "./tmp/data/dirl/dir_right.1", 200 S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH, 201 DIR, ""}, { 202 "./tmp/data/dirl/dir_right.1/dir_right.2", 203 S_IRWXU | S_IRWXG | S_IROTH | 204 S_IWOTH, 205 DIR, ""}, { 206 "./tmp/data/dirl/dir_right.1/dir_right.2/right.3", 207 0, 208 SYM, "../dir_right.2"}, { 209 "./tmp/data/loop", 210 0, 211 SYM, 212 "./loop"} 213 }; 214 215 char *goodlist[] = { 216 "/dirh", 217 "/dirh/dir_left.1", 218 "/dirh/dir_right.1", 219 "/dirh/dir_left.1/dir_left.2", 220 "/dirh/dir_right.1/dir_right.2", 221 "/dirh/dir_left.1/dir_left.2/left.3", 222 "/dirh/dir_right.1/dir_right.2/right.3" 223 }; 224 225 struct list badlist[] = { 226 {"/dirg", FTW_D}, 227 {"/dirg/dir_left.1", FTW_D}, 228 /* not FTW_NS in following since stat can't fail if file exists */ 229 {"/dirg/filebad", FTW_F}, 230 {"/dirg/fileok", FTW_F}, 231 {"/dirg/symlink", FTW_SL}, 232 {"/dirg/dir_right.1", FTW_DNR}, 233 {"/dirg/dir_left.1/dir_left.2", FTW_D}, 234 {"/dirg/dir_left.1/dir_left.2/left.3", FTW_F}, 235 }; 236 237 struct list mnem[] = { 238 {"FTW_F", FTW_F}, 239 {"FTW_D", FTW_D}, 240 {"FTW_DNR", FTW_DNR}, 241 {"FTW_NS", FTW_NS}, 242 {"FTW_SL", FTW_SL}, 243 #ifndef __linux__ 244 /* How do we define __USE_XOPEN_EXTENDED ? Following depends on that */ 245 {"FTW_DP", FTW_DP}, 246 {"FTW_SLN", FTW_SLN}, 247 #endif 248 }; 249 250 int npathdats, ngoods, nbads, nmnem; 251 252 /*--------------------------------------------------------------*/ 253 int main(void) 254 { 255 setup(); /* temp file is now open */ 256 257 npathdats = ARRAY_SIZE(pathdat); 258 ngoods = ARRAY_SIZE(goodlist); 259 nbads = ARRAY_SIZE(badlist); 260 nmnem = ARRAY_SIZE(mnem); 261 262 setup_path(); 263 264 /*---------------- ENTER BLOCK 0 --------------------------------*/ 265 blenter(); 266 #ifdef DEBUG 267 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 268 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 269 fprintf(temp, "depth, int flags) shall recursively descend the\n"); 270 fprintf(temp, "directory hierarchy rooted in path until it has\n"); 271 fprintf(temp, 272 "traversed the whole tree, calling the function fn for\n"); 273 fprintf(temp, "each object in the directory tree, and return 0.\n\n"); 274 #endif 275 test1A(); 276 blexit(); 277 /*--------------- EXIT BLOCK 0 ---------------------------------*/ 278 279 /*---------------- ENTER BLOCK 1 --------------------------------*/ 280 blenter(); 281 #ifdef DEBUG 282 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 283 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 284 fprintf(temp, "depth, int flags) when flags contains FTW_PHYS shall\n"); 285 fprintf(temp, "not traverse symbolic links.\n\n"); 286 #endif 287 test2A(); 288 blexit(); 289 /*--------------- EXIT BLOCK 1 ---------------------------------*/ 290 291 /*---------------- ENTER BLOCK 2 --------------------------------*/ 292 blenter(); 293 #ifdef DEBUG 294 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 295 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 296 fprintf(temp, 297 "depth, int flags) when flags does not contain FTW_PHYS\n"); 298 fprintf(temp, 299 "shall follow links instead of reporting them and shall\n"); 300 fprintf(temp, "not report the same file twice.\n\n"); 301 #endif 302 test3A(); 303 blexit(); 304 /*--------------- EXIT BLOCK 2 ---------------------------------*/ 305 306 /*---------------- ENTER BLOCK 3 --------------------------------*/ 307 blenter(); 308 #ifdef DEBUG 309 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 310 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 311 fprintf(temp, 312 "depth, int flags) when flags contains FTW_DEPTH shall\n"); 313 fprintf(temp, "report all files in a directory before reporting the\n"); 314 fprintf(temp, "directory.\n\n"); 315 #endif 316 test4A(); 317 blexit(); 318 /*--------------- EXIT BLOCK 3 ---------------------------------*/ 319 320 /*---------------- ENTER BLOCK 4 --------------------------------*/ 321 blenter(); 322 #ifdef DEBUG 323 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 324 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 325 fprintf(temp, "depth, int flags) when flags does not contain\n"); 326 fprintf(temp, "FTW_DEPTH shall report a directory before reporting\n"); 327 fprintf(temp, "the files in that directory.\n\n"); 328 #endif 329 test5A(); 330 blexit(); 331 /*--------------- EXIT BLOCK 4 ---------------------------------*/ 332 333 /*---------------- ENTER BLOCK 5 --------------------------------*/ 334 blenter(); 335 #ifdef DEBUG 336 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 337 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 338 fprintf(temp, 339 "depth, int flags) when flags contains FTW_CHDIR shall\n"); 340 fprintf(temp, 341 "change the current working directory to each directory\n"); 342 fprintf(temp, "as it reports files in that directory.\n\n"); 343 #endif 344 test6A(); 345 blexit(); 346 /*--------------- EXIT BLOCK 5 ---------------------------------*/ 347 348 /*---------------- ENTER BLOCK 6 --------------------------------*/ 349 blenter(); 350 #ifdef DEBUG 351 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 352 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 353 fprintf(temp, "depth, int flags) shall pass the path-name of the\n"); 354 fprintf(temp, "current object as the first argument of the function\n"); 355 fprintf(temp, "fn.\n\n"); 356 #endif 357 test7A(); 358 blexit(); 359 /*--------------- EXIT BLOCK 6 ---------------------------------*/ 360 361 /*---------------- ENTER BLOCK 7 --------------------------------*/ 362 blenter(); 363 #ifdef DEBUG 364 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 365 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 366 fprintf(temp, "depth, int flags) shall pass a pointer to a stat\n"); 367 fprintf(temp, "structure containing information about the current\n"); 368 fprintf(temp, "object as the second argument to fn.\n\n"); 369 #endif 370 test8A(); 371 blexit(); 372 /*--------------- EXIT BLOCK 7 ---------------------------------*/ 373 374 /*---------------- ENTER BLOCK 8 --------------------------------*/ 375 blenter(); 376 #ifdef DEBUG 377 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 378 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 379 fprintf(temp, "depth, int flags) shall pass FTW_F as the third\n"); 380 fprintf(temp, 381 "argument of the function fn when the object is a file.\n\n"); 382 #endif 383 test9A(); 384 blexit(); 385 /*--------------- EXIT BLOCK 8 ---------------------------------*/ 386 387 /*---------------- ENTER BLOCK 9 --------------------------------*/ 388 blenter(); 389 #ifdef DEBUG 390 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 391 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 392 fprintf(temp, "depth, int flags) shall pass FTW_D as the third\n"); 393 fprintf(temp, "argument of the function fn when the object is a\n"); 394 fprintf(temp, "directory.\n\n"); 395 #endif 396 test10A(); 397 blexit(); 398 /*--------------- EXIT BLOCK 9 ---------------------------------*/ 399 400 /*---------------- ENTER BLOCK 10 --------------------------------*/ 401 blenter(); 402 #ifdef DEBUG 403 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 404 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 405 fprintf(temp, "depth, int flags) shall pass FTW_DP as the third\n"); 406 fprintf(temp, "argument of the function fn when the object is a\n"); 407 fprintf(temp, "directory and subdirectories have been visited.\n\n"); 408 #endif 409 test11A(); 410 blexit(); 411 /*--------------- EXIT BLOCK 10 ---------------------------------*/ 412 413 /*---------------- ENTER BLOCK 11 --------------------------------*/ 414 blenter(); 415 #ifdef DEBUG 416 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 417 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 418 fprintf(temp, "depth, int flags) shall pass FTW_SL as the third\n"); 419 fprintf(temp, "argument of the function fn when the object is a\n"); 420 fprintf(temp, "symbolic link.\n\n"); 421 #endif 422 test12A(); 423 blexit(); 424 /*--------------- EXIT BLOCK 11 ---------------------------------*/ 425 426 /*---------------- ENTER BLOCK 12 --------------------------------*/ 427 blenter(); 428 #ifdef DEBUG 429 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 430 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 431 fprintf(temp, "depth, int flags) shall pass FTW_SLN as the third\n"); 432 fprintf(temp, "argument of the function fn when the object is a\n"); 433 fprintf(temp, "symbolic link that does not name an existing file.\n\n"); 434 #endif 435 test13A(); 436 blexit(); 437 /*--------------- EXIT BLOCK 12 ---------------------------------*/ 438 439 /*---------------- ENTER BLOCK 13 --------------------------------*/ 440 blenter(); 441 #ifdef DEBUG 442 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 443 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 444 fprintf(temp, "depth, int flags) shall pass FTW_DNR as the third\n"); 445 fprintf(temp, "argument of the function fn when the object is a\n"); 446 fprintf(temp, "directory that cannot be read.\n\n"); 447 #endif 448 test14A(); 449 blexit(); 450 /*--------------- EXIT BLOCK 13 ---------------------------------*/ 451 452 /*---------------- ENTER BLOCK 14 --------------------------------*/ 453 blenter(); 454 #ifdef DEBUG 455 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 456 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 457 fprintf(temp, "depth, int flags) shall pass FTW_NS as the third\n"); 458 fprintf(temp, 459 "argument of the function fn when stat() failed on the\n"); 460 fprintf(temp, "object because of lack of appropriate permission.\n\n"); 461 #endif 462 test15A(); 463 blexit(); 464 /*--------------- EXIT BLOCK 14 ---------------------------------*/ 465 466 /*---------------- ENTER BLOCK 15 --------------------------------*/ 467 blenter(); 468 #ifdef DEBUG 469 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 470 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 471 fprintf(temp, "depth, int flags) shall pass a structure which\n"); 472 fprintf(temp, "contains the offset into the pathname of the object\n"); 473 fprintf(temp, "and the depth relative to the root of the walk\n"); 474 fprintf(temp, 475 "starting from 0 as the fourth argument of the function\n"); 476 fprintf(temp, "fn.\n\n"); 477 #endif 478 test16A(); 479 blexit(); 480 /*--------------- EXIT BLOCK 15 ---------------------------------*/ 481 482 /*---------------- ENTER BLOCK 16 --------------------------------*/ 483 blenter(); 484 #ifdef DEBUG 485 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 486 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 487 fprintf(temp, "depth, int flags) shall pass FTW_SL as the third\n"); 488 fprintf(temp, "argument to the function fn if and only if the\n"); 489 fprintf(temp, "FTW_PHYS flag is included in flags.\n\n"); 490 #endif 491 test17A(); 492 blexit(); 493 /*--------------- EXIT BLOCK 16 ---------------------------------*/ 494 495 /*---------------- ENTER BLOCK 17 --------------------------------*/ 496 blenter(); 497 #ifdef DEBUG 498 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 499 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 500 fprintf(temp, "depth, int flags) shall pass FTW_SLN as the third\n"); 501 fprintf(temp, "argument to the function fn if and only if the\n"); 502 fprintf(temp, "FTW_PHYS flag is not included in flags.\n\n"); 503 #endif 504 test18A(); 505 blexit(); 506 /*--------------- EXIT BLOCK 17 ---------------------------------*/ 507 508 /*---------------- ENTER BLOCK 18 --------------------------------*/ 509 blenter(); 510 #ifdef DEBUG 511 fprintf(temp, "On a call to int nftw(const char *path, int\n"); 512 fprintf(temp, "(*fn)(const char *, const struct stat *, int, struct\n"); 513 fprintf(temp, 514 "FTW *), int depth, int flags) when the third argument\n"); 515 fprintf(temp, "passed to the function fn is FTW_DNR then the\n"); 516 fprintf(temp, 517 "descendants of the directory shall not be processed.\n\n"); 518 #endif 519 test19A(); 520 blexit(); 521 /*--------------- EXIT BLOCK 18 ---------------------------------*/ 522 523 /*---------------- ENTER BLOCK 19 --------------------------------*/ 524 blenter(); 525 #ifdef DEBUG 526 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 527 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 528 fprintf(temp, 529 "depth, int flags) shall close any file descriptors or\n"); 530 fprintf(temp, 531 "directory streams used to traverse the directory tree.\n\n"); 532 #endif 533 test20A(); 534 blexit(); 535 /*--------------- EXIT BLOCK 19 ---------------------------------*/ 536 537 /*---------------- ENTER BLOCK 20 --------------------------------*/ 538 blenter(); 539 #ifdef DEBUG 540 fprintf(temp, "On a call to int nftw(const char *path, int\n"); 541 fprintf(temp, "(*fn)(const char *, const struct stat *, int, struct\n"); 542 fprintf(temp, "FTW *), int depth, int flags) depth shall be the\n"); 543 fprintf(temp, 544 "maximum number of file descriptors used for the search.\n\n"); 545 #endif 546 test21A(); 547 blexit(); 548 /*--------------- EXIT BLOCK 20 ---------------------------------*/ 549 550 /*---------------- ENTER BLOCK 21 --------------------------------*/ 551 blenter(); 552 #ifdef DEBUG 553 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 554 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 555 fprintf(temp, "depth, int flags) shall use at most one file\n"); 556 fprintf(temp, "descriptor for each directory level.\n\n"); 557 #endif 558 test22A(); 559 blexit(); 560 /*--------------- EXIT BLOCK 21 ---------------------------------*/ 561 562 /*---------------- ENTER BLOCK 22 --------------------------------*/ 563 blenter(); 564 #ifdef DEBUG 565 fprintf(temp, "A call to int nftw(const char *path, int (*fn)(const\n"); 566 fprintf(temp, "char *, const struct stat *, int, struct FTW *), int\n"); 567 fprintf(temp, "depth, int flags) when the function fn returns a\n"); 568 fprintf(temp, "non-zero value shall stop and return the value\n"); 569 fprintf(temp, "returned by fn.\n\n"); 570 #endif 571 test23A(); 572 blexit(); 573 /*--------------- EXIT BLOCK 22 ---------------------------------*/ 574 575 /*---------------- ENTER BLOCK 23 --------------------------------*/ 576 blenter(); 577 #ifdef DEBUG 578 fprintf(temp, "ENAMETOOLONG in errno and return -1 on a call to int\n"); 579 fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); 580 fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); 581 fprintf(temp, "flags) when the length of path exceeds PATH_MAX.\n\n"); 582 #endif 583 test24A(); 584 blexit(); 585 /*--------------- EXIT BLOCK 23 ---------------------------------*/ 586 587 /*---------------- ENTER BLOCK 24 --------------------------------*/ 588 blenter(); 589 #ifdef DEBUG 590 fprintf(temp, "ENAMETOOLONG in errno and return -1 on a call to int\n"); 591 fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); 592 fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); 593 fprintf(temp, "flags) when a component of path exceeds NAME_MAX.\n\n"); 594 #endif 595 test25A(); 596 blexit(); 597 /*--------------- EXIT BLOCK 24 ---------------------------------*/ 598 599 /*---------------- ENTER BLOCK 25 --------------------------------*/ 600 blenter(); 601 #ifdef DEBUG 602 fprintf(temp, "ENOENT in errno and return -1 on a call to int\n"); 603 fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); 604 fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); 605 fprintf(temp, 606 "flags) when path points to a file which does not exist.\n\n"); 607 #endif 608 test26A(); 609 blexit(); 610 /*--------------- EXIT BLOCK 25 ---------------------------------*/ 611 612 /*---------------- ENTER BLOCK 26 --------------------------------*/ 613 blenter(); 614 #ifdef DEBUG 615 fprintf(temp, "ENOENT in errno and return -1 on a call to int\n"); 616 fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); 617 fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); 618 fprintf(temp, "flags) when path points to an empty string.\n\n"); 619 #endif 620 test27A(); 621 blexit(); 622 /*--------------- EXIT BLOCK 26 ---------------------------------*/ 623 624 /*---------------- ENTER BLOCK 27 --------------------------------*/ 625 blenter(); 626 #ifdef DEBUG 627 fprintf(temp, "ENOTDIR in errno and return -1 on a call to int\n"); 628 fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); 629 fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); 630 fprintf(temp, "flags) when path is not a directory.\n\n"); 631 #endif 632 test28A(); 633 blexit(); 634 /*--------------- EXIT BLOCK 27 ---------------------------------*/ 635 636 /*---------------- ENTER BLOCK 28 --------------------------------*/ 637 blenter(); 638 #ifdef DEBUG 639 fprintf(temp, "EACCES in errno and return -1 on a call to int\n"); 640 fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); 641 fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); 642 fprintf(temp, "flags) when search permission is denied for any\n"); 643 fprintf(temp, "component of path.\n\n"); 644 #endif 645 test29A(); 646 blexit(); 647 /*--------------- EXIT BLOCK 28 ---------------------------------*/ 648 649 /*---------------- ENTER BLOCK 29 --------------------------------*/ 650 blenter(); 651 #ifdef DEBUG 652 fprintf(temp, "EACCES in errno and return -1 on a call to int\n"); 653 fprintf(temp, "nftw(const char *path, int (*fn)(const char *, const\n"); 654 fprintf(temp, "struct stat *, int, struct FTW *), int depth, int\n"); 655 fprintf(temp, "flags) when read permission is denied for path.\n\n"); 656 #endif 657 test30A(); 658 blexit(); 659 /*--------------- EXIT BLOCK 29 ---------------------------------*/ 660 661 cleanup_function(); 662 663 anyfail(); /* THIS CALL DOES NOT RETURN - EXITS!! */ 664 tst_exit(); 665 /*--------------------------------------------------------------*/ 666 } 667 668 /** LTP Port **/ 669 /* 670 * setup 671 * 672 * Do set up - here its a dummy function 673 */ 674 void setup(void) 675 { 676 /* Direct debug output to stderr */ 677 temp = stderr; 678 679 /* Get the user id "nobody" */ 680 if ((ltpuser = getpwnam("nobody")) == NULL) { 681 perror("nobody not found in /etc/passwd"); 682 exit(1); 683 } 684 685 /* Switch to "nobody" */ 686 setuid(ltpuser->pw_uid); 687 688 tst_tmpdir(); 689 } 690 691 /* 692 * Function: blenter() 693 * 694 * Description: Print message on entering a new block 695 */ 696 void blenter(void) 697 { 698 local_flag = PASSED; 699 return; 700 } 701 702 /* 703 * Function: blexit() 704 * 705 * Description: This function will exit a block, a block may be a logical unit 706 * of a test. It will report the status if the test ie fail or 707 * pass. 708 */ 709 void blexit(void) 710 { 711 (local_flag == PASSED) ? tst_resm(TPASS, "Test block %d", block_number) 712 : tst_resm(TFAIL, "Test block %d", block_number); 713 block_number++; 714 return; 715 } 716 717 /* 718 * 719 * Function: anyfail() 720 * 721 * Description: Exit a test. 722 */ 723 void anyfail(void) 724 { 725 (local_flag == FAILED) ? tst_resm(TFAIL, "Test failed") 726 : tst_resm(TPASS, "Test passed"); 727 tst_rmdir(); 728 tst_exit(); 729 } 730 731 /**************/ 732