httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stodd...@hyperreal.org
Subject cvs commit: apache-2.0/src/lib/apr/file_io/win32 file_io.def fileacc.c fileio.h filestat.c readwrite.c
Date Fri, 24 Sep 1999 18:49:11 GMT
stoddard    99/09/24 11:49:08

  Modified:    src/lib/apr/file_io/win32 file_io.def fileacc.c fileio.h
                        filestat.c readwrite.c
  Log:
  Win32 fileio stuff. Not tested and needs to be reviewed & debugged.
  
  Revision  Changes    Path
  1.3       +6 -5      apache-2.0/src/lib/apr/file_io/win32/file_io.def
  
  Index: file_io.def
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/file_io.def,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- file_io.def	1999/09/22 19:50:04	1.2
  +++ file_io.def	1999/09/24 18:49:00	1.3
  @@ -36,8 +36,9 @@
       	ap_get_os_dir   @29
       	ap_putc   @30
       	ap_getc   @31
  -    	ap_fprintf   @32
  -    	ap_eof   @33
  -
  -	
  -	
  +	ap_puts @32
  +	ap_gets @33
  +	ap_flush @34
  +    	ap_fprintf   @35
  +    	ap_eof   @36
  +	ap_get_filetype @37
  
  
  
  1.3       +17 -0     apache-2.0/src/lib/apr/file_io/win32/fileacc.c
  
  Index: fileacc.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/fileacc.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- fileacc.c	1999/09/22 17:53:17	1.2
  +++ fileacc.c	1999/09/24 18:49:01	1.3
  @@ -162,7 +162,24 @@
           return APR_ENOFILE;
       }
   }
  +ap_status_t ap_get_filetype(struct file_t *file, ap_filetype_e *type)
  +{    
  +    if (file != NULL) {
  +        if (!file->stated) {
  +            ap_getfileinfo(file);
  +        }
  +        if (file->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  +            *type = APR_DIR;
  +        else
  +            *type = APR_REG;
   
  +        return APR_SUCCESS;
  +    }
  +    else {
  +        *type = APR_REG;
  +        return APR_ENOFILE;
  +    }
  +}
   ap_status_t ap_get_filedata(struct file_t *file, char *key, void *data)
   {    
       if (file != NULL) {
  
  
  
  1.2       +7 -8      apache-2.0/src/lib/apr/file_io/win32/fileio.h
  
  Index: fileio.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/fileio.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- fileio.h	1999/08/17 15:59:36	1.1
  +++ fileio.h	1999/09/24 18:49:02	1.2
  @@ -84,14 +84,13 @@
       ap_context_t *cntxt;
       HANDLE filehand;
       char *fname;
  -    char *demonfname;
  -	char *lowerdemonfname;
  +    DWORD dwFileAttributes;
  +    char *demonfname; /* Is this necessary */
  +    char *lowerdemonfname; /* Is this necessary */
       int buffered;
  -	int append;
  +    int stated;
  +    int append; /* is this necessary?*/
       int eof_hit;
  -/*    mode_t protection;
  -    uid_t user;
  -    gid_t group;*/
       off_t size;
       time_t atime;
       time_t mtime;
  @@ -102,12 +101,12 @@
       ap_context_t *cntxt;
       char *dirname;
       HANDLE dirhand;
  -	WIN32_FIND_DATA *entry;
  +    WIN32_FIND_DATA *entry;
   };
   
   struct iovec_t {
       ap_context_t *cntxt;
  -    struct iovec *iovec;
  +    struct iovec *iov;
   };
   
   ap_status_t file_cleanup(void *);
  
  
  
  1.2       +9 -11     apache-2.0/src/lib/apr/file_io/win32/filestat.c
  
  Index: filestat.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/filestat.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- filestat.c	1999/08/17 15:59:37	1.1
  +++ filestat.c	1999/09/24 18:49:02	1.2
  @@ -58,21 +58,19 @@
   #include "apr_file_io.h"
   #include "apr_general.h"
   #include "apr_errno.h"
  -
  +/* TODO: Handle the case when the file has not been opened */
   ap_status_t ap_getfileinfo(struct file_t *thefile)
   {
  -	FILETIME atime, ctime, mtime;
  +    BY_HANDLE_FILE_INFORMATION info;
  +    GetFileInformationByHandle(thefile->filehand, &info);
  +    thefile->dwFileAttributes = info.dwFileAttributes;
  +    thefile->size = info.nFileSizeLow; /* This is broken for files > ?? */
  +    thefile->atime = WinTimeToUnixTime(&info.ftLastAccessTime);
  +    thefile->ctime = WinTimeToUnixTime(&info.ftCreationTime);
  +    thefile->mtime = WinTimeToUnixTime(&info.ftLastWriteTime);
  +    thefile->stated = 1; 
   
  -/*        thefile->protection = info.st_mode;
  -        thefile->user = info.st_uid;
  -        thefile->group = info.st_gid;*/
  -	thefile->size = GetFileSize(thefile->filehand, NULL);
  -	GetFileTime(thefile->filehand, &ctime, &atime, &mtime);
  -	thefile->atime = WinTimeToUnixTime(&atime);
  -	thefile->mtime = WinTimeToUnixTime(&mtime);
  -	thefile->ctime = WinTimeToUnixTime(&ctime);
       return APR_SUCCESS;
   }
  -
   
   
  
  
  
  1.2       +82 -30    apache-2.0/src/lib/apr/file_io/win32/readwrite.c
  
  Index: readwrite.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/readwrite.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- readwrite.c	1999/08/17 15:59:37	1.1
  +++ readwrite.c	1999/09/24 18:49:03	1.2
  @@ -62,7 +62,7 @@
   
   ap_status_t ap_read(struct file_t *thefile, void *buf, ap_ssize_t *nbytes)
   {
  -	DWORD bread;
  +    DWORD bread;
       int lasterror;
   
       if (thefile->filehand == INVALID_HANDLE_VALUE) {
  @@ -71,18 +71,18 @@
       }
       
       if (ReadFile(thefile->filehand, buf, *nbytes, &bread, NULL)) {
  -		*nbytes = bread;
  -	    return APR_SUCCESS;
  -	}
  -	*nbytes = -1;
  +        *nbytes = bread;
  +        return APR_SUCCESS;
  +    }
  +    *nbytes = -1;
       lasterror = GetLastError();
  -	return APR_EEXIST;
  +    return APR_EEXIST;
   }
   
   ap_status_t ap_write(struct file_t *thefile, void *buf, ap_ssize_t *nbytes)
   {
       DWORD bwrote;
  -	FILETIME atime, mtime, ctime;
  +    FILETIME atime, mtime, ctime;
   	
       if (thefile->filehand == INVALID_HANDLE_VALUE) {
           *nbytes = -1;
  @@ -90,40 +90,45 @@
       }
   
       if (WriteFile(thefile->filehand, buf, *nbytes, &bwrote, NULL)) {
  -		if (strcmp(thefile->fname, "PIPE")) {
  -			FlushFileBuffers(thefile->filehand);
  -			thefile->size = GetFileSize(thefile->filehand, NULL);
  -			GetFileTime(thefile->filehand, &ctime, &atime, &mtime);
  -			thefile->atime = WinTimeToUnixTime(&atime);
  -			thefile->mtime = WinTimeToUnixTime(&mtime);
  -			thefile->ctime = WinTimeToUnixTime(&ctime);
  -		}
  -		*nbytes = bwrote;
  -		return APR_SUCCESS;
  -	}
  -	(*nbytes) = -1;
  -	return APR_EEXIST;
  +        if (strcmp(thefile->fname, "PIPE")) {
  +            FlushFileBuffers(thefile->filehand);
  +            thefile->size = GetFileSize(thefile->filehand, NULL);
  +            GetFileTime(thefile->filehand, &ctime, &atime, &mtime);
  +            thefile->atime = WinTimeToUnixTime(&atime);
  +            thefile->mtime = WinTimeToUnixTime(&mtime);
  +            thefile->ctime = WinTimeToUnixTime(&ctime);
  +        }
  +        *nbytes = bwrote;
  +        return APR_SUCCESS;
  +    }
  +    (*nbytes) = -1;
  +    return APR_EEXIST;
   }
   /*
  + * Too bad WriteFileGather() is not supported on 95&98 (or NT prior to SP2) 
  + */
   ap_status_t ap_writev(struct file_t *thefile, const struct iovec_t *vec, ap_ssize_t *iocnt)
   {
  -    int bytes;
  -    if ((bytes = writev(thefile->filedes, vec->iovec, *iocnt)) < 0) {
  -        *iocnt = bytes;
  -        return errno;
  -    12}
  -    else {
  -        *iocnt = bytes;
  -        return APR_SUCCESS;
  +    int i;
  +    DWORD bwrote = 0;
  +    int numvec = *iocnt;
  +    *iocnt = 0;
  +
  +    for (i = 0; i < numvec; i++) {
  +        if (!WriteFile(thefile->filehand,
  +                       vec->iov[i].iov_base, vec->iov[i].iov_len, &bwrote, NULL))
{
  +            return GetLastError(); /* TODO: Yes, I know this is broken... */
  +        }
  +        *iocnt += bwrote;
       }
  +    return APR_SUCCESS;
   }
  -*/
   
   ap_status_t ap_putc(ap_file_t *thefile, char ch)
   {
       DWORD bwrote;
   
  -    if (WriteFile(thefile->filehand, &ch, 1, &bwrote, NULL)) {
  +    if (!WriteFile(thefile->filehand, &ch, 1, &bwrote, NULL)) {
           return APR_EEXIST;
       }
       return APR_SUCCESS; 
  @@ -139,6 +144,53 @@
           thefile->eof_hit = TRUE;
           return APR_EOF;
       }
  +    return APR_SUCCESS; 
  +}
  +
  +ap_status_t ap_puts(ap_file_t *thefile, char *str)
  +{
  +    DWORD bwrote;
  +    int len;
  +
  +    len = strlen(str);
  +    str[len] = '\n';
  +    if (!WriteFile(thefile->filehand, str, len+1, &bwrote, NULL)) {
  +        str[len] = '\0';
  +        return APR_EEXIST;
  +    }
  +    str[len] = '\0';
  +
  +    return APR_SUCCESS; 
  +}
  +
  +ap_status_t ap_gets(ap_file_t *thefile, char *str, int len)
  +{
  +    DWORD bread;
  +    int i;
  +    if (!ReadFile(thefile->filehand, str, len, &bread, NULL)) {
  +        switch(GetLastError()) {
  +        case ERROR_HANDLE_EOF:
  +            return APR_EOF;
  +        default:
  +            return APR_EEXIST;
  +        }
  +    }
  +    if (bread == 0) {
  +        thefile->eof_hit = TRUE;
  +        return APR_EOF;
  +    }
  +    for (i=0; i<len; i++) {
  +        if (str[i] == '\n') {
  +            str[i] = '\0';
  +            return APR_SUCCESS;
  +        }
  +        str[i] = '\0';
  +    }
  +    return APR_SUCCESS; 
  +}
  +ap_status_t ap_flush(ap_file_t *thefile)
  +{
  +    FlushFileBuffers(thefile->filehand);
       return APR_SUCCESS; 
   }
   
  
  
  

Mime
View raw message