--------------------- PatchSet 10510 Date: 2008/04/24 19:09:18 Author: serassio Branch: nt Tag: (none) Log: Relaced readdir.c from Apache project with dirent.c from MinGW Members: include/squid_mswin.h:1.1.2.10->1.1.2.11 lib/Makefile.am:1.7.8.5->1.7.8.6 lib/dirent.c:1.1->1.1.2.1 lib/win32lib.c:1.1.64.10->1.1.64.11 port/win32/Makefile.am:1.1.14.11->1.1.14.12 port/win32/include/Readdir.h:1.1.12.1->1.1.12.2(DEAD) port/win32/include/dirent.h:1.1->1.1.2.1 port/win32/libmiscutil/libmiscutil.dsp:1.1.38.1->1.1.38.2 port/win32/src/readdir.c:1.1.38.1->1.1.38.2(DEAD) Index: squid/include/squid_mswin.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/squid_mswin.h,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -r1.1.2.10 -r1.1.2.11 --- squid/include/squid_mswin.h 25 Apr 2007 09:31:40 -0000 1.1.2.10 +++ squid/include/squid_mswin.h 24 Apr 2008 19:09:18 -0000 1.1.2.11 @@ -1,5 +1,5 @@ /* - * $Id: squid_mswin.h,v 1.1.2.10 2007/04/25 09:31:40 serassio Exp $ + * $Id: squid_mswin.h,v 1.1.2.11 2008/04/24 19:09:18 serassio Exp $ * * AUTHOR: Andrey Shorin * AUTHOR: Guido Serassio @@ -66,7 +66,6 @@ #include "default_config_file.h" /* Some tricks for MS Compilers */ #define __STDC__ 1 -#pragma include_alias(, ) #define THREADLOCAL __declspec(thread) #elif defined(__GNUC__) /* gcc environment */ @@ -244,12 +243,10 @@ #include #if defined(_MSC_VER) /* Microsoft C Compiler ONLY */ #pragma warning (pop) -#include "readdir.h" -#else +#endif #include #include -#include -#endif +// #include typedef char * caddr_t; Index: squid/lib/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/Makefile.am,v retrieving revision 1.7.8.5 retrieving revision 1.7.8.6 diff -u -r1.7.8.5 -r1.7.8.6 --- squid/lib/Makefile.am 11 Nov 2007 13:43:43 -0000 1.7.8.5 +++ squid/lib/Makefile.am 24 Apr 2008 19:09:19 -0000 1.7.8.6 @@ -36,6 +36,7 @@ @LIBREGEX@ \ $(LIBSSPWIN32) EXTRA_libmiscutil_a_SOURCES = \ + dirent.c \ snprintf.c \ strsep.c \ win32lib.c --- /dev/null 2008-04-25 00:22:21.000000000 +0000 +++ squid/lib/dirent.c 2008-04-25 00:22:21.682206775 +0000 @@ -0,0 +1,360 @@ +/* + * $Id: dirent.c,v 1.1.2.1 2008/04/24 19:09:19 serassio Exp $ + * + * Implement dirent-style opendir(), readdir(), closedir(), rewinddir(), + * seekdir() and telldir on Windows - Based on mingw-runtime package sources. + * AUTHOR: Guido Serassio + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + * Original file info follow: + * + * dirent.c + * This file has no copyright assigned and is placed in the Public Domain. + * This file is a part of the mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within the package. + * + * Derived from DIRLIB.C by Matt J. Weinstein + * This note appears in the DIRLIB.H + * DIRLIB.H by M. J. Weinstein Released to public domain 1-Jan-89 + * + * Updated by Jeremy Bettis + * Significantly revised and rewinddir, seekdir and telldir added by Colin + * Peters + * + */ + +#include "util.h" + +/* The following code section is part of the native Windows Squid port */ +#if defined(_SQUID_MSWIN_) +#include +#include +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#include /* for GetFileAttributes */ + +#define SUFFIX ("*") +#define SLASH ("\\") + + +/* + * opendir + * + * Returns a pointer to a DIR structure appropriately filled in to begin + * searching a directory. + */ +DIR * +opendir (const CHAR *szPath) +{ + DIR *nd; + unsigned int rc; + CHAR szFullPath[MAX_PATH]; + + errno = 0; + + if (!szPath) + { + errno = EFAULT; + return (DIR *) 0; + } + + if (szPath[0] == '\0') + { + errno = ENOTDIR; + return (DIR *) 0; + } + + /* Attempt to determine if the given path really is a directory. */ + rc = GetFileAttributes (szPath); + if (rc == (unsigned int)-1) + { + /* call GetLastError for more error info */ + errno = ENOENT; + return (DIR *) 0; + } + if (!(rc & FILE_ATTRIBUTE_DIRECTORY)) + { + /* Error, entry exists but not a directory. */ + errno = ENOTDIR; + return (DIR *) 0; + } + + /* Make an absolute pathname. */ + _fullpath (szFullPath, szPath, MAX_PATH); + + /* Allocate enough space to store DIR structure and the complete + * directory path given. */ + nd = (DIR *) malloc (sizeof (DIR) + (strlen (szFullPath) + + strlen (SLASH) + + strlen (SUFFIX) + 1) + * sizeof (CHAR)); + + if (!nd) + { + /* Error, out of memory. */ + errno = ENOMEM; + return (DIR *) 0; + } + + /* Create the search expression. */ + strcpy (nd->dd_name, szFullPath); + + /* Add on a slash if the path does not end with one. */ + if (nd->dd_name[0] != '\0' + && strchr (nd->dd_name, '/') != nd->dd_name + + strlen (nd->dd_name) - 1 + && strchr (nd->dd_name, '\\') != nd->dd_name + + strlen (nd->dd_name) - 1) + { + strcat (nd->dd_name, SLASH); + } + + /* Add on the search pattern */ + strcat (nd->dd_name, SUFFIX); + + /* Initialize handle to -1 so that a premature closedir doesn't try + * to call _findclose on it. */ + nd->dd_handle = -1; + + /* Initialize the status. */ + nd->dd_stat = 0; + + /* Initialize the dirent structure. ino and reclen are invalid under + * Win32, and name simply points at the appropriate part of the + * findfirst_t structure. */ + nd->dd_dir.d_ino = 0; + nd->dd_dir.d_reclen = 0; + nd->dd_dir.d_namlen = 0; + memset (nd->dd_dir.d_name, 0, FILENAME_MAX); + + return nd; +} + + +/* + * readdir + * + * Return a pointer to a dirent structure filled with the information on the + * next entry in the directory. + */ +struct dirent * +readdir (DIR * dirp) +{ + errno = 0; + + /* Check for valid DIR struct. */ + if (!dirp) + { + errno = EFAULT; + return (struct dirent *) 0; + } + + if (dirp->dd_stat < 0) + { + /* We have already returned all files in the directory + * (or the structure has an invalid dd_stat). */ + return (struct dirent *) 0; + } + else if (dirp->dd_stat == 0) + { + /* We haven't started the search yet. */ + /* Start the search */ + dirp->dd_handle = _findfirst (dirp->dd_name, &(dirp->dd_dta)); + + if (dirp->dd_handle == -1) + { + /* Whoops! Seems there are no files in that + * directory. */ + dirp->dd_stat = -1; + } + else + { + dirp->dd_stat = 1; + } + } + else + { + /* Get the next search entry. */ + if (_findnext (dirp->dd_handle, &(dirp->dd_dta))) + { + /* We are off the end or otherwise error. + _findnext sets errno to ENOENT if no more file + Undo this. */ + DWORD winerr = GetLastError (); + if (winerr == ERROR_NO_MORE_FILES) + errno = 0; + _findclose (dirp->dd_handle); + dirp->dd_handle = -1; + dirp->dd_stat = -1; + } + else + { + /* Update the status to indicate the correct + * number. */ + dirp->dd_stat++; + } + } + + if (dirp->dd_stat > 0) + { + /* Successfully got an entry. Everything about the file is + * already appropriately filled in except the length of the + * file name. */ + dirp->dd_dir.d_namlen = strlen (dirp->dd_dta.name); + strcpy (dirp->dd_dir.d_name, dirp->dd_dta.name); + return &dirp->dd_dir; + } + + return (struct dirent *) 0; +} + + +/* + * closedir + * + * Frees up resources allocated by opendir. + */ +int +closedir (DIR * dirp) +{ + int rc; + + errno = 0; + rc = 0; + + if (!dirp) + { + errno = EFAULT; + return -1; + } + + if (dirp->dd_handle != -1) + { + rc = _findclose (dirp->dd_handle); + } + + /* Delete the dir structure. */ + free (dirp); + + return rc; +} + +/* + * rewinddir + * + * Return to the beginning of the directory "stream". We simply call findclose + * and then reset things like an opendir. + */ +void +rewinddir (DIR * dirp) +{ + errno = 0; + + if (!dirp) + { + errno = EFAULT; + return; + } + + if (dirp->dd_handle != -1) + { + _findclose (dirp->dd_handle); + } + + dirp->dd_handle = -1; + dirp->dd_stat = 0; +} + +/* + * telldir + * + * Returns the "position" in the "directory stream" which can be used with + * seekdir to go back to an old entry. We simply return the value in stat. + */ +long +telldir (DIR * dirp) +{ + errno = 0; + + if (!dirp) + { + errno = EFAULT; + return -1; + } + return dirp->dd_stat; +} + +/* + * seekdir + * + * Seek to an entry previously returned by telldir. We rewind the directory + * and call readdir repeatedly until either dd_stat is the position number + * or -1 (off the end). This is not perfect, in that the directory may + * have changed while we weren't looking. But that is probably the case with + * any such system. + */ +void +seekdir (DIR * dirp, long lPos) +{ + errno = 0; + + if (!dirp) + { + errno = EFAULT; + return; + } + + if (lPos < -1) + { + /* Seeking to an invalid position. */ + errno = EINVAL; + return; + } + else if (lPos == -1) + { + /* Seek past end. */ + if (dirp->dd_handle != -1) + { + _findclose (dirp->dd_handle); + } + dirp->dd_handle = -1; + dirp->dd_stat = -1; + } + else + { + /* Rewind and read forward to the appropriate index. */ + rewinddir (dirp); + + while ((dirp->dd_stat < lPos) && readdir (dirp)) + ; + } +} +#endif /* _SQUID_MSWIN_ */ Index: squid/lib/win32lib.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/win32lib.c,v retrieving revision 1.1.64.10 retrieving revision 1.1.64.11 diff -u -r1.1.64.10 -r1.1.64.11 --- squid/lib/win32lib.c 22 Apr 2008 15:47:56 -0000 1.1.64.10 +++ squid/lib/win32lib.c 24 Apr 2008 19:09:19 -0000 1.1.64.11 @@ -1,6 +1,6 @@ /* - * $Id: win32lib.c,v 1.1.64.10 2008/04/22 15:47:56 serassio Exp $ + * $Id: win32lib.c,v 1.1.64.11 2008/04/24 19:09:19 serassio Exp $ * * Windows support * AUTHOR: Guido Serassio @@ -36,8 +36,7 @@ #include "util.h" -/* The following code section is part of an EXPERIMENTAL native */ -/* Windows NT/2000 Squid port - Compiles only on MS Visual C++ */ +/* The following code section is part of the native Windows Squid port */ #if defined(_SQUID_MSWIN_) #undef strerror @@ -791,4 +790,4 @@ else errno = EINVAL; } -#endif +#endif /* _SQUID_MSWIN_ */ Index: squid/port/win32/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid/port/win32/Attic/Makefile.am,v retrieving revision 1.1.14.11 retrieving revision 1.1.14.12 diff -u -r1.1.14.11 -r1.1.14.12 --- squid/port/win32/Makefile.am 21 Sep 2007 18:54:57 -0000 1.1.14.11 +++ squid/port/win32/Makefile.am 24 Apr 2008 19:09:19 -0000 1.1.14.12 @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in # -# $Id: Makefile.am,v 1.1.14.11 2007/09/21 18:54:57 serassio Exp $ +# $Id: Makefile.am,v 1.1.14.12 2008/04/24 19:09:19 serassio Exp $ # EXTRA_DIST = \ @@ -32,7 +32,7 @@ include/cdefs.h \ include/crypt.h \ include/getopt.h \ - include/Readdir.h \ + include/dirent.h \ ip_user_check/ip_user_check.dsp \ LDAP_auth/LDAP_auth.dsp \ LDAP_group/LDAP_group.dsp \ @@ -67,6 +67,5 @@ pinger/pinger.dsp \ squidclient/squidclient.dsp \ src/encrypt.c \ - src/readdir.c \ unlinkd/unlinkd.dsp \ win32_check_group/win32_check_group.dsp --- squid/port/win32/include/Readdir.h 2008-04-25 00:22:21.717194066 +0000 +++ /dev/null 2008-04-25 00:22:21.000000000 +0000 @@ -1,33 +0,0 @@ -/* - * Structures and types used to implement opendir/readdir/closedir - * on Windows 95/NT. -*/ - -#include -#include -#include - -#ifdef _MSC_VER /* Microsoft C Compiler ONLY */ -/* struct dirent - same as Unix */ -struct dirent { - ino_t d_ino; /* inode (always 1 in WIN32) */ - off_t d_off; /* offset to this dirent */ - unsigned short d_reclen; /* length of d_name */ - char d_name[_MAX_FNAME+1]; /* filename (null terminated) */ -}; - -/* typedef DIR - not the same as Unix */ -typedef struct { - long handle; /* _findfirst/_findnext handle */ - short offset; /* offset into directory */ - short finished; /* 1 if there are not more files */ - struct _finddata_t fileinfo; /* from _findfirst/_findnext */ - char *dir; /* the dir we are reading */ - struct dirent dent; /* the dirent to return */ -} DIR; - -/* Function prototypes */ -DIR * opendir(const char *); -struct dirent * readdir(DIR *); -int closedir(DIR *); -#endif --- /dev/null 2008-04-25 00:22:21.000000000 +0000 +++ squid/port/win32/include/dirent.h 2008-04-25 00:22:21.722713700 +0000 @@ -0,0 +1,105 @@ +/* + * $Id: dirent.h,v 1.1.2.1 2008/04/24 19:09:19 serassio Exp $ + * + * Implement dirent-style opendir(), readdir(), closedir(), rewinddir(), + * seekdir() and telldir on Windows - Based on mingw-runtime package sources. + * AUTHOR: Guido Serassio + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + * Original file info follow: + * + * DIRENT.H (formerly DIRLIB.H) + * This file has no copyright assigned and is placed in the Public Domain. + * This file is a part of the mingw-runtime package. + * No warranty is given; refer to the file DISCLAIMER within the package. + * + */ +#ifndef _DIRENT_H_ +#define _DIRENT_H_ + +/* All the headers include this file. */ +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct dirent +{ + long d_ino; /* Always zero. */ + unsigned short d_reclen; /* Always zero. */ + unsigned short d_namlen; /* Length of name in d_name. */ + char d_name[FILENAME_MAX]; /* File name. */ +}; + +/* + * This is an internal data structure. Good programmers will not use it + * except as an argument to one of the functions below. + * dd_stat field is now int (was short in older versions). + */ +typedef struct +{ + /* disk transfer area for this dir */ + struct _finddata_t dd_dta; + + /* dirent struct to return from dir (NOTE: this makes this thread + * safe as long as only one thread uses a particular DIR struct at + * a time) */ + struct dirent dd_dir; + + /* _findnext handle */ + long dd_handle; + + /* + * Status of search: + * 0 = not started yet (next entry to read is first entry) + * -1 = off the end + * positive = 0 based index of next entry + */ + int dd_stat; + + /* given path for dir with search pattern (struct is extended) */ + char dd_name[1]; +} DIR; + +DIR * __cdecl opendir (const char *); +struct dirent * __cdecl readdir (DIR *); +int __cdecl closedir (DIR *); +void __cdecl rewinddir (DIR *); +long __cdecl telldir (DIR *); +void __cdecl seekdir (DIR *, long); + + + +#ifdef __cplusplus +} +#endif + + +#endif /* Not _DIRENT_H_ */ Index: squid/port/win32/libmiscutil/libmiscutil.dsp =================================================================== RCS file: /cvsroot/squid-sf//squid/port/win32/libmiscutil/Attic/libmiscutil.dsp,v retrieving revision 1.1.38.1 retrieving revision 1.1.38.2 diff -u -r1.1.38.1 -r1.1.38.2 --- squid/port/win32/libmiscutil/libmiscutil.dsp 16 May 2006 21:05:58 -0000 1.1.38.1 +++ squid/port/win32/libmiscutil/libmiscutil.dsp 24 Apr 2008 19:09:19 -0000 1.1.38.2 @@ -93,6 +93,10 @@ # End Source File # Begin Source File +SOURCE=..\..\..\lib\dirent.c +# End Source File +# Begin Source File + SOURCE=..\..\..\lib\drand48.c # End Source File # Begin Source File @@ -133,10 +137,6 @@ # End Source File # Begin Source File -SOURCE=..\src\readdir.c -# End Source File -# Begin Source File - SOURCE=..\..\..\lib\rfc1035.c # End Source File # Begin Source File @@ -189,6 +189,10 @@ # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File +SOURCE=..\include\dirent.h +# End Source File +# Begin Source File + SOURCE=..\..\..\include\heap.h # End Source File # Begin Source File --- squid/port/win32/src/readdir.c 2008-04-25 00:22:21.740069900 +0000 +++ /dev/null 2008-04-25 00:22:21.000000000 +0000 @@ -1,80 +0,0 @@ -#include "config.h" -#include -#include -#include -#define strdup _strdup - -/********************************************************************** - * Implement dirent-style opendir/readdir/closedir on Window 95/NT - * - * Functions defined are opendir(), readdir() and closedir() with the - * same prototypes as the normal dirent.h implementation. - * - * Does not implement telldir(), seekdir(), rewinddir() or scandir(). - * The dirent struct is compatible with Unix, except that d_ino is - * always 1 and d_off is made up as we go along. - * - * The DIR typedef is not compatible with Unix. - **********************************************************************/ - -DIR * opendir(const char *dir) -{ - DIR *dp; - char *filespec; - long handle; - int index; - - filespec = malloc(strlen(dir) + 2 + 1); - strcpy(filespec, dir); - index = strlen(filespec) - 1; - if (index >= 0 && (filespec[index] == '/' || filespec[index] == '\\')) - filespec[index] = '\0'; - strcat(filespec, "/*"); - - dp = (DIR *)malloc(sizeof(DIR)); - dp->offset = 0; - dp->finished = 0; - dp->dir = strdup(dir); - - if ((handle = _findfirst(filespec, &(dp->fileinfo))) < 0) { - if (errno == ENOENT) - dp->finished = 1; - else - return NULL; - } - - dp->handle = handle; - free(filespec); - - return dp; -} - -struct dirent * readdir(DIR *dp) -{ - if (!dp || dp->finished) return NULL; - - if (dp->offset != 0) { - if (_findnext(dp->handle, &(dp->fileinfo)) < 0) { - dp->finished = 1; - return NULL; - } - } - dp->offset++; - - strncpy(dp->dent.d_name, dp->fileinfo.name, _MAX_FNAME); - dp->dent.d_ino = 1; - dp->dent.d_reclen = strlen(dp->dent.d_name); - dp->dent.d_off = dp->offset; - - return &(dp->dent); -} - -int closedir(DIR *dp) -{ - if (!dp) return 0; - _findclose(dp->handle); - if (dp->dir) free(dp->dir); - if (dp) free(dp); - - return 0; -}