diff options
author | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2001-01-22 00:59:26 +0000 |
---|---|---|
committer | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2001-01-22 00:59:26 +0000 |
commit | 2659655aa7a9563734cfde82017e7374e09c9192 (patch) | |
tree | 8ff69e50728ada17bb1d71beded5c851afd72544 /file_io/unix/filestat.c | |
parent | 7a5bfc8f62e1cebfff1eac2a0d0ac638c0c1642c (diff) | |
download | libapr-2659655aa7a9563734cfde82017e7374e09c9192.tar.gz |
Just combine some common code on Unix. This should make things a bit
easier to maintain.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61092 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/unix/filestat.c')
-rw-r--r-- | file_io/unix/filestat.c | 77 |
1 files changed, 31 insertions, 46 deletions
diff --git a/file_io/unix/filestat.c b/file_io/unix/filestat.c index 1c38f6987..ffc1fa33c 100644 --- a/file_io/unix/filestat.c +++ b/file_io/unix/filestat.c @@ -81,6 +81,35 @@ static apr_filetype_e filetype_from_mode(int mode) return type; } +static apr_status_t fill_out_finfo(apr_finfo_t *finfo, struct stat info, + apr_int32_t wanted) +{ + finfo->valid = APR_FINFO_MIN | APR_FINFO_IDENT | APR_FINFO_OWNER | + APR_FINFO_PROT; + finfo->protection = apr_unix_mode2perms(info.st_mode); + finfo->filetype = filetype_from_mode(info.st_mode); + finfo->user = info.st_uid; + finfo->group = info.st_gid; + finfo->size = info.st_size; + finfo->inode = info.st_ino; + finfo->device = info.st_dev; + +/* We don't have nlinks in the finfo structure. Are we going to add it? RBB*/ +/* finfo->nlinks = info.st_nlink; */ + + apr_ansi_time_to_apr_time(&finfo->atime, info.st_atime); + apr_ansi_time_to_apr_time(&finfo->mtime, info.st_mtime); + apr_ansi_time_to_apr_time(&finfo->ctime, info.st_ctime); + if (wanted & APR_FINFO_CSIZE) { + finfo->csize = info.st_blocks * 512; + finfo->valid |= APR_FINFO_CSIZE; + } + if (finfo->filetype == APR_LNK) { + finfo->valid |= APR_FINFO_LINK; + } + return APR_SUCCESS; +} + apr_status_t apr_getfileinfo(apr_finfo_t *finfo, apr_int32_t wanted, apr_file_t *thefile) { @@ -88,30 +117,8 @@ apr_status_t apr_getfileinfo(apr_finfo_t *finfo, apr_int32_t wanted, if (fstat(thefile->filedes, &info) == 0) { finfo->cntxt = thefile->cntxt; - finfo->valid = APR_FINFO_MIN| APR_FINFO_IDENT | APR_FINFO_OWNER | APR_FINFO_PROT; - finfo->protection = apr_unix_mode2perms(info.st_mode); - finfo->filetype = filetype_from_mode(info.st_mode); - finfo->user = info.st_uid; - finfo->group = info.st_gid; - finfo->size = info.st_size; - finfo->inode = info.st_ino; - finfo->device = info.st_dev; - -/* We don't have nlinks in the finfo structure. Are we going to add it? RBB*/ -/* finfo->nlinks = info.st_nlink; */ - - apr_ansi_time_to_apr_time(&finfo->atime, info.st_atime); - apr_ansi_time_to_apr_time(&finfo->mtime, info.st_mtime); - apr_ansi_time_to_apr_time(&finfo->ctime, info.st_ctime); finfo->fname = thefile->fname; - if (wanted & APR_FINFO_CSIZE) { - finfo->csize = info.st_blocks * 512; - finfo->valid |= APR_FINFO_CSIZE; - } - if (finfo->filetype == APR_LNK) { - finfo->valid |= APR_FINFO_LINK; - } - return APR_SUCCESS; + return fill_out_finfo(finfo, info, wanted); } else { return errno; @@ -140,30 +147,8 @@ apr_status_t apr_stat(apr_finfo_t *finfo, const char *fname, if (srv == 0) { finfo->cntxt = cont; - finfo->valid = APR_FINFO_MIN| APR_FINFO_IDENT | APR_FINFO_OWNER | APR_FINFO_PROT; - finfo->protection = apr_unix_mode2perms(info.st_mode); - finfo->filetype = filetype_from_mode(info.st_mode); - finfo->user = info.st_uid; - finfo->group = info.st_gid; - finfo->size = info.st_size; - finfo->inode = info.st_ino; - finfo->device = info.st_dev; - -/* We don't have nlinks in the finfo structure. Are we going to add it? RBB*/ -/* finfo->nlinks = info.st_nlink; */ - - apr_ansi_time_to_apr_time(&finfo->atime, info.st_atime); - apr_ansi_time_to_apr_time(&finfo->mtime, info.st_mtime); - apr_ansi_time_to_apr_time(&finfo->ctime, info.st_ctime); finfo->fname = fname; - if (wanted & APR_FINFO_CSIZE) { - finfo->csize = info.st_blocks * 512; - finfo->valid |= APR_FINFO_CSIZE; - } - if (finfo->filetype == APR_LNK) { - finfo->valid |= APR_FINFO_LINK; - } - return APR_SUCCESS; + return fill_out_finfo(finfo, info, wanted); } else { #if !defined(ENOENT) || !defined(ENOTDIR) |