Check-in Number:
|
3394 | |
Date: |
2003-May-28 15:12:31 (local)
2003-May-28 13:12:31 (UTC) |
User: | ms |
Branch: | |
Comment: |
Replace nonportable scandir(3) with portable opendir(3) and readdir(3). |
Tickets: |
|
Inspections: |
|
Files: |
|
ossp-pkg/rc/rc_anal.c 1.16 -> 1.17
--- rc_anal.c 2003/05/27 14:51:38 1.16
+++ rc_anal.c 2003/05/28 13:12:31 1.17
@@ -181,36 +181,41 @@
************************************************/
rc_return_t analGloblocs(rc_anal_t **ppInst)
{
- struct dirent ***pppFiles = NULL;
+ DIR *pLocdir = NULL;
+ struct dirent *pDirent = NULL;
int nCount = 0; /* How many globbed files we find */
- int nIter = 0; /* Iterate over the number of globbed files */
+ int nIter = 0; /* Used to step through found files */
- assert(*ppInst); /* Verify sanity */
+ assert(*ppInst); /* Sanity check */
- /* Write the globbed filenames to our anal object */
- pppFiles = malloc(sizeof(struct dirent));
- nCount = scandir((*ppInst)->m_szLocs, pppFiles, analFileselect, alphasort);
+ /* First just learn how many globbed files we have */
+ if ((pLocdir = opendir((*ppInst)->m_szLocs)) == NULL)
+ return(RC_THROW(RC_ERR_DIR));
+ for (pDirent = readdir(pLocdir); pDirent; pDirent = readdir(pLocdir))
+ if (!strncmp(pDirent->d_name, "rc.", 3))
+ nCount++;
+ closedir(pLocdir);
- /* Check out the health of this directory listing */
- if (nCount == -1)
+ if (nCount == 0) /* Check out the health of this directory listing */
return(RC_THROW(RC_ERR_DIR));
else /* Allocate for the string array to hold directory entry names */
(*ppInst)->m_szRcs = malloc(sizeof((*((*ppInst)->m_szRcs))) * (nCount + 1));
/* Loop through file index setting rc file names according to dirent */
- for (nIter = 0; nIter < nCount; ++nIter) {
- (*ppInst)->m_szRcs[nIter] = strdup((*pppFiles)[nIter]->d_name +\
- strlen("rc.") * sizeof(char));
+ if ((pLocdir = opendir((*ppInst)->m_szLocs)) == NULL)
+ return(RC_THROW(RC_ERR_DIR));
+ for (pDirent = readdir(pLocdir); pDirent; pDirent = readdir(pLocdir)) {
+ if (!strncmp(pDirent->d_name, "rc.", 3)) {
+ (*ppInst)->m_szRcs[nIter] = strdup(pDirent->d_name + \
+ strlen("rc.") * sizeof(char));
+ nIter++;
+ }
}
+ closedir(pLocdir);
+
(*ppInst)->m_szRcs[nIter] = NULL; /* Terminate */
(*ppInst)->m_nRcs = nCount; /* Store how many globbed files there are */
- /* Cleanup our Dirent object */
- if (pppFiles) {
- free(pppFiles);
- pppFiles = NULL;
- }
-
return(RC_THROW(RC_OK));
}
|
|