rbb         99/04/08 10:09:36

  Modified:    apr/file_io/unix open.c
               apr/test testfile.c
               docs     fileio.txt
               include  apr_file_io.h
  Log:
  Added a function to remove files.  apr_remove_file.  Also all the needed
  test functions to make sure it works.
  
  Revision  Changes    Path
  1.10      +11 -0     apache-apr/apr/file_io/unix/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/open.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- open.c    1999/02/25 21:33:43     1.9
  +++ open.c    1999/04/08 17:09:30     1.10
  @@ -137,3 +137,14 @@
        /* Are there any error conditions other than EINTR or EBADF? */
       }
   }
  +
  +apr_status_t apr_remove_file(char *path)
  +{
  +    if (unlink(path) == 0) {
  +        return APR_SUCCESS;
  +    }
  +    else {
  +        return APR_FAILURE;
  +    }
  +}
  +
  
  
  
  1.6       +58 -0     apache-apr/apr/test/testfile.c
  
  Index: testfile.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/test/testfile.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- testfile.c        1999/04/07 20:42:05     1.5
  +++ testfile.c        1999/04/08 17:09:31     1.6
  @@ -62,6 +62,8 @@
   #include <unistd.h>
   #endif
   
  +int test_filedel(void);
  +
   int main()
   {
       apr_file_t *thefile = NULL;
  @@ -145,5 +147,61 @@
       else {
           fprintf(stdout, "OK\n");
       }
  +    
  +    fprintf(stdout, "Deleting file.......");
  +    status = apr_remove_file(thefile->fname);
  +    if (status == APR_FAILURE) {
  +        fprintf(stderr, "Couldn't delete the file\n");
  +        exit(-1); 
  +    }
  +    else {
  +        fprintf(stdout, "OK\n");
  +    }
  +    
  +    fprintf(stdout, "Making sure it's gone.......");
  +    thefile = apr_open(filename, APR_READ, 444);
  +    if (thefile != NULL) {
  +        fprintf(stderr, "I could open the file for some reason?\n");
  +        exit(-1);
  +    }
  +    else {
  +        fprintf(stdout, "OK\n");
  +    }
  +    
  +    fprintf(stdout, "Deleting file while still open.......");
  +    if (test_filedel() == APR_FAILURE) {
  +        fprintf(stderr, "Something happened, please look into it.\n");
  +        exit(-1);
  +    }
  +    else {
  +        fprintf(stdout, "OK\n");
  +    }
  +    
       return 1;
  +}
  +
  +int test_filedel(void)
  +{
  +    apr_file_t *thefile;
  +    apr_int32_t flag = APR_READ | APR_WRITE | APR_CREATE;
  +    
  +    thefile = apr_open("testdel", flag, 444);
  +    if (thefile == NULL) {
  +         return APR_FAILURE;
  +    }
  +
  +    if (apr_remove_file(thefile->fname) == APR_FAILURE) {
  +        return APR_FAILURE;
  +    }
  +
  +    if (apr_close(thefile) == APR_FAILURE) {
  +        return APR_FAILURE;
  +    }
  +
  +    thefile = apr_open("testdel", APR_READ, 444);
  +    if (thefile != NULL) {
  +        return APR_FAILURE;
  +    }
  +    
  +    return APR_SUCCESS;
   }
  
  
  
  1.8       +8 -0      apache-apr/docs/fileio.txt
  
  Index: fileio.txt
  ===================================================================
  RCS file: /home/cvs/apache-apr/docs/fileio.txt,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- fileio.txt        1999/04/07 20:42:07     1.7
  +++ fileio.txt        1999/04/08 17:09:32     1.8
  @@ -98,6 +98,14 @@
                       APR_END -- add the offset to the current file size.
        return) Offset into file that the pointer was set to.
   
  + apr_status_t apr_rem_file(char *)
  +        Removes the file pointed to by the character string
  +     Arguments:
  +        arg 1)  The full path of the file to delete.
  +        return) APR_SUCCESS or APR_FAILURE.
  +Notes:  If the file is still open, it will not actually be removed until the
  +        all references of the file are closed.
  +
    APRStatus apr_access(char *, APRFilePerms)
        Determine the Accessibility of a file
        Arguments:
  
  
  
  1.10      +1 -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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- apr_file_io.h     1999/04/08 02:36:26     1.9
  +++ apr_file_io.h     1999/04/08 17:09:34     1.10
  @@ -101,6 +101,7 @@
   /*   Function definitions */
   apr_file_t *apr_open(char *, apr_int32_t, apr_fileperms_t);
   apr_status_t apr_close(apr_file_t *);
  +apr_status_t apr_remove_file(char *);
   
   apr_ssize_t apr_read(apr_file_t *, void *, apr_size_t);
   apr_ssize_t apr_write(apr_file_t *, void *, apr_size_t);
  
  
  

Reply via email to