rbb 99/04/09 07:37:05
Modified: apr/file_io/unix Makefile readwrite.c apr/test testfile.c docs fileio.txt impl.txt include apr_file_io.h Added: apr/file_io/unix dir.c Log: Added support for directory commands in apr. I also fixed a few warnings in the code. I updated the fileio.txt and impl.txt docs to reflect the current state of the fileio code. And lastly, I updated the test suite to include a few more tests. Revision Changes Path 1.5 +3 -1 apache-apr/apr/file_io/unix/Makefile Index: Makefile =================================================================== RCS file: /home/cvs/apache-apr/apr/file_io/unix/Makefile,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Makefile 1999/04/07 20:42:02 1.4 +++ Makefile 1999/04/09 14:36:57 1.5 @@ -47,7 +47,7 @@ LIB= libfile.a -OBJS= open.o readwrite.o filedup.o filestat.o seek.o\ +OBJS= open.o readwrite.o filedup.o filestat.o seek.o dir.o\ .c.o: $(CC) -c $(INCLUDES) $(CFLAGS) $< @@ -87,3 +87,5 @@ filedup.o: filedup.c filestat.o: filestat.c seek.o: seek.c +dir.o: dir.c + 1.3 +2 -2 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- readwrite.c 1999/04/07 19:38:41 1.2 +++ readwrite.c 1999/04/09 14:36:57 1.3 @@ -59,7 +59,7 @@ #include <errno.h> #include <unistd.h> -apr_size_t apr_read(apr_file_t *thefile, void *buf, apr_size_t nbytes) +apr_ssize_t apr_read(apr_file_t *thefile, void *buf, apr_size_t nbytes) { apr_size_t rv; @@ -73,7 +73,7 @@ return rv; } -apr_size_t apr_write(apr_file_t *thefile, void * buf, apr_size_t nbytes) +apr_ssize_t apr_write(apr_file_t *thefile, void * buf, apr_size_t nbytes) { apr_size_t rv; struct stat info; 1.1 apache-apr/apr/file_io/unix/dir.c Index: dir.c =================================================================== /* ==================================================================== * Copyright (c) 1999 The Apache Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * 4. The names "Apache Server" and "Apache Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Group. * For more information on the Apache Group and the Apache HTTP server * project, please see <http://www.apache.org/>. * */ #include "apr_file_io.h" #include <errno.h> #include <string.h> #include <dirent.h> apr_dir_t *apr_opendir(const char *dirname) { apr_dir_t *thedir = (apr_dir_t *)malloc(sizeof(apr_dir_t)); thedir->dirname = strdup(dirname); thedir->dirstruct = opendir(dirname); if (thedir->dirstruct == NULL) { free(thedir); return NULL; } else { return thedir; } } apr_status_t apr_closedir(apr_dir_t *thedir) { if (closedir(thedir->dirstruct) == 0) { free(thedir->dirname); free(thedir); thedir = NULL; return APR_SUCCESS; } else { return APR_FAILURE; } } apr_dirent_t *apr_readdir(apr_dir_t *thedir) { return readdir(thedir->dirstruct); } apr_status_t apr_rewinddir(apr_dir_t *thedir) { rewinddir(thedir->dirstruct); return APR_SUCCESS; } apr_status_t apr_make_dir(const char *path, apr_fileperms_t mode) { if (mkdir(path, mode) == 0) { return APR_SUCCESS; } else { return APR_FAILURE; } } apr_status_t apr_remove_dir(const char *path) { if (rmdir(path) == 0) { return APR_SUCCESS; } else { return APR_FAILURE; } } 1.7 +90 -11 apache-apr/apr/test/testfile.c Index: testfile.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testfile.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- testfile.c 1999/04/08 17:09:31 1.6 +++ testfile.c 1999/04/09 14:36:59 1.7 @@ -63,6 +63,7 @@ #endif int test_filedel(void); +int testdirs(void); int main() { @@ -74,7 +75,9 @@ char buf; char *filename = "test.fil"; - fprintf(stdout, "Opening file......."); + fprintf(stdout, "Testing file functions.\n"); + + fprintf(stdout, "\tOpening file......."); thefile = apr_open(filename, flag, 444); if (thefile == NULL) { perror("Didn't open file"); @@ -84,7 +87,7 @@ fprintf(stdout, "OK\n"); } - fprintf(stdout, "Checking file......."); + fprintf(stdout, "\tChecking file......."); if (thefile->filedes < 0) { fprintf(stderr, "Bad file des\n"); exit(-1); @@ -97,7 +100,7 @@ fprintf(stdout, "OK\n"); } - fprintf(stdout, "Writing to file......."); + fprintf(stdout, "\tWriting to file......."); nbytes = (apr_uint64_t)strlen("this is a test"); rv = apr_write(thefile, "this is a test", nbytes); @@ -113,7 +116,7 @@ fprintf(stdout, "OK\n"); } - fprintf(stdout, "Moving to start of file......."); + fprintf(stdout, "\tMoving to start of file......."); if (apr_seek(thefile, 0, SEEK_SET) != 0) { perror("couldn't seek to beginning of file."); exit(-1); @@ -122,7 +125,7 @@ fprintf(stdout, "OK\n"); } - fprintf(stdout, "Reading from the file......."); + fprintf(stdout, "\tReading from the file......."); nbytes = (apr_uint64_t)strlen("this is a test"); rv = apr_read(thefile, &buf, nbytes); if (rv == -1) { @@ -138,7 +141,7 @@ fprintf(stdout, "OK\n"); } - fprintf(stdout, "Closing File......."); + fprintf(stdout, "\tClosing File......."); status = apr_close(thefile); if (status == APR_FAILURE) { fprintf(stderr, "Couldn't close the file\n"); @@ -148,7 +151,7 @@ fprintf(stdout, "OK\n"); } - fprintf(stdout, "Deleting file......."); + fprintf(stdout, "\tDeleting file......."); status = apr_remove_file(thefile->fname); if (status == APR_FAILURE) { fprintf(stderr, "Couldn't delete the file\n"); @@ -158,7 +161,7 @@ fprintf(stdout, "OK\n"); } - fprintf(stdout, "Making sure it's gone......."); + fprintf(stdout, "\tMaking 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"); @@ -168,7 +171,7 @@ fprintf(stdout, "OK\n"); } - fprintf(stdout, "Deleting file while still open......."); + fprintf(stdout, "\tDeleting file while still open......."); if (test_filedel() == APR_FAILURE) { fprintf(stderr, "Something happened, please look into it.\n"); exit(-1); @@ -176,7 +179,9 @@ else { fprintf(stdout, "OK\n"); } - + + testdirs(); + return 1; } @@ -202,6 +207,80 @@ if (thefile != NULL) { return APR_FAILURE; } - + return APR_SUCCESS; } + +int testdirs(void) +{ + apr_dir_t *temp; + apr_dirent_t *entry, *entry1; + + fprintf(stdout, "Testing Directory functions.\n"); + + fprintf(stdout, "\tMakeing Directory......."); + if (apr_make_dir("testdir", 444) == APR_FAILURE) { + fprintf(stderr, "Could not create directory\n"); + return -1; + } + else { + fprintf(stdout, "OK\n"); + } + + if (apr_open("testdir/testfile", APR_READ | APR_WRITE | APR_CREATE, 444) != NULL) {; + return -1; + } + + fprintf(stdout, "\tOpening Directory......."); + if ((temp = apr_opendir("testdir")) == NULL) { + fprintf(stderr, "Could not open directory\n"); + return -1; + } + else { + fprintf(stdout, "OK\n"); + } + + fprintf(stdout, "\tReading Directory......."); + if ((entry = apr_readdir(temp)) == NULL) { + fprintf(stderr, "Could not read directory\n"); + return -1; + } + else { + fprintf(stdout, "OK\n"); + } + + + fprintf(stdout, "\tRewinding directory......."); + apr_rewinddir(temp); + + if ((entry1 = apr_readdir(temp)) != NULL) { + if (entry1->d_ino != entry->d_ino) { + fprintf(stderr, "Couldn't rewind directory\n"); + return -1; + } + else { + fprintf(stdout, "OK\n"); + } + } + + fprintf(stdout, "\tClosing Directory......."); + if (apr_closedir(temp) == APR_FAILURE) { + fprintf(stderr, "Could not close directory\n"); + return -1; + } + else { + fprintf(stdout, "OK\n"); + } + + fprintf(stdout, "\tRemoving Directory......."); + if (apr_remove_dir("testdir") == APR_FAILURE) { + fprintf(stderr, "Could not create directory\n"); + return -1; + } + else { + fprintf(stdout, "OK\n"); + } + + return 1; +} + 1.9 +36 -15 apache-apr/docs/fileio.txt Index: fileio.txt =================================================================== RCS file: /home/cvs/apache-apr/docs/fileio.txt,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- fileio.txt 1999/04/08 17:09:32 1.8 +++ fileio.txt 1999/04/09 14:37:00 1.9 @@ -98,7 +98,7 @@ 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 *) + apr_status_t apr_remove_file(char *) Removes the file pointed to by the character string Arguments: arg 1) The full path of the file to delete. @@ -106,26 +106,43 @@ 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: - arg 1) path to file - arg 3) Which access permissions to check for. - APRStatus apr_opendir(char *, APRDir *) + apr_dir_t *apr_opendir(const char *) Opens the specified directory stream. Arguments: arg 1) path of the directory to be opened. - arg 2) abstracted directory descriptor structure. - APRStatus apr_closedir(APRDir *) - Opens the specified directory stream. + return) abstracted directory descriptor structure. + + apr_status_t apr_closedir(apr_dir_t *) + closes the specified directory stream. Arguments: - arg 1) abstracted directory descriptor structure to be closed. - APRStatus apr_readdir(APRDir *, APRDirent *) + arg 1) abstracted directory descriptor structure to be closed. + return) APR_SUCCESS or APR_FAILURE + + apr_dirent_t *apr_readdir(apr_dir_t *) Retrieve the next directory entry from the specified directory. + Arguments: + arg 1) Abstracted directory descriptor to read from. + return) the next directory entry. + + apr_status_t *apr_rewinddir(apr_dir_t *) + Rewind directory to beginning of stream Arguments: - arg 1) Abstracted directory descriptor to read from. - arg 2) the next directory entry. + arg 1) Directory structure to rewind + return) APR_SUCCESS. (POSIX does not allow this function to fail!) + apr_status_t apr_make_dir(const char *, apr_fileperms_t) + Create a new directory on the disk + Arguments: + arg 1) The path of the new directory. + arg 2) The permissions to set for the new directory. + return) APR_SUCCESS or APR_FAILURE + + apr_status_t apr_remove_dir(const char *) + Remove a direcotry from the disk + Arguments: + arg 1) The path of the directory to remove. + return) APR_SUCCESS or APR_FAILURE + APRStatus apr_writev(APRFile, APRIOVec *, APRUInt64, APUInt64 *) Same as apr_write, except it gets the data from the APRIOVec array. Arguments: @@ -137,7 +154,11 @@ arg 4) number of bytes written. APR_FAILURE on failure. NOTES: apr_writev will write a complete entry from APRIOVec array before moving on to the next one. - + APRStatus apr_access(char *, APRFilePerms) + Determine the Accessibility of a file + Arguments: + arg 1) path to file + arg 3) Which access permissions to check for. **************** IMPLEMENTATION DETAILS ************** 1.2 +7 -7 apache-apr/docs/impl.txt Index: impl.txt =================================================================== RCS file: /home/cvs/apache-apr/docs/impl.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- impl.txt 1999/02/16 12:56:59 1.1 +++ impl.txt 1999/04/09 14:37:01 1.2 @@ -11,9 +11,8 @@ APRFile Windows: Handle. UNIX: structure { - APRINT file descriptor - FILE * file pointer - char * name + apr_int32_t file descriptor + char *name int mode int user id int group id @@ -29,11 +28,15 @@ because other types of programs may need it. For example, a database should not rely upon the data in a APRFile variable to be kept up to date. It is provided to help us "cheat" whenever possible. - + We have a file pointer and a file descriptor, because this is an easy way to determine if the output is buffered or not. We could do this with a simple boolean flag, it doesn't really metter to me. + APRDIR + UNIX: structure { + char *dirname + DIR *dirstruct; APRSocket in the future. */ @@ -68,9 +71,6 @@ Should be able to use same def as APRI_EXPORT APR_NETDB_BUF_SIZE size of host entry table. - APRDIR - 1) dir name: char * - 2) dir structure: OS specific. On UNIX => DIR APRIOVec 1) base addr: void *; starting point in memory of data 2) len: APRInt32; length of data. 1.11 +15 -1 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.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- apr_file_io.h 1999/04/08 17:09:34 1.10 +++ apr_file_io.h 1999/04/09 14:37:04 1.11 @@ -60,6 +60,7 @@ #include <sys/types.h> #include <fcntl.h> #include <time.h> +#include <dirent.h> #include "apr_general.h" #include "apr_errno.h" @@ -96,7 +97,13 @@ time_t ctime; } apr_file_t; +typedef struct apr_dir_t { + char *dirname; + DIR *dirstruct; +} apr_dir_t; + typedef mode_t apr_fileperms_t; +typedef struct dirent apr_dirent_t; /* Function definitions */ apr_file_t *apr_open(char *, apr_int32_t, apr_fileperms_t); @@ -109,7 +116,14 @@ apr_file_t *apr_dupfile(apr_file_t *); apr_status_t apr_getfileinfo(char *, apr_file_t *); apr_status_t apr_updatefileinfo(apr_file_t *); - apr_off_t apr_seek(apr_file_t *, apr_off_t, apr_seek_where_t); + +apr_dir_t *apr_opendir(const char *); +apr_status_t apr_closedir(apr_dir_t *); +apr_dirent_t *apr_readdir(apr_dir_t *); +apr_status_t apr_rewinddir(apr_dir_t *); +apr_status_t apr_make_dir(const char *, apr_fileperms_t); +apr_status_t apr_remove_dir(const char *); + #endif /* ! APR_FILE_IO_H */