int findNextFile( findFileHandleType *findFileHandle) { if (findFileHandle == 0) { return ERROR_NOT_FOUND; } while(findFileHandle->currentFile < &rootDir->entry[rootDir->maxEntries]) { findFileHandle->currentFile++; if (findFileHandle->currentFile->name[0] != 0) { if (findFileHandle->filespec[0] != 0 && wildcard_search(findFileHandle->filespec, findFileHandle->currentFile->name ) != 1) { continue; } return NO_ERROR; } } return ERROR_NOT_FOUND; }
int findFiles( char *filespec, findFileHandleType **findFileHandle ) { int i; directoryEntryType *currentFile; char strcmpbuffer[MAX_FILENAME_LEN+1]; char tempbuffer[24]; static findFileHandleType fileHandle; if (rootDir == 0) { return ERROR_INIT; } currentFile = &rootDir->entry[0]; for ( i = 0; i < rootDir->maxEntries; ++i ) { if (currentFile->name[0] != 0 ) { // nulls aren't necessariy stored in the directory if the filename has max length // so make a copy that we can use with the wildcard search function strncpy(strcmpbuffer, currentFile->name, MAX_FILENAME_LEN); strcmpbuffer[MAX_FILENAME_LEN] = 0; // now match against the filespec if (filespec[0] != 0 && wildcard_search(filespec, strcmpbuffer) != 1) { currentFile++; continue; } // its a match so copy it into another buffer so the caller doesn't get direct // access to the real directory structure fileHandle.currentFile = currentFile; strncpy(fileHandle.filespec, filespec, MAX_FILENAME_LEN); *findFileHandle = &fileHandle; return NO_ERROR; } // if currentFile++; } // for return ERROR_NOT_FOUND; }
int sal_config_set(char *name, char *value) { sc_t *sc, *psc; char *newval; char *wildcard = NULL; char *sc_wildcard; int length; sc_hash_t hash; if (name == NULL || *name == '\0') { return -1; } SC_HASH(name, hash); sc = sal_config_list[hash]; psc = NULL; while (sc != NULL) { if (sal_strcmp(sc->sc_name, name) == 0) { break; } psc = sc; sc = sc->sc_next; } if (sc != NULL) { /* found */ if (value == NULL) { /* delete */ if (sal_config_list[hash] == sc) { sal_config_list[hash] = sc->sc_next; } else { if (psc !=NULL) { psc->sc_next = sc->sc_next; } } FREE_SC(sc); return 0; } else { /* replace */ newval = sal_alloc(strlen(value) + 1, "config value"); if (newval == NULL) { return -1; } sal_strncpy(newval, value, strlen(value)); newval[strlen(value)] = '\0'; sal_free(sc->sc_value); sc->sc_value = newval; return 0; } } /* not found, delete */ if (value == NULL) { int i; wildcard = wildcard_search(name, wildcard, &length); if (wildcard != NULL) { sc_wildcard = sal_alloc((length + 1), "sc_wildcard"); *(sc_wildcard+length) = 0; for (i = 0; i < MAX_CONFIG_HASH_COUNT; i++) { sc = sal_config_list[i]; psc = NULL; while (sc != NULL){ sc_wildcard = sal_strncpy(sc_wildcard, sc->sc_name, length); sc_wildcard[length] = '\0'; if (sal_strcmp(sc_wildcard, wildcard) == 0) { if (sal_config_list[i] == sc) { sal_config_list[i] = sc->sc_next; FREE_SC(sc); sc = sal_config_list[i]; psc = NULL; } else { if (psc !=NULL) { psc->sc_next = sc->sc_next; } FREE_SC(sc); if (psc !=NULL) { sc = psc->sc_next; } } } else { psc = sc; sc = sc->sc_next; } } } sal_free(wildcard); sal_free(sc_wildcard); return 0; } else { return -1; } } /* not found, add */ if ((sc = sal_alloc(sizeof(sc_t), "config set")) == NULL) { return -1; } sc->sc_name = sal_alloc(strlen(name) + 1, "config name"); sc->sc_value = sal_alloc(strlen(value) + 1, "config value"); if (sc->sc_name == NULL || sc->sc_value == NULL) { FREE_SC(sc); return -1; } sal_strncpy(sc->sc_name, name, strlen(name)); sc->sc_name[strlen(name)] = '\0'; sal_strncpy(sc->sc_value, value, strlen(value)); sc->sc_value[strlen(value)] = '\0'; sc->sc_hash = hash; sc->sc_next = sal_config_list[hash]; sal_config_list[hash] = sc; return 0; }