rbb         99/04/30 08:19:59

  Modified:    apr/file_io/unix dir.c fileacc.c filedup.c fileio.h
                        filestat.c open.c pipe.c readwrite.c seek.c
               apr/include apr_lib.h
               apr/lib  apr_pools.c
               apr/misc/unix Makefile
               apr/test Makefile testfile.c
  Log:
  Changed fileio apr stuff to use apr_context_t's.  I haven't updated the docs,
  that's next.  I also modified the apr_pools stuff to link properly.  Lastly,
  I update the fileio test program.
  
  Revision  Changes    Path
  1.2       +22 -15    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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- dir.c     1999/04/09 14:36:57     1.1
  +++ dir.c     1999/04/30 15:19:50     1.2
  @@ -58,9 +58,19 @@
   #include <string.h>
   #include <dirent.h>
   
  -apr_dir_t *apr_opendir(const char *dirname)
  +apr_status_t dir_cleanup(apr_dir_t *thedir)
   {
  -    apr_dir_t *thedir = (apr_dir_t *)malloc(sizeof(apr_dir_t));
  +    if (closedir(thedir->dirstruct) == 0) {
  +        return APR_SUCCESS;
  +    }
  +    else {
  +        return APR_FAILURE;
  +    }
  +} 
  +
  +apr_dir_t *apr_opendir(apr_context_t *cont, const char *dirname)
  +{
  +    apr_dir_t *thedir = (apr_dir_t *)apr_palloc(cont->pool, 
sizeof(apr_dir_t));
   
       thedir->dirname = strdup(dirname);
       thedir->dirstruct = opendir(dirname);
  @@ -70,35 +80,32 @@
           return NULL;
       }    
       else {
  +        apr_register_cleanup(cont->pool, (void *)thedir, dir_cleanup, NULL);
           return thedir;
       }
   }
   
  -apr_status_t apr_closedir(apr_dir_t *thedir)
  +apr_status_t apr_closedir(apr_context_t *cont, apr_dir_t *thedir)
   {
  -    if (closedir(thedir->dirstruct) == 0) {
  -        free(thedir->dirname);
  -        free(thedir);
  -        thedir = NULL;
  +    if (dir_cleanup(thedir) == APR_SUCCESS) {
  +        apr_kill_cleanup(cont->pool, thedir, dir_cleanup);
           return APR_SUCCESS;
  -    }
  -    else {
  -        return APR_FAILURE;
       }
  -} 
  +    return APR_FAILURE;
  +}
   
  -apr_dirent_t *apr_readdir(apr_dir_t *thedir)
  +apr_dirent_t *apr_readdir(apr_context_t *cont, apr_dir_t *thedir)
   {
       return readdir(thedir->dirstruct);
   }
   
  -apr_status_t apr_rewinddir(apr_dir_t *thedir)
  +apr_status_t apr_rewinddir(apr_context_t *cont, apr_dir_t *thedir)
   {
       rewinddir(thedir->dirstruct);
       return APR_SUCCESS;
   }
   
  -apr_status_t apr_make_dir(const char *path, apr_fileperms_t mode)
  +apr_status_t apr_make_dir(apr_context_t *cont, const char *path, 
apr_fileperms_t mode)
   {
       if (mkdir(path, mode) == 0) {
           return APR_SUCCESS;
  @@ -108,7 +115,7 @@
       }
   }
   
  -apr_status_t apr_remove_dir(const char *path)
  +apr_status_t apr_remove_dir(apr_context_t *cont, const char *path)
   {
       if (rmdir(path) == 0) {
           return APR_SUCCESS;
  
  
  
  1.3       +1 -1      apache-apr/apr/file_io/unix/fileacc.c
  
  Index: fileacc.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/fileacc.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- fileacc.c 1999/04/26 13:07:46     1.2
  +++ fileacc.c 1999/04/30 15:19:51     1.3
  @@ -60,7 +60,7 @@
   
   /* A file to put ALL of the accessor functions for apr_file_t types. */
   
  -char * apr_get_filename(apr_file_t *thefile)
  +char * apr_get_filename(apr_context_t *cont, apr_file_t *thefile)
   {
       if (thefile != NULL) {
           return thefile->fname;
  
  
  
  1.6       +4 -2      apache-apr/apr/file_io/unix/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/filedup.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- filedup.c 1999/04/23 12:45:26     1.5
  +++ filedup.c 1999/04/30 15:19:51     1.6
  @@ -55,10 +55,11 @@
   #include <strings.h>
   #include "apr_file_io.h"
   #include "apr_general.h"
  +#include "fileio.h"
   
  -apr_file_t *apr_dupfile(apr_file_t *old_file)
  +apr_file_t *apr_dupfile(apr_context_t *cont, apr_file_t *old_file)
   {
  -    apr_file_t * new_file = (apr_file_t *)malloc(sizeof(apr_file_t));
  +    apr_file_t *new_file = (apr_file_t *)apr_palloc(cont->pool, 
sizeof(apr_file_t));
       
       if (new_file == NULL) {
           errno = ENOMEM;
  @@ -74,5 +75,6 @@
       old_file->atime = new_file->atime;    
       old_file->mtime = new_file->mtime;
       old_file->ctime = new_file->ctime;
  +    apr_register_cleanup(cont->pool, (void *)new_file, file_cleanup, NULL);
   }
   
  
  
  
  1.2       +3 -0      apache-apr/apr/file_io/unix/fileio.h
  
  Index: fileio.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/fileio.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- fileio.h  1999/04/12 17:48:19     1.1
  +++ fileio.h  1999/04/30 15:19:51     1.2
  @@ -62,6 +62,7 @@
   #include <time.h>
   #include <dirent.h>
   #include <sys/uio.h>
  +#include "apr_errno.h"
   
   /* Permissions flags */
   #define UREAD     S_IRUSR
  @@ -97,6 +98,8 @@
   typedef mode_t            fileperms_t;
   typedef struct dirent     dirent_t;
   typedef struct iovec      iovec_t;
  +
  +apr_status_t file_cleanup(struct file_t *);
   
   #endif  /* ! FILE_IO_H */
   
  
  
  
  1.2       +2 -2      apache-apr/apr/file_io/unix/filestat.c
  
  Index: filestat.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/filestat.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- filestat.c        1999/02/25 21:33:43     1.1
  +++ filestat.c        1999/04/30 15:19:51     1.2
  @@ -57,7 +57,7 @@
   #include "apr_general.h"
   #include "apr_errno.h"
   
  -apr_status_t apr_getfileinfo(char * fname, apr_file_t *thefile)
  +apr_status_t apr_getfileinfo(apr_context_t *cont, char * fname, apr_file_t 
*thefile)
   {
       struct stat info;
       int rv = stat(fname, &info);
  @@ -78,7 +78,7 @@
       }
   }
   
  -apr_status_t apr_updatefileinfo(apr_file_t *thefile)
  +apr_status_t apr_updatefileinfo(apr_context_t *cont, apr_file_t *thefile)
   {
       struct stat info;
       int rv = fstat(thefile->filedes, &info);
  
  
  
  1.14      +23 -18    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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- open.c    1999/04/12 17:48:19     1.13
  +++ open.c    1999/04/30 15:19:51     1.14
  @@ -58,8 +58,20 @@
   #include <errno.h>
   #include <string.h>
   
  -apr_file_t *apr_open(char *fname, apr_int32_t flag,  apr_fileperms_t mode)
  +apr_status_t file_cleanup(apr_file_t *file)
   {
  +    if (close(file->filedes) == 0) {
  +        file->filedes = -1;
  +        return APR_SUCCESS;
  +    }
  +    else {
  +        return APR_FAILURE;
  +     /* Are there any error conditions other than EINTR or EBADF? */
  +    }
  +}
  +
  +apr_file_t *apr_open(apr_context_t *cont, char *fname, apr_int32_t flag,  
apr_fileperms_t mode)
  +{
       int oflags = 0;
       apr_file_t *dafile = (apr_file_t *)malloc(sizeof(apr_file_t));
       struct stat info;
  @@ -75,7 +87,7 @@
       }
       else {
           errno = EACCES;
  -     free(dafile);
  +        dafile->filedes = -1;
           return NULL;
       }
   
  @@ -108,37 +120,30 @@
       
       if (dafile->filedes < 0) {
           dafile->filedes = -1;
  -        free(dafile->fname);
  -        free(dafile);
           return NULL;
       }
   
  -    if (apr_updatefileinfo(dafile) == APR_SUCCESS) {
  -     return dafile;
  +    if (apr_updatefileinfo(cont, dafile) == APR_SUCCESS) {
  +     apr_register_cleanup(cont->pool, (void *)dafile, file_cleanup, NULL);
  +        return dafile;
       }
       else {
           errno = ENOSTAT;
  -        free(dafile->fname);
  -     free(dafile);
  +        dafile->filedes = -1;
           return NULL;
       }
   }
   
  -apr_status_t apr_close(apr_file_t *file)
  +apr_status_t apr_close(apr_context_t *cont, apr_file_t *file)
   {
  -    if (close(file->filedes) == 0) {
  -        file->filedes = -1;
  -        free(file->fname);
  -        free(file);
  +    if (file_cleanup(file) == APR_SUCCESS) {
  +        apr_kill_cleanup(cont->pool, file, file_cleanup);
           return APR_SUCCESS;
  -    }
  -    else {
  -        return APR_FAILURE;
  -     /* Are there any error conditions other than EINTR or EBADF? */
       }
  +    return APR_FAILURE;
   }
   
  -apr_status_t apr_remove_file(char *path)
  +apr_status_t apr_remove_file(apr_context_t *cont, char *path)
   {
       if (unlink(path) == 0) {
           return APR_SUCCESS;
  
  
  
  1.2       +2 -2      apache-apr/apr/file_io/unix/pipe.c
  
  Index: pipe.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/pipe.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- pipe.c    1999/04/20 20:46:40     1.1
  +++ pipe.c    1999/04/30 15:19:52     1.2
  @@ -61,7 +61,7 @@
   #include <sys/types.h>
   #include <sys/stat.h>
   
  -apr_status_t apr_create_pipe(apr_file_t *in, apr_file_t *out)
  +apr_status_t apr_create_pipe(apr_context_t *cont, apr_file_t *in, apr_file_t 
*out)
   {
       int filedes[2];
   
  @@ -78,7 +78,7 @@
       return APR_SUCCESS;
   }
   
  -char *apr_create_namedpipe(char *dirpath, apr_fileperms_t mode)
  +char *apr_create_namedpipe(apr_context_t *cont, char *dirpath, 
apr_fileperms_t mode)
   {
       char *tmp;
   
  
  
  
  1.5       +3 -3      apache-apr/apr/file_io/unix/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/readwrite.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- readwrite.c       1999/04/09 18:02:41     1.4
  +++ readwrite.c       1999/04/30 15:19:52     1.5
  @@ -59,7 +59,7 @@
   #include <errno.h>
   #include <unistd.h>
   #include <sys/uio.h>
  -apr_ssize_t apr_read(apr_file_t *thefile, void *buf, apr_ssize_t nbytes)
  +apr_ssize_t apr_read(apr_context_t *cont, apr_file_t *thefile, void *buf, 
apr_ssize_t nbytes)
   {
       apr_size_t rv;
   
  @@ -73,7 +73,7 @@
       return rv;
   }
   
  -apr_ssize_t apr_write(apr_file_t *thefile, void *buf, apr_ssize_t nbytes)
  +apr_ssize_t apr_write(apr_context_t *cont, apr_file_t *thefile, void *buf, 
apr_ssize_t nbytes)
   {
       apr_size_t rv;
       struct stat info;
  @@ -94,7 +94,7 @@
       return rv;
   }
   
  -apr_ssize_t apr_writev(apr_file_t *thefile, const apr_iovec_t * vec, 
apr_ssize_t iocnt)
  +apr_ssize_t apr_writev(apr_context_t *cont, apr_file_t *thefile, const 
apr_iovec_t * vec, apr_ssize_t iocnt)
   {
       int bytes;
       if ((bytes = writev(thefile->filedes, vec, iocnt)) < 0) {
  
  
  
  1.2       +1 -1      apache-apr/apr/file_io/unix/seek.c
  
  Index: seek.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/file_io/unix/seek.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- seek.c    1999/04/09 14:11:38     1.1
  +++ seek.c    1999/04/30 15:19:52     1.2
  @@ -57,7 +57,7 @@
   #include <errno.h>
   #include <string.h>
   
  -apr_off_t apr_seek(apr_file_t *thefile, apr_off_t offset, apr_seek_where_t 
where)
  +apr_off_t apr_seek(apr_context_t *cont, apr_file_t *thefile, apr_off_t 
offset, apr_seek_where_t where)
   {
       return lseek(thefile->filedes, offset, where);
   }
  
  
  
  1.3       +16 -8     apache-apr/apr/include/apr_lib.h
  
  Index: apr_lib.h
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/include/apr_lib.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- apr_lib.h 1999/04/28 19:20:01     1.2
  +++ apr_lib.h 1999/04/30 15:19:55     1.3
  @@ -64,6 +64,7 @@
   #ifndef APR_LIB_H
   #define APR_LIB_H
   
  +#include "apr_general.h"
   #include "apr_config.h"
   #include "hsregex.h"
   
  @@ -112,12 +113,19 @@
    * Define the prototypes for the various APR GP routines.
    */
   API_EXPORT(char *) apr_cpystrn(char *d, const char *s, size_t l);
  -API_EXPORT(apr_mutex_t *) apr_create_mutex(void *m);
  +/*API_EXPORT(apr_mutex_t *) apr_create_mutex(void *m);*/
   API_EXPORT(int) apr_slack(int l, int h);
   API_EXPORT_NONSTD(int) apr_execle(const char *c, const char *a, ...);
   API_EXPORT_NONSTD(int) apr_execve(const char *c, const char *argv[],
                                  const char *envp[]);
   
  +#define apr_create_mutex(x) (0)
  +#define apr_release_mutex(x) (0)
  +#define apr_acquire_mutex(x) (0)
  +#define apr_islower(x) (0)
  +#define apr_isalpha(x) (0)
  +#define apr_isdigit(x) (0)
  +
   /*
    * Small utility macros to make things easier to read.  Not usually a
    * goal, to be sure..
  @@ -269,12 +277,12 @@
   API_EXPORT(void) apr_overlap_tables(apr_table_t *a, const apr_table_t *b,
                                    unsigned flags);
   API_EXPORT(void) apr_register_cleanup(apr_pool_t *p, void *data,
  -                                   void (*plain_cleanup) (void *),
  -                                   void (*child_cleanup) (void *));
  +                                   apr_status_t (*plain_cleanup) (void *),
  +                                   apr_status_t (*child_cleanup) (void *));
   API_EXPORT(void) apr_kill_cleanup(apr_pool_t *p, void *data,
  -                               void (*cleanup) (void *));
  +                               apr_status_t (*cleanup) (void *));
   API_EXPORT(void) apr_run_cleanup(apr_pool_t *p, void *data,
  -                              void (*cleanup) (void *));
  +                              apr_status_t (*cleanup) (void *));
   API_EXPORT(void) apr_cleanup_for_exec(void);
   API_EXPORT_NONSTD(void) apr_null_cleanup(void *data);
   API_EXPORT(void) apr_note_cleanups_for_fd(apr_pool_t *p, int fd);
  @@ -319,13 +327,13 @@
   API_EXPORT(int) apr_pcloseh(apr_pool_t *a, HANDLE hDevice);
   #endif /* WIN32 */
   
  -#ifdef TPF
  +/*#ifdef TPF*/
   #define apr_block_alarms() (0)
   #define apr_unblock_alarms() (0)
  -#else /* TPF */
  +/*#else 
   API_EXPORT(void) apr_block_alarms(void);
   API_EXPORT(void) apr_unblock_alarms(void);
  -#endif /* TPF */
  +#endif */
   
   #ifdef __cplusplus
   }
  
  
  
  1.2       +17 -15    apache-apr/apr/lib/apr_pools.c
  
  Index: apr_pools.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/lib/apr_pools.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_pools.c       1999/04/28 19:20:19     1.1
  +++ apr_pools.c       1999/04/30 15:19:56     1.2
  @@ -63,7 +63,9 @@
    */
   
   #include "apr_config.h"
  +#include "apr_general.h"
   #include "apr_pools.h"
  +#include "apr_lib.h"
   
   /*
    * Debugging support: Define this to enable code which helps detect re-use
  @@ -1708,14 +1710,14 @@
   
   struct cleanup {
       void *data;
  -    void (*plain_cleanup) (void *);
  -    void (*child_cleanup) (void *);
  +    apr_status_t (*plain_cleanup) (void *);
  +    apr_status_t (*child_cleanup) (void *);
       struct cleanup *next;
   };
   
   API_EXPORT(void) apr_register_cleanup(apr_pool_t *p, void *data,
  -                                   void (*plain_cleanup) (void *),
  -                                   void (*child_cleanup) (void *))
  +                                   apr_status_t (*plain_cleanup) (void *),
  +                                   apr_status_t (*child_cleanup) (void *))
   {
       struct cleanup *c;
   
  @@ -1728,7 +1730,7 @@
   }
   
   API_EXPORT(void) apr_kill_cleanup(apr_pool_t *p, void *data,
  -                               void (*cleanup) (void *))
  +                               apr_status_t (*cleanup) (void *))
   {
       struct cleanup *c = p->cleanups;
       struct cleanup **lastp = &p->cleanups;
  @@ -1745,7 +1747,7 @@
   }
   
   API_EXPORT(void) apr_run_cleanup(apr_pool_t *p, void *data,
  -                              void (*cleanup) (void *))
  +                              apr_status_t (*cleanup) (void *))
   {
       apr_block_alarms();              /* Run cleanup only once! */
       (*cleanup) (data);
  @@ -1807,7 +1809,7 @@
    * Files and file descriptors; these are just an application of the
    * generic cleanup interface.
    */
  -
  +#if 0 /*not really needed any more, apr takes care of this stuff */
   static void fd_cleanup(void *fdv)
   {
       close((int) (long) fdv);
  @@ -1883,12 +1885,12 @@
       return res;
   }
   #endif
  -
  +*/
   /* Note that we have separate plain_ and child_ cleanups for FILE *s,
    * since fclose() would flush I/O buffers, which is extremely undesirable;
    * we just close the descriptor.
    */
  -
  +/*
   static void file_cleanup(void *fpv)
   {
       fclose((FILE *) fpv);
  @@ -1913,14 +1915,14 @@
   
   #ifdef WIN32
       modeFlags = _S_IREAD | _S_IWRITE;
  -#else /* WIN32 */
  +#else 
       modeFlags = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
  -#endif /* WIN32 */
  +#endif
   
       apr_block_alarms();
   
       if (*mode == 'a') {
  -     /* Work around faulty implementations of fopen */
  +     /* Work around faulty implementations of fopen */ 
        baseFlag = (*(mode + 1) == '+') ? O_RDWR : O_WRONLY;
        desc = open(name, baseFlag | O_APPEND | O_CREAT,
                    modeFlags);
  @@ -2052,7 +2054,7 @@
       res = closesocket(sock);
   #ifdef WIN32
       errno = WSAGetLastError();
  -#endif /* WIN32 */
  +#endif 
       save_errno = errno;
       apr_kill_cleanup(a, (void *) (long) sock, socket_cleanup);
       apr_unblock_alarms();
  @@ -2096,7 +2098,7 @@
       apr_kill_cleanup(p, (void *) reg, regex_cleanup);
       apr_unblock_alarms();
   }
  -
  +#endif /* if 0 not really needed anymore.  APR takes care of this. */
   /*****************************************************************
    *
    * More grotty system stuff... subprocesses.  Frump.  These don't use
  @@ -2133,6 +2135,7 @@
   #define BINMODE
   #endif
   
  +#if 0
   static pid_t spawn_child_core(apr_pool_t *p,
                              int (*func) (void *, apr_child_info_t *),
                              void *data,enum kill_conditions kill_how,
  @@ -2448,7 +2451,6 @@
       return pid;
   }
   
  -#if 0
   API_EXPORT(int) apr_bspawn_child(apr_pool_t *p,
                                 int (*func) (void *v, apr_child_info_t *c),
                                 void *data, enum kill_conditions kill_how,
  
  
  
  1.2       +1 -1      apache-apr/apr/misc/unix/Makefile
  
  Index: Makefile
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/misc/unix/Makefile,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Makefile  1999/04/29 20:20:32     1.1
  +++ Makefile  1999/04/30 15:19:57     1.2
  @@ -45,7 +45,7 @@
   INCLUDES=$(INCLUDES1) $(INCLUDES0) $(EXTRA_INCLUDES)
   LDFLAGS=$(LDFLAGS1) $(EXTRA_LDFLAGS)
   
  -LIB=  libfile.a
  +LIB=  libaprmisc.a
   
   OBJS= start.o 
   
  
  
  
  1.8       +1 -1      apache-apr/apr/test/Makefile
  
  Index: Makefile
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/test/Makefile,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Makefile  1999/04/28 14:30:25     1.7
  +++ Makefile  1999/04/30 15:19:58     1.8
  @@ -12,7 +12,7 @@
   SRCDIR=..
   EXTRA_CFLAGS=-g 
   EXTRA_LDFLAGS=
  -EXTRA_LIBS=-L../threadproc -lthreadproc -L../file_io -lfile -L../network_io 
-lnetwork 
  +EXTRA_LIBS=-L../misc -laprmisc -L../lib -lapr -L../misc -laprmisc 
-L../threadproc -lthreadproc -L../file_io -lfile -L../network_io -lnetwork 
   EXTRA_INCLUDES=
   EXTRA_DEPS=
   OSDIR=
  
  
  
  1.12      +30 -27    apache-apr/apr/test/testfile.c
  
  Index: testfile.c
  ===================================================================
  RCS file: /home/cvs/apache-apr/apr/test/testfile.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- testfile.c        1999/04/12 17:54:11     1.11
  +++ testfile.c        1999/04/30 15:19:58     1.12
  @@ -62,11 +62,12 @@
   #include <unistd.h>
   #endif
   
  -int test_filedel(void);
  -int testdirs(void);
  +int test_filedel(apr_context_t *);
  +int testdirs(apr_context_t *);
   
   int main()
   {
  +    apr_context_t *context;
       apr_file_t *thefile = NULL;
       apr_status_t status = 0;
       apr_int32_t flag = APR_READ | APR_WRITE | APR_CREATE;
  @@ -75,10 +76,12 @@
       char buf;
       char *filename = "test.fil";
   
  +    context = apr_initialize(NULL);
  +
       fprintf(stdout, "Testing file functions.\n");
   
       fprintf(stdout, "\tOpening file.......");
  -    thefile = apr_open(filename, flag, APR_UREAD | APR_UWRITE | APR_GREAD);
  +    thefile = apr_open(context, filename, flag, APR_UREAD | APR_UWRITE | 
APR_GREAD);
       if (thefile == NULL) {
           perror("Didn't open file");
           exit(-1);
  @@ -88,11 +91,11 @@
       }
       
       fprintf(stdout, "\tChecking file.......");
  -    if (apr_valid_file(thefile) == APR_FAILURE) {
  +    if (thefile == NULL) {
           fprintf(stderr, "Bad file des\n");
           exit(-1);
       }
  -    if (strcmp(apr_get_filename(thefile), filename) != 0) {
  +    if (strcmp(apr_get_filename(context, thefile), filename) != 0) {
           fprintf(stderr, "wrong filename\n");
           exit(-1);
       }
  @@ -103,7 +106,7 @@
       fprintf(stdout, "\tWriting to file.......");
       
       nbytes = (apr_uint64_t)strlen("this is a test");
  -    rv = apr_write(thefile, "this is a test", nbytes);
  +    rv = apr_write(context, thefile, "this is a test", nbytes);
       if (rv == -1) {
           perror("something's wrong");
           exit(-1);
  @@ -117,7 +120,7 @@
       }
   
       fprintf(stdout, "\tMoving to start of file.......");
  -    if (apr_seek(thefile, 0, SEEK_SET) != 0) {
  +    if (apr_seek(context, thefile, 0, SEEK_SET) != 0) {
           perror("couldn't seek to beginning of file.");
           exit(-1);
       }
  @@ -127,7 +130,7 @@
   
       fprintf(stdout, "\tReading from the file.......");
       nbytes = (apr_uint64_t)strlen("this is a test");
  -    rv = apr_read(thefile, &buf, nbytes);
  +    rv = apr_read(context, thefile, &buf, nbytes);
       if (rv == -1) {
           perror("something's wrong");
           exit(-1);
  @@ -142,7 +145,7 @@
       }
   
       fprintf(stdout, "\tClosing File.......");
  -    status = apr_close(thefile);
  +    status = apr_close(context, thefile);
       if (status == APR_FAILURE) {
           fprintf(stderr, "Couldn't close the file\n");
           exit(-1); 
  @@ -152,7 +155,7 @@
       }
       
       fprintf(stdout, "\tDeleting file.......");
  -    status = apr_remove_file(filename);
  +    status = apr_remove_file(context, filename);
       if (status == APR_FAILURE) {
           fprintf(stderr, "Couldn't delete the file\n");
           exit(-1); 
  @@ -162,7 +165,7 @@
       }
       
       fprintf(stdout, "\tMaking sure it's gone.......");
  -    thefile = apr_open(filename, APR_READ, APR_UREAD | APR_UWRITE | 
APR_GREAD);
  +    thefile = apr_open(context, filename, APR_READ, APR_UREAD | APR_UWRITE | 
APR_GREAD);
       if (thefile != NULL) {
           fprintf(stderr, "I could open the file for some reason?\n");
           exit(-1);
  @@ -171,30 +174,30 @@
           fprintf(stdout, "OK\n");
       }
       
  -    testdirs(); 
  +    testdirs(context); 
    
       return 1;
   }
   
  -int test_filedel(void)
  +int test_filedel(apr_context_t *context)
   {
       apr_file_t *thefile;
       apr_int32_t flag = APR_READ | APR_WRITE | APR_CREATE;
       
  -    thefile = apr_open("testdel", flag, APR_UREAD | APR_UWRITE | APR_GREAD);
  +    thefile = apr_open(context, "testdel", flag, APR_UREAD | APR_UWRITE | 
APR_GREAD);
       if (thefile == NULL) {
            return APR_FAILURE;
       }
   
  -    if (apr_remove_file(thefile->fname) == APR_FAILURE) {
  +    if (apr_remove_file(context, thefile->fname) == APR_FAILURE) {
           return APR_FAILURE;
       }
   
  -    if (apr_close(thefile) == APR_FAILURE) {
  +    if (apr_close(context, thefile) == APR_FAILURE) {
           return APR_FAILURE;
       }
   
  -    thefile = apr_open("testdel", APR_READ, APR_UREAD | APR_UWRITE | 
APR_GREAD);
  +    thefile = apr_open(context, "testdel", APR_READ, APR_UREAD | APR_UWRITE 
| APR_GREAD);
       if (thefile == NULL) {
           return APR_FAILURE;
       }
  @@ -202,7 +205,7 @@
       return APR_SUCCESS;
   }
   
  -int testdirs(void)
  +int testdirs(apr_context_t *context)
   {
       apr_dir_t *temp;  
       apr_dirent_t *entry, *entry1;
  @@ -210,7 +213,7 @@
       fprintf(stdout, "Testing Directory functions.\n");
   
       fprintf(stdout, "\tMakeing Directory.......");
  -    if (apr_make_dir("testdir", APR_UREAD | APR_UWRITE | APR_UEXECUTE | 
APR_GREAD | APR_GWRITE | APR_GEXECUTE | APR_WREAD | APR_WWRITE | APR_WEXECUTE) 
== APR_FAILURE) {
  +    if (apr_make_dir(context, "testdir", APR_UREAD | APR_UWRITE | 
APR_UEXECUTE | APR_GREAD | APR_GWRITE | APR_GEXECUTE | APR_WREAD | APR_WWRITE | 
APR_WEXECUTE) == APR_FAILURE) {
           fprintf(stderr, "Could not create directory\n");
           return -1;
       }
  @@ -218,12 +221,12 @@
           fprintf(stdout, "OK\n");
       }
   
  -    if (apr_open("testdir/testfile", APR_READ | APR_WRITE | APR_CREATE, 
APR_UREAD | APR_UWRITE | APR_UEXECUTE) == NULL) {;
  +    if (apr_open(context, "testdir/testfile", APR_READ | APR_WRITE | 
APR_CREATE, APR_UREAD | APR_UWRITE | APR_UEXECUTE) == NULL) {;
           return -1;
       }
   
       fprintf(stdout, "\tOpening Directory.......");
  -    if ((temp = apr_opendir("testdir")) == NULL) {
  +    if ((temp = apr_opendir(context, "testdir")) == NULL) {
           fprintf(stderr, "Could not open directory\n");
           return -1;
       }
  @@ -232,7 +235,7 @@
       }
   
       fprintf(stdout, "\tReading Directory.......");
  -    if ((entry = apr_readdir(temp)) == NULL) {
  +    if ((entry = apr_readdir(context, temp)) == NULL) {
           fprintf(stderr, "Could not read directory\n");
           return -1;
       }
  @@ -242,9 +245,9 @@
       
   
       fprintf(stdout, "\tRewinding directory.......");
  -    apr_rewinddir(temp); 
  +    apr_rewinddir(context, temp); 
      
  -    if ((entry1 = apr_readdir(temp)) != NULL) {
  +    if ((entry1 = apr_readdir(context, temp)) != NULL) {
           if (entry1->d_ino != entry->d_ino) {
               fprintf(stderr, "Couldn't rewind directory\n");
               return -1;
  @@ -255,7 +258,7 @@
       }
       
       fprintf(stdout, "\tClosing Directory.......");
  -    if (apr_closedir(temp) == APR_FAILURE) {
  +    if (apr_closedir(context, temp) == APR_FAILURE) {
           fprintf(stderr, "Could not close directory\n");
           return -1;
       }
  @@ -264,7 +267,7 @@
       }
   
       fprintf(stdout, "\tRemoving file from directory.......");
  -    if (apr_remove_file("testdir/testfile") == APR_FAILURE) {
  +    if (apr_remove_file(context, "testdir/testfile") == APR_FAILURE) {
           fprintf(stderr, "Could not remove file\n");
           return -1;
       }
  @@ -273,7 +276,7 @@
       }
   
       fprintf(stdout, "\tRemoving Directory.......");
  -    if (apr_remove_dir("testdir") == APR_FAILURE) {
  +    if (apr_remove_dir(context, "testdir") == APR_FAILURE) {
           fprintf(stderr, "Could not create directory\n");
           return -1;
       }
  
  
  

Reply via email to