Fix some^Wseveral style bugs from last commit.
Remove "sys/types.h" as "sys/param.h" is already included Use cast rather than back-pointer to convert from public to private version of FTS data, and so avoid littering fts.h with any of the details. Pointed out By: bde, kientzle
This commit is contained in:
parent
ac006f74fd
commit
07dee1a777
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=129161
@ -63,7 +63,6 @@ typedef struct {
|
|||||||
#define FTS_STOP 0x200 /* (private) unrecoverable error */
|
#define FTS_STOP 0x200 /* (private) unrecoverable error */
|
||||||
int fts_options; /* fts_open options, global flags */
|
int fts_options; /* fts_open options, global flags */
|
||||||
void *fts_clientptr; /* thunk for sort function */
|
void *fts_clientptr; /* thunk for sort function */
|
||||||
struct _fts_private *fts_priv; /* implementation data */
|
|
||||||
} FTS;
|
} FTS;
|
||||||
|
|
||||||
typedef struct _ftsent {
|
typedef struct _ftsent {
|
||||||
|
@ -40,10 +40,9 @@ static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include "namespace.h"
|
#include "namespace.h"
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -64,7 +63,7 @@ static int fts_palloc(FTS *, size_t);
|
|||||||
static FTSENT *fts_sort(FTS *, FTSENT *, int);
|
static FTSENT *fts_sort(FTS *, FTSENT *, int);
|
||||||
static u_short fts_stat(FTS *, FTSENT *, int);
|
static u_short fts_stat(FTS *, FTSENT *, int);
|
||||||
static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
|
static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
|
||||||
static int fts_ufslinks(FTS *sp, const FTSENT *ent);
|
static int fts_ufslinks(FTS *, const FTSENT *);
|
||||||
|
|
||||||
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
|
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
|
||||||
|
|
||||||
@ -80,25 +79,24 @@ static int fts_ufslinks(FTS *sp, const FTSENT *ent);
|
|||||||
#define BREAD 3 /* fts_read */
|
#define BREAD 3 /* fts_read */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal representation of FTS, including extra implementation details.
|
* Internal representation of an FTS, including extra implementation
|
||||||
* The FTS returned from fts_open is ftsp_fts from this structure, and it's
|
* details. The FTS returned from fts_open points to this structure's
|
||||||
* fts_priv in turn points back to this internal version. i.e. for a given
|
* ftsp_fts member (and can be cast to an _fts_private as required)
|
||||||
* fts_private *priv: &priv->fts_fts == (FTS *)f == priv->fts_fts.fts_priv
|
|
||||||
*/
|
*/
|
||||||
struct _fts_private {
|
struct _fts_private {
|
||||||
FTS ftsp_fts;
|
FTS ftsp_fts;
|
||||||
struct statfs ftsp_statfs;
|
struct statfs ftsp_statfs;
|
||||||
dev_t ftsp_dev;
|
dev_t ftsp_dev;
|
||||||
int ftsp_linksreliable;
|
int ftsp_linksreliable;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it knows
|
* The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it
|
||||||
* that a directory could not possibly have subdirectories. This is decided
|
* knows that a directory could not possibly have subdirectories. This
|
||||||
* by looking at the link count: A subdirectory would increment its parent's
|
* is decided by looking at the link count: a subdirectory would
|
||||||
* link count by virtue of its own ".." entry.
|
* increment its parent's link count by virtue of its own ".." entry.
|
||||||
* This assumption only holds for UFS-like filesystems that implement links
|
* This assumption only holds for UFS-like filesystems that implement
|
||||||
* and directories this way, so we must punt for others.
|
* links and directories this way, so we must punt for others.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char *ufslike_filesystems[] = {
|
static const char *ufslike_filesystems[] = {
|
||||||
@ -129,13 +127,12 @@ fts_open(argv, options, compar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate/initialize the stream */
|
/* Allocate/initialize the stream */
|
||||||
if ((priv = malloc(sizeof(struct _fts_private))) == NULL)
|
if ((priv = malloc(sizeof(*priv))) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
memset(priv, 0, sizeof(struct _fts_private));
|
memset(priv, 0, sizeof(*priv));
|
||||||
sp = &priv->ftsp_fts;
|
sp = &priv->ftsp_fts;
|
||||||
sp->fts_compar = compar;
|
sp->fts_compar = compar;
|
||||||
sp->fts_options = options;
|
sp->fts_options = options;
|
||||||
sp->fts_priv = priv;
|
|
||||||
|
|
||||||
/* Shush, GCC. */
|
/* Shush, GCC. */
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
@ -1202,7 +1199,7 @@ fts_ufslinks(FTS *sp, const FTSENT *ent)
|
|||||||
struct _fts_private *priv;
|
struct _fts_private *priv;
|
||||||
const char **cpp;
|
const char **cpp;
|
||||||
|
|
||||||
priv = sp->fts_priv;
|
priv = (struct _fts_private *)sp;
|
||||||
/*
|
/*
|
||||||
* If this node's device is different from the previous, grab
|
* If this node's device is different from the previous, grab
|
||||||
* the filesystem information, and decide on the reliability
|
* the filesystem information, and decide on the reliability
|
||||||
@ -1224,5 +1221,5 @@ fts_ufslinks(FTS *sp, const FTSENT *ent)
|
|||||||
priv->ftsp_linksreliable = 0;
|
priv->ftsp_linksreliable = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return priv->ftsp_linksreliable;
|
return (priv->ftsp_linksreliable);
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,6 @@ typedef struct {
|
|||||||
#define FTS_STOP 0x200 /* (private) unrecoverable error */
|
#define FTS_STOP 0x200 /* (private) unrecoverable error */
|
||||||
int fts_options; /* fts_open options, global flags */
|
int fts_options; /* fts_open options, global flags */
|
||||||
void *fts_clientptr; /* thunk for sort function */
|
void *fts_clientptr; /* thunk for sort function */
|
||||||
struct _fts_private *fts_priv; /* implementation data */
|
|
||||||
} FTS;
|
} FTS;
|
||||||
|
|
||||||
typedef struct _ftsent {
|
typedef struct _ftsent {
|
||||||
|
@ -40,10 +40,9 @@ static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94";
|
|||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
#include "namespace.h"
|
#include "namespace.h"
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -64,7 +63,7 @@ static int fts_palloc(FTS *, size_t);
|
|||||||
static FTSENT *fts_sort(FTS *, FTSENT *, int);
|
static FTSENT *fts_sort(FTS *, FTSENT *, int);
|
||||||
static u_short fts_stat(FTS *, FTSENT *, int);
|
static u_short fts_stat(FTS *, FTSENT *, int);
|
||||||
static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
|
static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
|
||||||
static int fts_ufslinks(FTS *sp, const FTSENT *ent);
|
static int fts_ufslinks(FTS *, const FTSENT *);
|
||||||
|
|
||||||
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
|
#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
|
||||||
|
|
||||||
@ -80,25 +79,24 @@ static int fts_ufslinks(FTS *sp, const FTSENT *ent);
|
|||||||
#define BREAD 3 /* fts_read */
|
#define BREAD 3 /* fts_read */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal representation of FTS, including extra implementation details.
|
* Internal representation of an FTS, including extra implementation
|
||||||
* The FTS returned from fts_open is ftsp_fts from this structure, and it's
|
* details. The FTS returned from fts_open points to this structure's
|
||||||
* fts_priv in turn points back to this internal version. i.e. for a given
|
* ftsp_fts member (and can be cast to an _fts_private as required)
|
||||||
* fts_private *priv: &priv->fts_fts == (FTS *)f == priv->fts_fts.fts_priv
|
|
||||||
*/
|
*/
|
||||||
struct _fts_private {
|
struct _fts_private {
|
||||||
FTS ftsp_fts;
|
FTS ftsp_fts;
|
||||||
struct statfs ftsp_statfs;
|
struct statfs ftsp_statfs;
|
||||||
dev_t ftsp_dev;
|
dev_t ftsp_dev;
|
||||||
int ftsp_linksreliable;
|
int ftsp_linksreliable;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it knows
|
* The "FTS_NOSTAT" option can avoid a lot of calls to stat(2) if it
|
||||||
* that a directory could not possibly have subdirectories. This is decided
|
* knows that a directory could not possibly have subdirectories. This
|
||||||
* by looking at the link count: A subdirectory would increment its parent's
|
* is decided by looking at the link count: a subdirectory would
|
||||||
* link count by virtue of its own ".." entry.
|
* increment its parent's link count by virtue of its own ".." entry.
|
||||||
* This assumption only holds for UFS-like filesystems that implement links
|
* This assumption only holds for UFS-like filesystems that implement
|
||||||
* and directories this way, so we must punt for others.
|
* links and directories this way, so we must punt for others.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char *ufslike_filesystems[] = {
|
static const char *ufslike_filesystems[] = {
|
||||||
@ -129,13 +127,12 @@ fts_open(argv, options, compar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate/initialize the stream */
|
/* Allocate/initialize the stream */
|
||||||
if ((priv = malloc(sizeof(struct _fts_private))) == NULL)
|
if ((priv = malloc(sizeof(*priv))) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
memset(priv, 0, sizeof(struct _fts_private));
|
memset(priv, 0, sizeof(*priv));
|
||||||
sp = &priv->ftsp_fts;
|
sp = &priv->ftsp_fts;
|
||||||
sp->fts_compar = compar;
|
sp->fts_compar = compar;
|
||||||
sp->fts_options = options;
|
sp->fts_options = options;
|
||||||
sp->fts_priv = priv;
|
|
||||||
|
|
||||||
/* Shush, GCC. */
|
/* Shush, GCC. */
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
@ -1202,7 +1199,7 @@ fts_ufslinks(FTS *sp, const FTSENT *ent)
|
|||||||
struct _fts_private *priv;
|
struct _fts_private *priv;
|
||||||
const char **cpp;
|
const char **cpp;
|
||||||
|
|
||||||
priv = sp->fts_priv;
|
priv = (struct _fts_private *)sp;
|
||||||
/*
|
/*
|
||||||
* If this node's device is different from the previous, grab
|
* If this node's device is different from the previous, grab
|
||||||
* the filesystem information, and decide on the reliability
|
* the filesystem information, and decide on the reliability
|
||||||
@ -1224,5 +1221,5 @@ fts_ufslinks(FTS *sp, const FTSENT *ent)
|
|||||||
priv->ftsp_linksreliable = 0;
|
priv->ftsp_linksreliable = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return priv->ftsp_linksreliable;
|
return (priv->ftsp_linksreliable);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user