static void _fileCreateDirectory(const char *fileName, unsigned short volRefNum) { #ifndef USE_FILE_API int i = 0; for (i = 0; i < stringLen(fileName); i++) { if (fileName[i] == '/') { char *tempPath = stringDup(fileName); if (tempPath) { FileRef fileRef; tempPath[i + 1] = 0; // Try to open the path, if that fails we need to create it if (!VFSFileOpen(volRefNum, tempPath, vfsModeRead, &fileRef)) { VFSFileClose(fileRef); } else { VFSDirCreate(volRefNum, tempPath); } memMgrChunkFree(tempPath); } else { // To bad, we'll just fail for now break; } } } #endif }
//*********************************************************** // Procedure: fclose // // Parameter: stream Reference to file // // Returnval: 0 // // Description: Close file. //*********************************************************** int fclose(FILE *stream) { UInt16 error; UInt32 lBytesWritten; //-------------------------------- // Check for stdxxx //-------------------------------- switch((int) stream) { case _stdin: case _stdout: case _stderr: return 0; } if(stream) { if(stream->cacheSize) { //--------------------------------------------- // Write cached data //--------------------------------------------- if(stream->bufSize > 0 && stream->mode == MODE_BUFWRITE) VFSFileWrite(stream->fileRef, stream->bufSize, stream->cache, &lBytesWritten); } //--------------------------------------------- // Close file //--------------------------------------------- if(stream->fileRef) error = VFSFileClose(stream->fileRef); //--------------------------------------------- // Release memory of cache //--------------------------------------------- if (stream->cache) free(stream->cache); //--------------------------------------------- // Release memory of file struct //--------------------------------------------- free(stream); } return 0; }
void fileClose(FILE *f) { if (!f) return; #ifdef USE_FILE_API if (f->fileHand) { FileClose(f->fileHand); f->fileHand = NULL; } #else if (f->fileRef) { VFSFileClose(f->fileRef); } #endif memMgrChunkFree(f); }
/*============================================================================ Description: See documentation for standard C library fclose ==========================================================================*/ unsigned short palm_fclose( PALM_FILE* io_pSF ) { unsigned short unRet = 0; if(io_pSF->volRef == ((UInt16)-1)) { unRet = FileClose( io_pSF->file.fh ); } else { unRet = VFSFileClose(io_pSF->file.fr); } MemPtrFree( io_pSF ); io_pSF = NULL; return unRet; }
/* Add file to doc list */ static void AddVFSFile ( UInt16 volRefNum, FileInfoType* info, const Char* dir, UInt16 location, EnumerateCardType enumerateWhat ) { Err err; Char* path; FileRef ref; DocumentInfo docInfo; UInt32 type; UInt32 creatorID; /* Set path to document */ path = SafeMemPtrNew( StrLen( dir ) + StrLen( info->nameP ) + 2 ); StrCopy( path, dir ); StrCat( path, info->nameP ); err = VFSFileOpen( volRefNum, path, vfsModeRead, &ref ); if ( err == errNone ) { Char volumeLabel[ LABEL_LEN ]; err = VFSFileDBInfo( ref, docInfo.name, &docInfo.attributes, NULL, &docInfo.created, NULL, NULL, NULL, NULL, NULL, &type, &creatorID, NULL ); if ( err == errNone && IsDocScan( enumerateWhat ) && type == ViewerDocumentType && creatorID == ViewerAppID ) { DocumentData* handlePtr; MemHandle handle; UInt16 index; VFSFileSize( ref, &docInfo.size ); GetPluckerVolumeLabel( volRefNum, volumeLabel, LABEL_LEN ); docInfo.cardNo = 0; docInfo.filename = info->nameP; VFSFileClose( ref ); handle = FindDocData( docInfo.name, numOfElements, &index ); if ( handle != NULL ) { UInt16 categories; UInt32 oldCreated; UInt16 oldLocation; Boolean oldActive; Char oldVolumeLabel[ LABEL_LEN ]; UInt16 fileLen; UInt16 volumeLabelLen; UInt32 timestamp; SetFoundDocument( index ); handlePtr = MemHandleLock( handle ); oldCreated = handlePtr->created; oldLocation = handlePtr->location; oldActive = handlePtr->active; categories = handlePtr->categories; timestamp = handlePtr->timestamp; fileLen = StrLen( handlePtr->data ) + 1; volumeLabelLen = StrLen( handlePtr->data + fileLen ) + 1; StrNCopy( oldVolumeLabel, handlePtr->data + fileLen, volumeLabelLen ); MemHandleUnlock( handle ); /* If the document is newer than the stored one, or moved to external card then updated info */ if ( ! oldActive || oldCreated < docInfo.created || oldLocation != location || ! STREQ( volumeLabel, oldVolumeLabel ) ) { /* Assign remaining document data */ docInfo.location = location; docInfo.active = true; docInfo.categories = categories; /* A "new" document should be indicated as unread */ if ( ! oldActive || oldCreated < docInfo.created ) docInfo.timestamp = 0; else docInfo.timestamp = timestamp; /* If document has been moved to external card the meta database must be renamed */ if ( oldLocation != location ) VFSRenameMetaDocument( docInfo.name, oldLocation, &docInfo ); UpdateDocument( &docInfo, volumeLabel, index, &handle ); } } else { docInfo.location = location; docInfo.volumeRef = volRefNum; docInfo.active = true; docInfo.timestamp = 0; ErrTry { docInfo.categories = GetDefaultCategories( &docInfo ); } ErrCatch( UNUSED_PARAM( err ) ) { docInfo.categories = UNFILED_CATEGORY; } ErrEndCatch AddDocument( &docInfo, volumeLabel ); } }