--------------------- PatchSet 10511 Date: 2008/04/24 19:20:58 Author: serassio Branch: nt Tag: (none) Log: Ran indent Members: lib/dirent.c:1.1.2.1->1.1.2.2 port/win32/include/dirent.h:1.1.2.1->1.1.2.2 Index: squid/lib/dirent.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/Attic/dirent.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/lib/dirent.c 24 Apr 2008 19:09:19 -0000 1.1.2.1 +++ squid/lib/dirent.c 24 Apr 2008 19:20:58 -0000 1.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: dirent.c,v 1.1.2.1 2008/04/24 19:09:19 serassio Exp $ + * $Id: dirent.c,v 1.1.2.2 2008/04/24 19:20:58 serassio Exp $ * * Implement dirent-style opendir(), readdir(), closedir(), rewinddir(), * seekdir() and telldir on Windows - Based on mingw-runtime package sources. @@ -45,7 +45,7 @@ * Updated by Jeremy Bettis * Significantly revised and rewinddir, seekdir and telldir added by Colin * Peters - * + * */ #include "util.h" @@ -59,7 +59,7 @@ #include #define WIN32_LEAN_AND_MEAN -#include /* for GetFileAttributes */ +#include /* for GetFileAttributes */ #define SUFFIX ("*") #define SLASH ("\\") @@ -71,91 +71,80 @@ * Returns a pointer to a DIR structure appropriately filled in to begin * searching a directory. */ -DIR * -opendir (const CHAR *szPath) +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); + 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; + return nd; } @@ -166,74 +155,59 @@ * next entry in the directory. */ struct dirent * -readdir (DIR * dirp) +readdir(DIR * dirp) { - errno = 0; + 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; + /* 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 - { - 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++; + } 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; + 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; + return (struct dirent *) 0; } @@ -243,28 +217,24 @@ * Frees up resources allocated by opendir. */ int -closedir (DIR * dirp) +closedir(DIR * dirp) { - int rc; + int rc; - errno = 0; - rc = 0; + errno = 0; + rc = 0; - if (!dirp) - { - errno = EFAULT; - return -1; + if (!dirp) { + errno = EFAULT; + return -1; } - - if (dirp->dd_handle != -1) - { - rc = _findclose (dirp->dd_handle); + if (dirp->dd_handle != -1) { + rc = _findclose(dirp->dd_handle); } + /* Delete the dir structure. */ + free(dirp); - /* Delete the dir structure. */ - free (dirp); - - return rc; + return rc; } /* @@ -274,23 +244,19 @@ * and then reset things like an opendir. */ void -rewinddir (DIR * dirp) +rewinddir(DIR * dirp) { - errno = 0; + errno = 0; - if (!dirp) - { - errno = EFAULT; - return; + if (!dirp) { + errno = EFAULT; + return; } - - if (dirp->dd_handle != -1) - { - _findclose (dirp->dd_handle); + if (dirp->dd_handle != -1) { + _findclose(dirp->dd_handle); } - - dirp->dd_handle = -1; - dirp->dd_stat = 0; + dirp->dd_handle = -1; + dirp->dd_stat = 0; } /* @@ -300,16 +266,15 @@ * seekdir to go back to an old entry. We simply return the value in stat. */ long -telldir (DIR * dirp) +telldir(DIR * dirp) { - errno = 0; + errno = 0; - if (!dirp) - { - errno = EFAULT; - return -1; + if (!dirp) { + errno = EFAULT; + return -1; } - return dirp->dd_stat; + return dirp->dd_stat; } /* @@ -322,39 +287,30 @@ * any such system. */ void -seekdir (DIR * dirp, long lPos) +seekdir(DIR * dirp, long lPos) { - errno = 0; + 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); + 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); + 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)) - ; + while ((dirp->dd_stat < lPos) && readdir(dirp)); } } #endif /* _SQUID_MSWIN_ */ Index: squid/port/win32/include/dirent.h =================================================================== RCS file: /cvsroot/squid-sf//squid/port/win32/include/Attic/dirent.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/port/win32/include/dirent.h 24 Apr 2008 19:09:19 -0000 1.1.2.1 +++ squid/port/win32/include/dirent.h 24 Apr 2008 19:20:59 -0000 1.1.2.2 @@ -1,5 +1,5 @@ /* - * $Id: dirent.h,v 1.1.2.1 2008/04/24 19:09:19 serassio Exp $ + * $Id: dirent.h,v 1.1.2.2 2008/04/24 19:20:59 serassio Exp $ * * Implement dirent-style opendir(), readdir(), closedir(), rewinddir(), * seekdir() and telldir on Windows - Based on mingw-runtime package sources. @@ -50,56 +50,53 @@ 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. */ -}; + 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 -{ + typedef struct { /* disk transfer area for this dir */ - struct _finddata_t dd_dta; + 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; + struct dirent dd_dir; /* _findnext handle */ - long dd_handle; + long dd_handle; /* - * Status of search: + * 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; + int dd_stat; /* given path for dir with search pattern (struct is extended) */ - char dd_name[1]; -} DIR; + 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); + 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_ */ +#endif +#endif /* Not _DIRENT_H_ */