diff options
author | bjh <bjh@13f79535-47bb-0310-9956-ffa450edef68> | 2000-01-10 15:35:48 +0000 |
---|---|---|
committer | bjh <bjh@13f79535-47bb-0310-9956-ffa450edef68> | 2000-01-10 15:35:48 +0000 |
commit | 576c587f28775dda8cd4ef4cd20a20ae30df5e7d (patch) | |
tree | 021e6d03fbb1f8e119db6bed5c843e4a7043a095 /file_io/os2/filestat.c | |
parent | 733606d02d1e41b8db58faf2c19b894ee29143e2 (diff) | |
download | libapr-576c587f28775dda8cd4ef4cd20a20ae30df5e7d.tar.gz |
Rework ap_finfo_t to split the file type out of the protection field.
I've taken a stab at the unix implementation but tested only on OS/2.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@59584 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/os2/filestat.c')
-rw-r--r-- | file_io/os2/filestat.c | 102 |
1 files changed, 82 insertions, 20 deletions
diff --git a/file_io/os2/filestat.c b/file_io/os2/filestat.c index d638ebe9f..41914f975 100644 --- a/file_io/os2/filestat.c +++ b/file_io/os2/filestat.c @@ -53,48 +53,110 @@ * */ +#define INCL_DOS +#define INCL_DOSERRORS #include "fileio.h" #include "apr_file_io.h" #include "apr_lib.h" #include <sys/time.h> - -#define INCL_DOS #include <os2.h> -long os2date2unix( FDATE os2date, FTIME os2time ) +static void FS3_to_finfo(ap_finfo_t *finfo, FILESTATUS3 *fstatus) +{ + finfo->protection = (fstatus->attrFile & FILE_READONLY) ? 0555 : 0777; + + if (fstatus->attrFile & FILE_DIRECTORY) + finfo->filetype = APR_DIR; + else + finfo->filetype = APR_REG; + + finfo->user = 0; + finfo->group = 0; + finfo->inode = 0; + finfo->size = fstatus->cbFile; + ap_os2_time_to_ap_time(&finfo->atime, fstatus->fdateLastAccess, fstatus->ftimeLastAccess ); + ap_os2_time_to_ap_time(&finfo->mtime, fstatus->fdateLastWrite, fstatus->ftimeLastWrite ); + ap_os2_time_to_ap_time(&finfo->ctime, fstatus->fdateCreation, fstatus->ftimeCreation ); +} + + + +static ap_status_t handle_type(ap_filetype_e *ftype, HFILE file) { - struct tm tmpdate; + ULONG filetype, fileattr, rc; + + rc = DosQueryHType(file, &filetype, &fileattr); - memset(&tmpdate, 0, sizeof(tmpdate)); - tmpdate.tm_hour = os2time.hours; - tmpdate.tm_min = os2time.minutes; - tmpdate.tm_sec = os2time.twosecs * 2; + if (rc == 0) { + switch (filetype & 0xff) { + case 0: + *ftype = APR_REG; + break; + + case 1: + *ftype = APR_CHR; + break; - tmpdate.tm_mday = os2date.day; - tmpdate.tm_mon = os2date.month - 1; - tmpdate.tm_year = os2date.year + 80; - tmpdate.tm_isdst = -1; + case 2: + *ftype = APR_PIPE; + break; + } - return mktime( &tmpdate ); + return APR_SUCCESS; + } + return os2errno(rc); } -ap_status_t ap_getfileinfo(struct file_t *thefile) +ap_status_t ap_getfileinfo(ap_finfo_t *finfo, struct file_t *thefile) { - ULONG rc; - + ULONG rc; + FILESTATUS3 fstatus; + if (thefile->isopen) - rc = DosQueryFileInfo(thefile->filedes, FIL_STANDARD, &thefile->status, sizeof(thefile->status)); + rc = DosQueryFileInfo(thefile->filedes, FIL_STANDARD, &fstatus, sizeof(fstatus)); else - rc = DosQueryPathInfo(thefile->fname, FIL_STANDARD, &thefile->status, sizeof(thefile->status)); + rc = DosQueryPathInfo(thefile->fname, FIL_STANDARD, &fstatus, sizeof(fstatus)); + + if (rc == 0) { + FS3_to_finfo(finfo, &fstatus); + + if (finfo->filetype == APR_REG) { + if (thefile->isopen) { + return handle_type(&finfo->filetype, thefile->filedes); + } + } else { + return APR_SUCCESS; + } + } + + finfo->protection = 0; + finfo->filetype = APR_NOFILE; + return os2errno(rc); +} + + + +ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_context_t *cont) +{ + ULONG rc; + FILESTATUS3 fstatus; + + finfo->protection = 0; + finfo->filetype = APR_NOFILE; + rc = DosQueryPathInfo(fname, FIL_STANDARD, &fstatus, sizeof(fstatus)); if (rc == 0) { - thefile->validstatus = TRUE; + FS3_to_finfo(finfo, &fstatus); + return APR_SUCCESS; + } else if (rc == ERROR_INVALID_ACCESS) { + memset(finfo, 0, sizeof(ap_finfo_t)); + finfo->protection = 0444; + finfo->filetype = APR_CHR; return APR_SUCCESS; } - thefile->validstatus = FALSE; return os2errno(rc); } |