Path: blob/main/tools/test/stress2/testcases/fts/fts.c
39566 views
/*-1* Copyright (c) 2008 Peter Holm <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*25*/2627/* Directory scan */2829#include <sys/param.h>30#include <err.h>31#include <errno.h>32#include <fts.h>33#include <libutil.h>34#include <stdint.h>35#include <stdio.h>36#include <stdlib.h>37#include <string.h>38#include <unistd.h>3940#include "stress.h"4142int43setup(int nb __unused)44{45return (0);46}4748void49cleanup(void)50{51}5253int54test(void)55{5657FTS *fts;58FTSENT *p;59int ftsoptions;60char *args[2] = {NULL, NULL};6162ftsoptions = FTS_LOGICAL;63args[0] = strdup(".");6465if ((fts = fts_open(args, ftsoptions, NULL)) == NULL)66err(1, "fts_open");6768while ((p = fts_read(fts)) != NULL && done_testing == 0) {69if (op->verbose > 2)70(void) printf("%s\n", p->fts_path);71switch (p->fts_info) {72case FTS_F: /* Ignore. */73break;74case FTS_D: /* Ignore. */75break;76case FTS_DP:77break;78case FTS_DC: /* Ignore. */79break;80case FTS_SL: /* Ignore. */81break;82case FTS_SLNONE: /* Ignore. */83break;84case FTS_DNR: /* Warn, continue. */85case FTS_ERR:86case FTS_NS:87case FTS_DEFAULT:88if (op->verbose > 1)89warnx("%s: %s", p->fts_path, strerror(p->fts_errno));90break;91default:92printf("%s: default, %d\n", getprogname(), p->fts_info);93break;94}95}9697if (fts_close(fts) == -1)98err(1, "fts_close()");99100return (0);101}102103104