You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@hyperreal.org on 1999/05/13 20:38:06 UTC

cvs commit: apache-apr/docs fileio.txt

rbb         99/05/13 11:38:06

  Modified:    apr/file_io/unix dir.c
               apr/test testfile.c
               include  apr_errno.h apr_file_io.h
               docs     fileio.txt
  Log:
  The directory chagnes discussed on new-httpd are finally done.
  
  Revision  Changes    Path
  1.6       +84 -3     apache-apr/apr/file_io/unix/dir.c
  
  Index: dir.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/dir.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- dir.c	1999/05/12 19:15:29	1.5
  +++ dir.c	1999/05/13 18:38:02	1.6
  @@ -56,12 +56,15 @@
   #include <errno.h>
   #include <string.h>
   #include <dirent.h>
  +#include <sys/stat.h>
   #include "fileio.h"
   #include "apr_file_io.h"
  +#include "apr_lib.h"
   
  -ap_status_t dir_cleanup(struct dir_t *thedir)
  +ap_status_t dir_cleanup(void *thedir)
   {
  -    if (closedir(thedir->dirstruct) == 0) {
  +    struct dir_t *dir = thedir;
  +    if (closedir(dir->dirstruct) == 0) {
           return APR_SUCCESS;
       }
       else {
  @@ -75,6 +78,7 @@
   
       thedir->dirname = strdup(dirname);
       thedir->dirstruct = opendir(dirname);
  +    thedir->entry = NULL;
   
       if (thedir->dirstruct == NULL) {
           free(thedir);
  @@ -82,7 +86,6 @@
       }    
       else {
           ap_register_cleanup(cont->pool, (void *)thedir, dir_cleanup, NULL);
  -        thedir->entry = NULL;
           return thedir;
       }
   }
  @@ -132,4 +135,82 @@
       }
   }
   
  +ap_ssize_t ap_dir_entry_size(ap_context_t *context, ap_dir_t *thedir)
  +{
  +    struct stat filestat;
  +    char *fname = NULL;    
  +
  +    if (thedir->entry == NULL) {
  +        errno = ENOFILE;
  +        return -1;
  +    }
  +    fname = ap_pstrcat(context->pool, thedir->dirname, "/", 
  +                       thedir->entry->d_name, NULL);
  +    if (stat(fname, &filestat) == -1) {
  +        errno = ENOSTAT;
  +        return -1;
  +    }
  +    
  +    return filestat.st_size;
  +}
  +
  +time_t ap_dir_entry_mtime(ap_context_t *context, ap_dir_t *thedir)
  +{
  +    struct stat filestat;
  +    char *fname = NULL;
  +
  +    if (thedir->entry == NULL) {
  +        errno = ENOFILE;
  +        return -1;
  +    }
  +
  +    fname = ap_pstrcat(context->pool, thedir->dirname, "/", 
  +                       thedir->entry->d_name, NULL);
  +    if (stat(fname, &filestat) == -1) {
  +        errno = ENOSTAT;
  +        return -1;
  +    }
  +    
  +    return filestat.st_mtime;
  +}
  + 
  +ap_filetype_e ap_dir_entry_ftype(ap_context_t *context, ap_dir_t *thedir)
  +{
  +    struct stat filestat;
  +    char *fname = NULL;
  +
  +    if (thedir->entry == NULL) {
  +        errno = ENOFILE;
  +        return -1;
  +    }
  +
  +    fname = ap_pstrcat(context->pool, thedir->dirname, "/", 
  +                       thedir->entry->d_name, NULL);
  +    if (stat(fname, &filestat) == -1) {
  +        errno = ENOSTAT;
  +        return -1;
  +    }
  +
  +    if (S_ISREG(filestat.st_mode))
  +        return APR_REG;    
  +    if (S_ISDIR(filestat.st_mode))
  +        return APR_DIR;    
  +    if (S_ISCHR(filestat.st_mode))
  +        return APR_CHR;    
  +    if (S_ISBLK(filestat.st_mode))
  +        return APR_BLK;    
  +    if (S_ISFIFO(filestat.st_mode))
  +        return APR_PIPE;    
  +    if (S_ISLNK(filestat.st_mode))
  +        return APR_LNK;    
  +    if (S_ISSOCK(filestat.st_mode))
  +        return APR_SOCK;    
  +}
  +
  +char * ap_get_dir_filename(ap_context_t * context, ap_dir_t *thedir)
  +{
  +    char *name = (char *)ap_palloc(context->pool, strlen(thedir->entry->d_name));
  +    name = ap_pstrdup(context->pool, thedir->entry->d_name);
  +    return name;
  +}
   
  
  
  
  1.17      +35 -2     apache-apr/apr/test/testfile.c
  
  Index: testfile.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/test/testfile.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- testfile.c	1999/05/13 13:06:51	1.16
  +++ testfile.c	1999/05/13 18:38:04	1.17
  @@ -208,6 +208,9 @@
   int testdirs(ap_context_t *context)
   {
       ap_dir_t *temp;  
  +    ap_file_t *file;
  +    ap_ssize_t bytes;
  +    char *fname;
   
       fprintf(stdout, "Testing Directory functions.\n");
   
  @@ -220,10 +223,12 @@
           fprintf(stdout, "OK\n");
       }
   
  -    if (ap_open(context, "testdir/testfile", APR_READ | APR_WRITE | APR_CREATE, APR_UREAD | APR_UWRITE | APR_UEXECUTE) == NULL) {;
  +    if ((file = ap_open(context, "testdir/testfile", APR_READ | APR_WRITE | APR_CREATE, APR_UREAD | APR_UWRITE | APR_UEXECUTE)) == NULL) {;
           return -1;
       }
   
  +    bytes = ap_write(context, file, "Another test!!", strlen("Another test!!")); 
  +
       fprintf(stdout, "\tOpening Directory.......");
       if ((temp = ap_opendir(context, "testdir")) == NULL) {
           fprintf(stderr, "Could not open directory\n");
  @@ -240,9 +245,37 @@
       }
       else {
           fprintf(stdout, "OK\n");
  +    }
  +   
  +    fprintf(stdout, "\tGetting Information about the file.......\n");
  +    fprintf(stdout, "\t\tFile name.......");
  +    do {
  +        /* Because I want the file I created, I am skipping the "." and ".."
  +         * files that are here. 
  +         */
  +        ap_readdir(context, temp); 
  +        fname = ap_get_dir_filename(context, temp);
  +    } while (fname[0] == '.');
  +    if (strcmp(fname, "testfile")) {
  +        fprintf(stderr, "Got wrong file name %s\n", fname);
  +        return -1;
  +    }
  +    fprintf(stdout, "OK\n");
  +
  +    fprintf(stdout, "\t\tFile type.......");
  +    if (ap_dir_entry_ftype(context, temp) != APR_REG) {
  +        fprintf(stderr, "Got wrong file type\n");
  +        return -1;
       }
  -    
  +    fprintf(stdout, "OK\n");
   
  +    fprintf(stdout, "\t\tFile size.......");
  +    if (ap_dir_entry_size(context, temp) != bytes) {
  +        fprintf(stderr, "Got wrong file size %d\n", ap_dir_entry_size(context, temp));
  +        return -1;
  +    }
  +    fprintf(stdout, "OK\n");
  +     
       fprintf(stdout, "\tRewinding directory.......");
       ap_rewinddir(context, temp); 
       fprintf(stdout, "OK\n");
  
  
  
  1.9       +1 -0      apache-apr/include/apr_errno.h
  
  Index: apr_errno.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/include/apr_errno.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- apr_errno.h	1999/05/12 12:00:10	1.8
  +++ apr_errno.h	1999/05/13 18:38:04	1.9
  @@ -72,6 +72,7 @@
   
   #define ENOSTAT 4001
   #define ENOPOOL 4002
  +#define ENOFILE 4003
   
   #ifdef __cplusplus
   }
  
  
  
  1.26      +8 -0      apache-apr/include/apr_file_io.h
  
  Index: apr_file_io.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/include/apr_file_io.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- apr_file_io.h	1999/05/12 19:15:26	1.25
  +++ apr_file_io.h	1999/05/13 18:38:05	1.26
  @@ -63,6 +63,9 @@
   extern "C" {
   #endif /* __cplusplus */
   
  +typedef enum {APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE, APR_LNK, 
  +              APR_SOCK} ap_filetype_e; 
  +
   /* Flags for ap_open */
   #define APR_READ     1           /* Open the file for reading */
   #define APR_WRITE    2           /* Open the file for writing */
  @@ -126,6 +129,11 @@
   
   /*accessor and general file_io functions. */
   char *ap_get_filename(ap_context_t *, ap_file_t *);
  +char *ap_get_dir_filename(ap_context_t *, ap_dir_t *);
  +
  +ap_ssize_t ap_dir_entry_size(ap_context_t *, ap_dir_t *);
  +time_t ap_dir_entry_mtime(ap_context_t *, ap_dir_t *);
  +ap_filetype_e ap_dir_entry_ftype(ap_context_t *, ap_dir_t *);
   
   #ifdef __cplusplus
   }
  
  
  
  1.22      +30 -0     apache-apr/docs/fileio.txt
  
  Index: fileio.txt
  ===================================================================
  RCS file: /home/cvs/apache-apr/docs/fileio.txt,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- fileio.txt	1999/05/12 18:03:01	1.21
  +++ fileio.txt	1999/05/13 18:38:05	1.22
  @@ -134,6 +134,8 @@
           arg 1)  The context to use.
   	arg 2)  Abstracted directory descriptor to read from.
   	return) APR_SUCCESS or APR_FAILURE.
  +NOTE:  This is garaunteed to have the files "." and ".." as the first two 
  +       files. 
   
    ap_status_t *ap_rewinddir(ap_context_t *, ap_dir_t *)
           Rewind directory to beginning of stream
  @@ -156,6 +158,34 @@
           arg 1)  The context to use.
           arg 2)  The path of the directory to remove.
           return) APR_SUCCESS or APR_FAILURE
  + 
  + char *ap_get_dir_filename(ap_context_t *, apr_dir_t *)
  +        Get the name of the current file in a directory.
  +     Arguments:
  +        arg 1)  The context to use
  +        arg 2)  The directory we care about.
  +        return) the file name
  + 
  + ap_ssize_t ap_dir_entry_size(ap_context_t *, apr_dir_t *)
  +        Get the size of the current file in a directory.
  +     Arguments:
  +        arg 1)  The context to use
  +        arg 2)  The directory we care about.
  +        return) the size of the file in bytes 
  +
  + ap_time_t ap_dir_entry_mtime(ap_context_t *, apr_dir_t *)
  +        Get the last modified time of the current file in a directory.
  +     Arguments:
  +        arg 1)  The context to use
  +        arg 2)  The directory we care about.
  +        return) the time the file was last modified 
  +
  + ap_filetype_e ap_dir_entry_ftype(ap_context_t *, apr_dir_t *)
  +        Get the file type of the current file in a directory.
  +     Arguments:
  +        arg 1)  The context to use
  +        arg 2)  The directory we care about.
  +        return) the type of the file 
   
    ap_ssize_t ap_writev(ap_context_t *, ap_file_t, ap_iovec_t *, ap_ssize_t)
   	Same as ap_write, except it gets the data from the APRIOVec array.