cvs commit: apache-2.0/src/lib/apr/time/win32 time.c
stoddard00/01/31 16:08:26 Modified:src/lib/apr/time/win32 time.c Log: Make some of the APR to Windows time conversion routines available to other APR functions. Revision ChangesPath 1.7 +3 -5 apache-2.0/src/lib/apr/time/win32/time.c Index: time.c === RCS file: /home/cvs/apache-2.0/src/lib/apr/time/win32/time.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- time.c2000/01/17 23:17:37 1.6 +++ time.c2000/02/01 00:08:25 1.7 @@ -67,7 +67,7 @@ */ #define AP_DELTA_EPOCH_IN_USEC 116444736; -static void FileTimeToAprTime(ap_time_t *result, FILETIME *input) +void FileTimeToAprTime(ap_time_t *result, FILETIME *input) { /* Convert FILETIME one 64 bit number so we can work with it. */ *result = input-dwHighDateTime; @@ -75,13 +75,11 @@ *result |= input-dwLowDateTime; *result /= 10;/* Convert from 100 nano-sec periods to micro-seconds. */ *result -= AP_DELTA_EPOCH_IN_USEC; /* Convert from Windows epoch to Unix epoch */ -//printf(FileTimeToAprTime: aprtime - %I64d\n, *result); return; } -static void AprTimeToFileTime(LPFILETIME pft, ap_time_t t) +void AprTimeToFileTime(LPFILETIME pft, ap_time_t t) { LONGLONG ll; -//printf(AprTimeToFileTime: aprtime - %I64d\n, t); t += AP_DELTA_EPOCH_IN_USEC; ll = t * 10; pft-dwLowDateTime = (DWORD)ll; @@ -89,7 +87,7 @@ return; } -static void SystemTimeToAprExpTime(ap_exploded_time_t *xt, SYSTEMTIME *tm) +void SystemTimeToAprExpTime(ap_exploded_time_t *xt, SYSTEMTIME *tm) { xt-tm_usec = tm-wMilliseconds * 1000; xt-tm_sec = tm-wSecond;
cvs commit: apache-2.0/src/lib/apr/network_io/win32 sockopt.c
stoddard00/01/31 16:10:13 Modified:src/lib/apr/network_io/win32 sockopt.c Log: Add code to set the socket timeout. Correct some error return codes. Revision ChangesPath 1.6 +12 -4 apache-2.0/src/lib/apr/network_io/win32/sockopt.c Index: sockopt.c === RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/win32/sockopt.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- sockopt.c 1999/10/25 23:55:23 1.5 +++ sockopt.c 2000/02/01 00:10:12 1.6 @@ -91,19 +91,27 @@ else one = 0; +if (opt APR_SO_TIMEOUT) { +int timeout = on * 1000; /* Windows needs timeout in mSeconds */ +sock-timeout = timeout; +if (setsockopt(sock-sock, SOL_SOCKET, SO_RCVTIMEO, (char*) timeout, + sizeof(timeout)) == SOCKET_ERROR) { +return WSAGetLastError(); +} +} if (opt APR_SO_KEEPALIVE) { if (setsockopt(sock-sock, SOL_SOCKET, SO_KEEPALIVE, (void *)one, sizeof(int)) == -1) { -return APR_EEXIST; +return WSAGetLastError(); } } if (opt APR_SO_DEBUG) { if (setsockopt(sock-sock, SOL_SOCKET, SO_DEBUG, (void *)one, sizeof(int)) == -1) { -return APR_EEXIST; +return WSAGetLastError(); } } if (opt APR_SO_REUSEADDR) { if (setsockopt(sock-sock, SOL_SOCKET, SO_REUSEADDR, (void *)one, sizeof(int)) == -1) { -return APR_EEXIST; +return WSAGetLastError(); } } if (opt APR_SO_NONBLOCK) { @@ -124,7 +132,7 @@ } } return APR_SUCCESS; -} +} ap_status_t ap_gethostname(char *buf, int len, ap_context_t *cont) {
cvs commit: apache-2.0/src/lib/apr/file_io/win32 open.c
stoddard00/01/31 16:13:37 Modified:src/lib/apr/file_io/win32 open.c Log: Open files for sequential access. This is a file system cache optimization for when files are accessed sequentially (a common case with Apache). This does not prevent a file from being accessed randomly. Revision ChangesPath 1.16 +1 -1 apache-2.0/src/lib/apr/file_io/win32/open.c Index: open.c === RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/open.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- open.c1999/12/17 15:14:06 1.15 +++ open.c2000/02/01 00:13:28 1.16 @@ -131,7 +131,7 @@ } (*dafile)-filehand = CreateFile(fname, oflags, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, - NULL, createflags, FILE_ATTRIBUTE_NORMAL, 0); + NULL, createflags, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0); if ((*dafile)-filehand == INVALID_HANDLE_VALUE) { theerror = GetLastError();
cvs commit: apache-2.0/src/lib/apr/file_io/win32 filestat.c
stoddard00/01/31 16:15:13 Modified:src/lib/apr/file_io/win32 filestat.c Log: Reimplement ap_stat using native Windows calls. This is good for a 10% performance boost serving a 500 byte static file. Revision ChangesPath 1.6 +66 -7 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- filestat.c2000/01/17 23:34:38 1.5 +++ filestat.c2000/02/01 00:15:11 1.6 @@ -58,15 +58,12 @@ #include apr_file_io.h #include apr_general.h #include apr_errno.h +#include apr_time.h #include sys/stat.h -#define S_ISLNK(m) (0) -#ifndef S_ISREG -#define S_ISREG(m) (((m)(S_IFMT)) == (S_IFREG)) -#endif -#ifndef S_ISDIR -#define S_ISDIR(m) (((m) S_IFDIR) == S_IFDIR) -#endif +#define S_ISLNK(m) (0) +#define S_ISREG(m) (((m) (S_IFMT)) == S_IFREG) +#define S_ISDIR(m) (((m) (S_IFDIR)) == S_IFDIR) static ap_filetype_e filetype_from_mode(int mode) { @@ -81,6 +78,27 @@ return type; } +BOOLEAN is_exe(const char* fname, ap_context_t *cont) { +const char* exename; +const char* ext; +exename = strrchr(fname, '/'); +if (!exename) { +exename = strrchr(fname, '\\'); +} +if (!exename) { +exename = fname; +} +else { +exename++; +} +ext = strrchr(exename, '.'); + +if (ext (!strcasecmp(ext,.exe) || !strcasecmp(ext,.com) || +!strcasecmp(ext,.bat) || !strcasecmp(ext,.cmd))) { +return TRUE; +} +return FALSE; +} ap_status_t ap_getfileinfo(ap_finfo_t *finfo, struct file_t *thefile) { @@ -110,6 +128,46 @@ } ap_status_t ap_stat(ap_finfo_t *finfo, const char *fname, ap_context_t *cont) { +WIN32_FILE_ATTRIBUTE_DATA FileInformation; + +memset(finfo,'\0', sizeof(*finfo)); + +if (!GetFileAttributesEx(fname, GetFileExInfoStandard, FileInformation)) { +return GetLastError(); +} +/* Filetype - Directory or file? */ +if (FileInformation.dwFileAttributes FILE_ATTRIBUTE_DIRECTORY) { +finfo-protection |= S_IFDIR; +finfo-filetype = APR_DIR; +} +else { +finfo-protection |= S_IFREG; +finfo-filetype = APR_REG; +} +/* Read, write execute for owner */ +if (FileInformation.dwFileAttributes FILE_ATTRIBUTE_READONLY) { +finfo-protection |= S_IREAD; +} +else { +finfo-protection |= S_IREAD; +finfo-protection |= S_IWRITE; +} +/* Is this an executable? Guess based on the file extension. */ +if (is_exe(fname, cont)) { +finfo-protection |= S_IEXEC; +} +/* File times */ +FileTimeToAprTime(finfo-atime, FileInformation.ftLastAccessTime); +FileTimeToAprTime(finfo-ctime, FileInformation.ftCreationTime); +FileTimeToAprTime(finfo-mtime, FileInformation.ftLastWriteTime); + +/* File size + * Note: This cannot handle files greater than can be held by an int */ +finfo-size = FileInformation.nFileSizeLow; + +return APR_SUCCESS; +#if 0 +/* ap_stat implemented using stat() */ struct stat info; int rv = stat(fname, info); if (rv == 0) { @@ -127,5 +185,6 @@ else { return errno; } +#endif }
cvs commit: apache-2.0/src/lib/apr/file_io/win32 readwrite.c
stoddard00/01/31 16:40:45 Modified:src/lib/apr/file_io/win32 readwrite.c Log: Return correct error status. Revision ChangesPath 1.10 +10 -10apache-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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- readwrite.c 1999/12/09 21:00:10 1.9 +++ readwrite.c 2000/02/01 00:40:40 1.10 @@ -86,7 +86,7 @@ } *nbytes = -1; -return APR_EEXIST; +return lasterror; } ap_status_t ap_write(struct file_t *thefile, void *buf, ap_ssize_t *nbytes) @@ -112,7 +112,7 @@ return APR_SUCCESS; } (*nbytes) = -1; -return APR_EEXIST; +return GetLastError(); } /* * Too bad WriteFileGather() is not supported on 9598 (or NT prior to SP2) @@ -127,7 +127,7 @@ 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... */ +return GetLastError(); } *iocnt += bwrote; } @@ -139,7 +139,7 @@ DWORD bwrote; if (!WriteFile(thefile-filehand, ch, 1, bwrote, NULL)) { -return APR_EEXIST; +return GetLastError(); } return APR_SUCCESS; } @@ -162,17 +162,17 @@ /* SetFilePointer is only valid for a file device ...*/ if (GetFileType(thefile-filehand) != FILE_TYPE_DISK) { -return !APR_SUCCESS; /* is there no generic failure code? */ +return GetLastError(); } /* that's buffered... */ if (!thefile-buffered) { -return !APR_SUCCESS; /* is there no generic failure code? */ +return GetLastError(); } /* and the file pointer is not pointing to the start of the file. */ if (GetFilePointer(thefile-filehand)) { if (SetFilePointer(thefile-filehand, -1, NULL, FILE_CURRENT) == 0x) { -return !APR_SUCCESS; +return GetLastError(); } } @@ -184,7 +184,7 @@ { DWORD bread; if (!ReadFile(thefile-filehand, ch, 1, bread, NULL)) { -return APR_EEXIST; +return GetLastError(); } if (bread == 0) { thefile-eof_hit = TRUE; @@ -202,7 +202,7 @@ str[len] = '\n'; if (!WriteFile(thefile-filehand, str, len+1, bwrote, NULL)) { str[len] = '\0'; -return APR_EEXIST; +return GetLastError(); } str[len] = '\0'; @@ -218,7 +218,7 @@ case ERROR_HANDLE_EOF: return APR_EOF; default: -return APR_EEXIST; +return GetLastError(); } } if (bread == 0) {
cvs commit: apache-2.0/src/lib/apr/file_io/win32 dir.c
stoddard00/01/31 16:44:36 Modified:src/lib/apr/file_io/win32 dir.c Log: CloseHandle() returns 0 on failure Revision ChangesPath 1.10 +3 -5 apache-2.0/src/lib/apr/file_io/win32/dir.c Index: dir.c === RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/dir.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- dir.c 2000/01/11 23:23:49 1.9 +++ dir.c 2000/02/01 00:44:34 1.10 @@ -76,12 +76,10 @@ ap_status_t dir_cleanup(void *thedir) { struct dir_t *dir = thedir; -if (CloseHandle(dir-dirhand) == 0) { -return APR_SUCCESS; +if (!CloseHandle(dir-dirhand)) { +return GetLastError(); } -else { -return errno; -} +return APR_SUCCESS; } ap_status_t ap_opendir(struct dir_t **new, const char *dirname, ap_context_t *cont)
cvs commit: apache-2.0/src/lib/apr/file_io/win32 dir.c
stoddard00/01/31 16:51:46 Modified:src/lib/apr/file_io/win32 dir.c Log: Return correct error status Revision ChangesPath 1.11 +14 -16apache-2.0/src/lib/apr/file_io/win32/dir.c Index: dir.c === RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/dir.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- dir.c 2000/02/01 00:44:34 1.10 +++ dir.c 2000/02/01 00:51:45 1.11 @@ -103,11 +103,11 @@ ap_status_t ap_closedir(struct dir_t *thedir) { -if (FindClose(thedir-dirhand)) { -ap_kill_cleanup(thedir-cntxt, thedir, dir_cleanup); -return APR_SUCCESS; +if (!FindClose(thedir-dirhand)) { +return GetLastError(); } -return APR_EEXIST; +ap_kill_cleanup(thedir-cntxt, thedir, dir_cleanup); +return APR_SUCCESS; } ap_status_t ap_readdir(struct dir_t *thedir) @@ -116,14 +116,14 @@ thedir-entry = ap_palloc(thedir-cntxt, sizeof(WIN32_FIND_DATA)); thedir-dirhand = FindFirstFile(thedir-dirname, thedir-entry); if (thedir-dirhand == INVALID_HANDLE_VALUE) { -return APR_EEXIST; +return GetLastError(); } return APR_SUCCESS; } -if (FindNextFile(thedir-dirhand, thedir-entry)) { -return APR_SUCCESS; +if (!FindNextFile(thedir-dirhand, thedir-entry)) { +return GetLastError(); } -return APR_EEXIST; +return APR_SUCCESS; } ap_status_t ap_rewinddir(struct dir_t *thedir) @@ -146,21 +146,19 @@ ap_status_t ap_make_dir(const char *path, ap_fileperms_t perm, ap_context_t *cont) { -if (CreateDirectory(path, NULL)) { -return APR_SUCCESS; +if (!CreateDirectory(path, NULL)) { +return GetLastError(); } -return APR_EEXIST; +return APR_SUCCESS; } ap_status_t ap_remove_dir(const char *path, ap_context_t *cont) { -DWORD huh; char *temp = canonical_filename(cont, path); -if (RemoveDirectory(temp)) { -return APR_SUCCESS; +if (!RemoveDirectory(temp)) { +return GetLastError(); } -huh = GetLastError(); -return APR_EEXIST; +return APR_SUCCESS; } ap_status_t ap_dir_entry_size(ap_ssize_t *size, struct dir_t *thedir)
cvs commit: apache-2.0/src/lib/apr/file_io/win32 seek.c
stoddard00/01/31 16:57:40 Modified:src/lib/apr/file_io/win32 seek.c Log: Fix indenting Revision ChangesPath 1.2 +16 -16apache-2.0/src/lib/apr/file_io/win32/seek.c Index: seek.c === RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/seek.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- seek.c1999/08/17 15:59:37 1.1 +++ seek.c2000/02/01 00:57:34 1.2 @@ -61,24 +61,24 @@ ap_status_t ap_seek(struct file_t *thefile, ap_seek_where_t where, ap_off_t *offset) { DWORD howmove; - DWORD rv; +DWORD rv; - switch(where) { - case APR_SET: { - howmove = FILE_BEGIN; - break; - } - case APR_CUR: { - howmove = FILE_CURRENT; - break; - } - case APR_END: { - howmove = FILE_END; - break; - } - } +switch(where) { +case APR_SET: { +howmove = FILE_BEGIN; +break; +} +case APR_CUR: { +howmove = FILE_CURRENT; +break; +} +case APR_END: { +howmove = FILE_END; +break; +} +} -rv = SetFilePointer(thefile-filehand, *offset,NULL, howmove); +rv = SetFilePointer(thefile-filehand, *offset, NULL, howmove); if (rv == -1) { *offset = -1; return APR_EEXIST;