summaryrefslogtreecommitdiff
path: root/file_io/unix
diff options
context:
space:
mode:
authorrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2000-01-06 14:43:22 +0000
committerrbb <rbb@13f79535-47bb-0310-9956-ffa450edef68>2000-01-06 14:43:22 +0000
commit40de0d02842272180c1150c04345a2ea30aa7088 (patch)
tree1f0104f87e59b692031bbe592e8026b2088df304 /file_io/unix
parent7a9ce03860a139580710ac5042830ec21dcf5226 (diff)
downloadlibapr-40de0d02842272180c1150c04345a2ea30aa7088.tar.gz
Separate the stat structure from the file structure and use ap_stat and
ap_getfileinfo in apache. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@59574 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/unix')
-rw-r--r--file_io/unix/fileacc.c146
-rw-r--r--file_io/unix/filedup.c7
-rw-r--r--file_io/unix/fileio.h9
-rw-r--r--file_io/unix/filestat.c58
-rw-r--r--file_io/unix/open.c4
-rw-r--r--file_io/unix/pipe.c6
-rw-r--r--file_io/unix/readwrite.c9
7 files changed, 46 insertions, 193 deletions
diff --git a/file_io/unix/fileacc.c b/file_io/unix/fileacc.c
index 1acd7130a..af394ae94 100644
--- a/file_io/unix/fileacc.c
+++ b/file_io/unix/fileacc.c
@@ -104,144 +104,30 @@ mode_t get_fileperms(ap_fileperms_t mode)
}
/* ***APRDOC********************************************************
- * ap_status_t ap_get_filesize(ap_ssize_t *, ap_file_t *)
- * Return the size of the current file.
- * arg 1) The currently open file.
- * arg 2) The size of the file.
- */
-ap_status_t ap_get_filesize(ap_ssize_t *size, struct file_t *file)
-{
- if (file != NULL) {
- if (file->stated == 0) {
- ap_getfileinfo(file);
- }
- *size = file->size;
- return APR_SUCCESS;
- }
- else {
- *size = -1;
- return APR_ENOFILE;
- }
-}
-
-/* ***APRDOC********************************************************
- * ap_status_t ap_get_fileperms(ap_fileperms_t *, ap_file_t *)
- * Return the permissions of the current file.
- * arg 1) The currently open file.
- * arg 2) The permissions of the file.
- */
-ap_status_t ap_get_fileperms(ap_fileperms_t *perm, struct file_t *file)
-{
- if (file != NULL) {
- if (file->stated == 0) {
- ap_getfileinfo(file);
- }
- *perm = file->protection;
- return APR_SUCCESS;
- }
- else {
- *perm = -1;
- return APR_ENOFILE;
- }
-}
-
-/* ***APRDOC********************************************************
- * ap_status_t ap_get_fileatime(time_t *, ap_file_t *)
- * Return the last access time of the current file.
- * arg 1) The currently open file.
- * arg 2) The last access time of the file.
- */
-ap_status_t ap_get_fileatime(time_t *atime, struct file_t *file)
-{
- if (file != NULL) {
- if (file->stated == 0) {
- ap_getfileinfo(file);
- }
- *atime = file->atime;
- return APR_SUCCESS;
- }
- else {
- *atime = -1;
- return APR_ENOFILE;
- }
-}
-
-/* ***APRDOC********************************************************
- * ap_status_t ap_get_filectime(time_t *, ap_file_t *)
- * Return the time of the last change to the current file.
- * arg 1) The currently open file.
- * arg 2) The last change time of the file.
- */
-ap_status_t ap_get_filectime(time_t *ptime, struct file_t *file)
-{
- if (file != NULL) {
- if (file->stated == 0) {
- ap_getfileinfo(file);
- }
- *ptime = file->ctime;
- return APR_SUCCESS;
- }
- else {
- *ptime = -1;
- return APR_ENOFILE;
- }
-}
-
-/* ***APRDOC********************************************************
- * ap_status_t ap_get_filemtime(time_t *, ap_file_t *)
- * Return the last modified time of the current file.
- * arg 1) The currently open file.
- * arg 2) The last modified time of the file.
- */
-ap_status_t ap_get_filemtime(time_t *mtime, struct file_t *file)
-{
- if (file != NULL) {
- if (file->stated == 0) {
- ap_getfileinfo(file);
- }
- *mtime = file->mtime;
- return APR_SUCCESS;
- }
- else {
- *mtime = -1;
- return APR_ENOFILE;
- }
-}
-
-/* ***APRDOC********************************************************
* ap_status_t ap_get_filetype(ap_filetype_e, ap_file_t *)
* Return the type of the current file.
* arg 1) The currently open file.
* arg 2) The file type
*/
-ap_status_t ap_get_filetype(ap_filetype_e *type, struct file_t *file)
+ap_status_t ap_get_filetype(ap_filetype_e *type, ap_fileperms_t perms)
{
- if (file != NULL) {
- if (file->stated == 0) {
- ap_getfileinfo(file);
- }
- if (S_ISREG(file->protection))
- *type = APR_REG;
- if (S_ISDIR(file->protection))
- *type = APR_DIR;
- if (S_ISCHR(file->protection))
- *type = APR_CHR;
- if (S_ISBLK(file->protection))
- *type = APR_BLK;
- if (S_ISFIFO(file->protection))
- *type = APR_PIPE;
- if (S_ISLNK(file->protection))
- *type = APR_LNK;
+ if (S_ISREG(perms))
+ *type = APR_REG;
+ if (S_ISDIR(perms))
+ *type = APR_DIR;
+ if (S_ISCHR(perms))
+ *type = APR_CHR;
+ if (S_ISBLK(perms))
+ *type = APR_BLK;
+ if (S_ISFIFO(perms))
+ *type = APR_PIPE;
+ if (S_ISLNK(perms))
+ *type = APR_LNK;
#ifndef BEOS
- if (S_ISSOCK(file->protection))
- *type = APR_SOCK;
+ if (S_ISSOCK(perms))
+ *type = APR_SOCK;
#endif
- return APR_SUCCESS;
- }
- else {
- *type = APR_REG;
- return APR_ENOFILE;
- }
+ return APR_SUCCESS;
}
/* ***APRDOC********************************************************
diff --git a/file_io/unix/filedup.c b/file_io/unix/filedup.c
index 60e0b455e..14ee8429b 100644
--- a/file_io/unix/filedup.c
+++ b/file_io/unix/filedup.c
@@ -104,13 +104,6 @@ ap_status_t ap_dupfile(struct file_t **new_file, struct file_t *old_file)
}
(*new_file)->fname = ap_pstrdup(old_file->cntxt, old_file->fname);
(*new_file)->buffered = old_file->buffered;
- (*new_file)->protection = old_file->protection;
- (*new_file)->user = old_file->user;
- (*new_file)->group = old_file->group;
- (*new_file)->size = old_file->size;
- (*new_file)->atime = old_file->atime;
- (*new_file)->mtime = old_file->mtime;
- (*new_file)->ctime = old_file->ctime;
ap_register_cleanup((*new_file)->cntxt, (void *)(*new_file), file_cleanup,
ap_null_cleanup);
return APR_SUCCESS;
diff --git a/file_io/unix/fileio.h b/file_io/unix/fileio.h
index b1efb3d72..2f2a0957b 100644
--- a/file_io/unix/fileio.h
+++ b/file_io/unix/fileio.h
@@ -108,15 +108,8 @@ struct file_t {
char * fname;
int oflags;
int buffered;
- int stated;
int eof_hit;
- mode_t protection;
- uid_t user;
- gid_t group;
- off_t size;
- time_t atime;
- time_t mtime;
- time_t ctime;
+ int pipe;
int timeout;
};
diff --git a/file_io/unix/filestat.c b/file_io/unix/filestat.c
index 25472d889..383622b4a 100644
--- a/file_io/unix/filestat.c
+++ b/file_io/unix/filestat.c
@@ -63,20 +63,24 @@
* get the specified file's stats..
* arg 1) The file to get information about.
*/
-ap_status_t ap_getfileinfo(struct file_t *thefile)
+ap_status_t ap_getfileinfo(ap_finfo_t *finfo, struct file_t *thefile)
{
struct stat info;
int rv = stat(thefile->fname, &info);
if (rv == 0) {
- thefile->protection = info.st_mode;
- thefile->user = info.st_uid;
- thefile->group = info.st_gid;
- thefile->size = info.st_size;
- thefile->atime = info.st_atime;
- thefile->mtime = info.st_mtime;
- thefile->ctime = info.st_ctime;
- thefile->stated = 1;
+ finfo->protection = info.st_mode;
+ finfo->user = info.st_uid;
+ finfo->group = info.st_gid;
+ finfo->size = info.st_size;
+ finfo->inode = info.st_ino;
+ ap_make_time(&finfo->atime, thefile->cntxt);
+ ap_set_curtime(finfo->atime, info.st_atime);
+ ap_make_time(&finfo->mtime, thefile->cntxt);
+ ap_set_curtime(finfo->mtime, info.st_mtime);
+ ap_make_time(&finfo->ctime, thefile->cntxt);
+ ap_set_curtime(finfo->ctime, info.st_ctime);
+
return APR_SUCCESS;
}
else {
@@ -92,35 +96,23 @@ ap_status_t ap_getfileinfo(struct file_t *thefile)
* arg 2) The name of the file to stat.
* arg 3) the context to use to allocate the new file.
*/
-ap_status_t ap_stat(struct file_t **thefile, const char *fname, ap_context_t *cont)
+ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_context_t *cont)
{
struct stat info;
int rv = stat(fname, &info);
if (rv == 0) {
- if ((*thefile) == NULL) {
- /* Only allocate more space and initialize the object if it is
- * NULL when passed in.
- */
- (*thefile) = ap_pcalloc(cont, sizeof(struct file_t));
- if ((*thefile) == NULL) {
- return APR_ENOMEM;
- }
- (*thefile)->cntxt = cont;
- ap_register_cleanup((*thefile)->cntxt, (void *)(*thefile),
- file_cleanup, ap_null_cleanup);
- (*thefile)->fname = ap_pstrdup(cont, fname);
- (*thefile)->filehand = NULL;
- (*thefile)->filedes = -1;
- }
- (*thefile)->protection = info.st_mode;
- (*thefile)->user = info.st_uid;
- (*thefile)->group = info.st_gid;
- (*thefile)->size = info.st_size;
- (*thefile)->atime = info.st_atime;
- (*thefile)->mtime = info.st_mtime;
- (*thefile)->ctime = info.st_ctime;
- (*thefile)->stated = 1;
+ finfo->protection = info.st_mode;
+ finfo->user = info.st_uid;
+ finfo->group = info.st_gid;
+ finfo->size = info.st_size;
+ finfo->inode = info.st_ino;
+ ap_make_time(&finfo->atime, cont);
+ ap_set_curtime(finfo->atime, info.st_atime);
+ ap_make_time(&finfo->mtime, cont);
+ ap_set_curtime(finfo->mtime, info.st_mtime);
+ ap_make_time(&finfo->ctime, cont);
+ ap_set_curtime(finfo->ctime, info.st_ctime);
return APR_SUCCESS;
}
else {
diff --git a/file_io/unix/open.c b/file_io/unix/open.c
index 03ba96e92..11fdef6ab 100644
--- a/file_io/unix/open.c
+++ b/file_io/unix/open.c
@@ -176,7 +176,7 @@ ap_status_t ap_open(struct file_t **new, const char *fname, ap_int32_t flag, ap
if (flag & APR_DELONCLOSE) {
unlink(fname);
}
- (*new)->stated = 0; /* we haven't called stat for this file yet. */
+ (*new)->pipe = 0;
(*new)->timeout = -1;
(*new)->eof_hit = 0;
ap_register_cleanup((*new)->cntxt, (void *)(*new), file_cleanup,
@@ -265,7 +265,6 @@ ap_status_t ap_put_os_file(struct file_t **file, ap_os_file_t *thefile,
(*file)->buffered = 0;
(*file)->eof_hit = 0;
(*file)->timeout = -1;
- (*file)->stated = 0;
(*file)->filedes = *dafile;
return APR_SUCCESS;
}
@@ -321,7 +320,6 @@ ap_status_t ap_open_stderr(struct file_t **thefile, ap_context_t *cont)
(*thefile)->cntxt = cont;
(*thefile)->fname = NULL;
(*thefile)->filehand = NULL;
- (*thefile)->stated = 0;
(*thefile)->buffered = 0;
(*thefile)->eof_hit = 0;
diff --git a/file_io/unix/pipe.c b/file_io/unix/pipe.c
index d1ccd402b..5754e8aae 100644
--- a/file_io/unix/pipe.c
+++ b/file_io/unix/pipe.c
@@ -88,7 +88,7 @@ static ap_status_t pipenonblock(struct file_t *thefile)
*/
ap_status_t ap_set_pipe_timeout(struct file_t *thepipe, ap_int32_t timeout)
{
- if (thepipe->stated == -1) {
+ if (thepipe->pipe == 1) {
thepipe->timeout = timeout;
return APR_SUCCESS;
}
@@ -114,16 +114,16 @@ ap_status_t ap_create_pipe(struct file_t **in, struct file_t **out, ap_context_t
(*in)->cntxt = cont;
(*in)->filedes = filedes[0];
(*in)->buffered = 0;
+ (*in)->pipe = 1;
(*in)->fname = ap_pstrdup(cont, "PIPE");
- (*in)->stated = -1;
(*in)->timeout = -1;
(*out) = (struct file_t *)ap_palloc(cont, sizeof(struct file_t));
(*out)->cntxt = cont;
(*out)->filedes = filedes[1];
(*out)->buffered = 0;
+ (*in)->pipe = 1;
(*out)->fname = ap_pstrdup(cont, "PIPE");
- (*out)->stated = -1;
(*out)->timeout = -1;
pipenonblock(*in);
diff --git a/file_io/unix/readwrite.c b/file_io/unix/readwrite.c
index 7e74eaf23..47808c53c 100644
--- a/file_io/unix/readwrite.c
+++ b/file_io/unix/readwrite.c
@@ -193,7 +193,6 @@ ap_status_t ap_write(struct file_t *thefile, void *buf, ap_ssize_t *nbytes)
}
} /* BUFFERED ?? */
- thefile->stated = 0;
*nbytes = rv;
if (rv == -1) {
return errno;
@@ -234,7 +233,6 @@ ap_status_t ap_writev(struct file_t *thefile, const struct iovec_t *vec, ap_ssiz
}
else {
*iocnt = bytes;
- thefile->stated = 0;
return APR_SUCCESS;
}
}
@@ -250,7 +248,6 @@ ap_status_t ap_putc(char ch, ap_file_t *thefile)
{
if (thefile->buffered) {
if (fputc(ch, thefile->filehand) == ch) {
- thefile->stated = 0;
return APR_SUCCESS;
}
return errno;
@@ -258,7 +255,6 @@ ap_status_t ap_putc(char ch, ap_file_t *thefile)
if (write(thefile->filedes, &ch, 1) != 1) {
return errno;
}
- thefile->stated = 0;
return APR_SUCCESS;
}
@@ -272,13 +268,11 @@ ap_status_t ap_ungetc(char ch, ap_file_t *thefile)
{
if (thefile->buffered) {
if (ungetc(ch, thefile->filehand) == ch) {
- thefile->stated = 0;
return APR_SUCCESS;
}
return errno;
}
/* Not sure what to do in this case. For now, return SUCCESS. */
- thefile->stated = 0;
return APR_SUCCESS;
}
@@ -330,7 +324,6 @@ ap_status_t ap_puts(char *str, ap_file_t *thefile)
if (thefile->buffered) {
if (fputs(str, thefile->filehand)) {
- thefile->stated = 0;
return APR_SUCCESS;
}
return errno;
@@ -340,7 +333,6 @@ ap_status_t ap_puts(char *str, ap_file_t *thefile)
if (rv != len) {
return errno;
}
- thefile->stated = 0;
return APR_SUCCESS;
}
@@ -353,7 +345,6 @@ ap_status_t ap_flush(ap_file_t *thefile)
{
if (thefile->buffered) {
if (!fflush(thefile->filehand)) {
- thefile->stated = 0;
return APR_SUCCESS;
}
return errno;