FT_Stream_Open( FT_Stream stream, const char* filepathname ) { // FILE* file; BPTR file; // TetiSoft struct FileInfoBlock* fib; // TetiSoft if ( !stream ) return FT_Err_Invalid_Stream_Handle; // file = fopen( filepathname, "rb" ); file = Open( filepathname, MODE_OLDFILE ); // TetiSoft if ( !file ) { FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_Err_Cannot_Open_Resource; } // fseek( file, 0, SEEK_END ); // astream->size = ftell( file ); // fseek( file, 0, SEEK_SET ); fib = AllocDosObject( DOS_FIB, NULL ); if ( !fib ) { Close ( file ); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_Err_Cannot_Open_Resource; } if ( !( ExamineFH( file, fib ) ) ) { FreeDosObject( DOS_FIB, fib ); Close ( file ); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_Err_Cannot_Open_Resource; } stream->size = fib->fib_Size; FreeDosObject( DOS_FIB, fib ); // stream->descriptor.pointer = file; stream->descriptor.pointer = (void *)file; stream->pathname.pointer = (char*)filepathname; stream->pos = 0; stream->read = ft_io_stream; stream->close = ft_close_stream; FT_TRACE1(( "FT_Stream_Open:" )); FT_TRACE1(( " opened `%s' (%d bytes) successfully\n", filepathname, stream->size )); return FT_Err_Ok; }
void readUserData(void) { BPTR lock; int goon; char __aligned buffer[2048]; struct ExAllControl *ec; struct ExAllData *ed; printf("Reading user data...\n"); if(!(ec = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { cleanup(EXIT_ERROR, "Out of memory."); } if(!(lock = Lock("NiKom:Users", ACCESS_READ))) { FreeDosObject(DOS_EXALLCONTROL, ec); cleanup(EXIT_ERROR,"Could not Lock() NiKom:Users\n"); } ec->eac_LastKey = 0L; ec->eac_MatchString = NULL; ec->eac_MatchFunc = NULL; goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; for(;;) { if(!ec->eac_Entries) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; continue; } if(!scanUserDir(ed->ed_Name)) { UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); cleanup(EXIT_ERROR, "Could not read users."); } ed = ed->ed_Next; if(!ed) { if(!goon) { break; } goon = ExAll(lock,(struct ExAllData *)buffer,2048,ED_NAME,ec); ed = (struct ExAllData *)buffer; } } UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); printf("Read users (Highest id: %d)\n", ((struct ShortUser *)Servermem->user_list.mlh_TailPred)->nummer); printf("User #0 : %s\n",((struct ShortUser *)Servermem->user_list.mlh_Head)->namn); }
int scanUserDir(char *dirname) { BPTR lock; int goon; char __aligned buffer[2048]; struct ExAllControl *ec; struct ExAllData *ed; char path[100]; printf(" Reading user directory %s...\n", dirname); if(!(ec = (struct ExAllControl *)AllocDosObject(DOS_EXALLCONTROL, NULL))) { cleanup(EXIT_ERROR,"Out of memory."); } sprintf(path, "NiKom:Users/%s", dirname); if(!(lock = Lock(path, ACCESS_READ))) { FreeDosObject(DOS_EXALLCONTROL, ec); cleanup(EXIT_ERROR,"Could not Lock() NiKom:Users/x"); } ec->eac_LastKey = 0L; ec->eac_MatchString = NULL; ec->eac_MatchFunc = NULL; goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; for(;;) { if(!ec->eac_Entries) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; continue; } if(!readSingleUser(atoi(ed->ed_Name))) { UnLock(lock); FreeDosObject(DOS_EXALLCONTROL, ec); return 0; } ed = ed->ed_Next; if(!ed) { if(!goon) { break; } goon = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_NAME, ec); ed = (struct ExAllData *)buffer; } } UnLock(lock); FreeDosObject(DOS_EXALLCONTROL, ec); return 1; }
/****************************************************************** * my_isfilehidden * * Hidden is *wrong* here. AmigaOS just knows "Hold"! ******************************************************************/ bool my_isfilehidden (const TCHAR *name) { struct FileInfoBlock *fib=NULL; BPTR lock=NULL; bool result=FALSE; D(bug("[JUAE:A-FSDB] %s('%s')\n", __PRETTY_FUNCTION__, name)); lock=Lock(name, SHARED_LOCK); if(!lock) { bug("[JUAE:A-FSDB] %s: failed to lock entry %s\n", __PRETTY_FUNCTION__, name); goto exit; } if(!(fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) || !Examine(lock, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine lock @ 0x%p [fib @ 0x%p]\n", __PRETTY_FUNCTION__, lock, fib); goto exit; } if(fib->fib_Protection & FIBF_HOLD) { result=TRUE; } exit: if(lock) UnLock(lock); if(fib) FreeDosObject(DOS_FIB, fib); return result; }
VOID ToggleModuleDisabled( BlankerPrefs *Prefs ) { struct FileInfoBlock *Blk; BPTR BlankerLock; BYTE Path[108]; strcpy( Path, Prefs->bp_Dir ); AddPart( Path, Prefs->bp_Blanker, 108 ); if( BlankerLock = Lock( Path, ACCESS_READ )) { if( Blk = AllocDosObject( DOS_FIB, 0L )) { if( Examine( BlankerLock, Blk )) { if( Stricmp( Blk->fib_Comment, "Disabled" )) SetComment( Path, "Disabled" ); else SetComment( Path, "" ); } FreeDosObject( DOS_FIB, Blk ); } UnLock( BlankerLock ); } }
void my_setfilehidden (const TCHAR *name, bool hidden) { LONG mask; struct FileInfoBlock *fib=NULL; BPTR lock=NULL; D(bug("[JUAE:A-FSDB] %s('%s')\n", __PRETTY_FUNCTION__, name)); lock=Lock(name, SHARED_LOCK); if(!lock) { bug("[JUAE:A-FSDB] %s: failed to lock entry %s\n", __PRETTY_FUNCTION__, name); goto exit; } if(!(fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) || !Examine(lock, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine lock @ 0x%p [fib @ 0x%p]\n", __PRETTY_FUNCTION__, lock, fib); goto exit; } mask=fib->fib_Protection | FIBF_HOLD; if(!SetProtection(name, mask)) { bug("ERROR: could not set %s to FIBF_HOLD!\n", name); } exit: if(lock) UnLock(lock); if(fib) FreeDosObject(DOS_FIB, fib); return; }
/* * fgetentrytype * * check whether a filesystem object is a file or a directory * * result: see fentrytype_t definition * */ fentrytype_t fgetentrytype(const STRPTR name) { fentrytype_t type = FE_NONE; #ifdef AMIGA struct FileInfoBlock *fib; BPTR lock = Lock(name,ACCESS_READ); if(lock) { if((fib = AllocDosObjectTagList(DOS_FIB,NULL))) { if(Examine(lock,fib)) { /* this will barf on softlinks, but on AmigaOS these suck anyway */ type = (fib->fib_DirEntryType > 0) ? FE_DIR : FE_FILE; } FreeDosObject(DOS_FIB,fib); } UnLock(lock); } #else /* Does this work on RiscOS? Does anyone use HSC on RiscOS? Does anyone use * RiscOS...? */ struct stat sbuf; if(-1 != stat(name,&sbuf)) { if(S_ISDIR(sbuf.st_mode)) type = FE_DIR; else if(S_ISREG(sbuf.st_mode) || S_ISLNK(sbuf.st_mode)) type = FE_FILE; } #endif return type; }
/* * fgetmtime * * Get the date/time of last modification from a file and return it as a * pointer to an internal struct tm or NULL on failure. * */ const struct tm *fgetmtime(const STRPTR name) { struct tm *time = NULL; #ifdef AMIGA struct FileInfoBlock *fib; BPTR lock = Lock(name,ACCESS_READ); if(lock) { if((fib = AllocDosObjectTagList(DOS_FIB,NULL))) { if(Examine(lock,fib)) { time_t tt; /* convert struct DateStamp to time_t format */ /* TODO: test this */ tt = 252432000 + fib->fib_Date.ds_Days * 86400 + fib->fib_Date.ds_Minute * 60 + fib->fib_Date.ds_Tick / 50; time = localtime(&tt); } FreeDosObject(DOS_FIB,fib); } UnLock(lock); } #else /* Does this work on RiscOS? Does anyone use HSC on RiscOS? Does anyone use * RiscOS...? */ struct stat sbuf; if(-1 != stat(name,&sbuf)) { time = localtime(&sbuf.st_mtime); } #endif return time; }
int deleteDir(char *dirname) { char __aligned buffer[2048]; struct ExAllControl *ec; int moreFromExAll, success = TRUE; BPTR lock; if(!(lock = Lock(dirname, ACCESS_READ))) { return 1; } printf("Deleting all files in directory %s\n", dirname); ec = (struct ExAllControl *) AllocDosObject(DOS_EXALLCONTROL, NULL); ec->eac_LastKey=0L; ec->eac_MatchString=NULL; ec->eac_MatchFunc=NULL; do { moreFromExAll = ExAll(lock, (struct ExAllData *)buffer, 2048, ED_TYPE, ec); if(!handleExAllResult(ec, (struct ExAllData *) buffer, dirname)) { success = FALSE; break; } } while(moreFromExAll); UnLock(lock); FreeDosObject(DOS_EXALLCONTROL,ec); if(success) { success = deleteFile(dirname); } return success; }
int stat(const char *name,struct stat *buf) { APTR oldwin,*wptr=&((struct Process *)FindTask(NULL))->pr_WindowPtr; struct FileInfoBlock *fib; BPTR lock; int ret=-1; #ifdef IXPATHS if((name=__amigapath(name))==NULL) return -1; #endif /* avoid possible dos-requesters ;-( */ oldwin=*wptr; *wptr=(APTR)ret; if((lock=Lock((STRPTR)name,SHARED_LOCK))!=0) { if((fib=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL))!=NULL) { if(Examine(lock,fib)!=DOSFALSE) ret=__stat(buf,fib); else __seterrno(); FreeDosObject(DOS_FIB,fib); } else __seterrno(); UnLock(lock); } else __seterrno(); *wptr=oldwin; return ret; }
static PtrT ReadFileToCustomMemory(const StrT fileName, uint32_t memFlags) { BPTR fh; PtrT data = NULL; PtrT path = AbsPath(fileName); if ((fh = Open(path, MODE_OLDFILE))) { struct FileInfoBlock *infoBlock; if ((infoBlock = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL))) { if (ExamineFH(fh, infoBlock)) { size_t dataLen = infoBlock->fib_Size; if ((data = MemNewCustom(dataLen, memFlags, NULL))) { if (dataLen != Read(fh, data, dataLen)) { MemUnref(data); data = NULL; } } } FreeDosObject(DOS_FIB, infoBlock); } Close(fh); } MemUnref(path); return data; }
void my_closedir (struct my_opendir_s *mod) { if(mod) { if(mod->h) FreeDosObject(DOS_FIB, mod->h); if(mod->lock) UnLock(mod->lock); free(mod); } }
void ami_menu_arexx_scan(struct gui_window_2 *gwin) { int item = AMI_MENU_AREXX; BPTR lock = 0; UBYTE *buffer; struct ExAllControl *ctrl; char matchpatt[16]; LONG cont; struct ExAllData *ead; char *menu_lab; if(lock = Lock(nsoption_charp(arexx_dir), SHARED_LOCK)) { if(buffer = AllocVecTagList(1024, NULL)) { if(ctrl = AllocDosObject(DOS_EXALLCONTROL,NULL)) { ctrl->eac_LastKey = 0; if(ParsePatternNoCase("#?.nsrx",(char *)&matchpatt,16) != -1) { ctrl->eac_MatchString = (char *)&matchpatt; } do { cont = ExAll(lock,(struct ExAllData *)buffer,1024,ED_COMMENT,ctrl); if((!cont) && (IoErr() != ERROR_NO_MORE_ENTRIES)) break; if(!ctrl->eac_Entries) continue; for(ead = (struct ExAllData *)buffer; ead; ead = ead->ed_Next) { if(item >= AMI_MENU_AREXX_MAX) continue; if(EAD_IS_FILE(ead)) { gwin->menu[item].nm_Type = NM_ITEM; if(ead->ed_Comment[0] != '\0') menu_lab = ead->ed_Comment; else menu_lab = ead->ed_Name; ami_menu_alloc_item(gwin, item, NM_ITEM, menu_lab, 0, NULL, ami_menu_item_arexx_entries, (void *)strdup(ead->ed_Name)); item++; } } }while(cont); FreeDosObject(DOS_EXALLCONTROL,ctrl); } FreeVec(buffer); } UnLock(lock); } gwin->menu[item].nm_Type = NM_END; gwin->menu[item].nm_Label = NULL; }
void NewFreeArgs(struct NewRDArgs *rdargs) { ENTER(); D(DBF_STARTUP, "FreeArgs(rdargs->FreeArgs)"); FreeArgs(rdargs->FreeArgs); if(rdargs->RDArgs != NULL) { free((void *)rdargs->RDArgs->RDA_Source.CS_Buffer); D(DBF_STARTUP, "FreeDosObject(DOS_RDARGS, rdargs->RDArgs)"); FreeDosObject(DOS_RDARGS, rdargs->RDArgs); } if(rdargs->Args != NULL) { ULONG i; for(i=0; i < rdargs->MaxArgs; i++) { if(rdargs->Args[i] != NULL) FreeVecPooled(rdargs->Pool, rdargs->Args[i]); } FreeVecPooled(rdargs->Pool, rdargs->Args); rdargs->Args = NULL; } if(rdargs->ToolWindow != NULL) { FreeVecPooled(rdargs->Pool, rdargs->ToolWindow); rdargs->ToolWindow = NULL; } if(rdargs->WinFH != 0) { D(DBF_STARTUP, "SelectOutput( .. ) .. Close( ... )"); SelectOutput(rdargs->OldOutput); SelectInput(rdargs->OldInput); Close(rdargs->WinFH); rdargs->WinFH = 0; } if(rdargs->Pool != NULL) { #if defined(__amigaos4__) FreeSysObject(ASOT_MEMPOOL, rdargs->Pool); #else DeletePool(rdargs->Pool); #endif rdargs->Pool = NULL; } D(DBF_STARTUP, "memory freed"); LEAVE(); }
/****************************************************************** * my_getvolumeinfo (also works for directories on AROS) * * * return FLAGS: * -1: error * MYVOLUMEINFO_READONLY * * all other flags not supported, as they are not used anywhere * ******************************************************************/ int my_getvolumeinfo (const TCHAR *name) { struct FileInfoBlock *fib; BPTR file=NULL; int ret=-1; bug("[JUAE:A-FSDB] %s('%s')\n", __PRETTY_FUNCTION__, name); fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, TAG_END); if(!fib) { bug("[JUAE:A-FSDB] %s: failed to allocate FIB\n", __PRETTY_FUNCTION__); goto EXIT; } if(!(file=Lock(name, SHARED_LOCK))) { bug("[JUAE:A-FSDB] %s: failed to lock entry\n", __PRETTY_FUNCTION__); DebOut("no lock..\n"); goto EXIT; } if (!Examine(file, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine\n", __PRETTY_FUNCTION__); goto EXIT; } bug("[JUAE:A-FSDB] %s: fib prot flags 0x%lx\n", __PRETTY_FUNCTION__, fib->fib_Protection); if(fib->fib_DirEntryType >0) { bug("[JUAE:A-FSDB] %s: DIRECTORY!\n", __PRETTY_FUNCTION__); ret=0; } if(!(fib->fib_Protection && FIBF_WRITE)) { bug("[JUAE:A-FSDB] %s: read only entry!\n", __PRETTY_FUNCTION__); ret=MYVOLUMEINFO_READONLY; } EXIT: if(fib) { FreeDosObject(DOS_FIB, fib); } if(file) { UnLock(file); } return ret; }
/****************************************************************** * fsdb_fill_file_attrs * * For an a_inode we have newly created based on a filename we * found on the native fs, fill in information about this * file/directory. * ******************************************************************/ int fsdb_fill_file_attrs (a_inode *base, a_inode *aino) { struct FileInfoBlock *fib=NULL; BPTR lock=NULL; int ret=0; //DebOut("%lx %lx\n", base, aino); //DebOut("aino->dir: %s\n", aino->dir); DebOut("aino->nname: %s\n", aino->nname); fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, TAG_END); if(!fib) goto ERROR; lock=Lock(aino->nname, SHARED_LOCK); if(!lock) goto ERROR; if (!Examine(lock, fib)) goto ERROR; if(fib->fib_DirEntryType>0) { //DebOut("=> directory\n"); aino->dir=1; if(fib->fib_DirEntryType==ST_SOFTLINK) { DebOut("WARNING: not tested: SoftLink detected!\n"); aino->softlink=2; /* 1 hardlink, 2 softlink ? */ } } if(fib->fib_Comment) { //DebOut("comment: >%s<\n", fib->fib_Comment); aino->comment=(TCHAR *) strndup((const char *)fib->fib_Comment, 79); /* maximum length is 79 chars, 0 will be added automatically */ } aino->amigaos_mode=fib->fib_Protection; //DebOut("protection: %04x\n", fib->fib_Protection); /* !? */ #if 0 if (reset && (base->volflags & MYVOLUMEINFO_STREAMS)) { create_uaefsdb (aino, fsdb, mode); write_uaefsdb (aino->nname, fsdb); } #endif ret=1; #warning TODO?: care for base and host changes! ERROR: if(fib) FreeDosObject(DOS_FIB, fib); if(lock) UnLock(lock); return ret; }
/* Release all resources allocated during `simulated_opendir'; also works correctly if structure was only partially initialized. */ static void free_simulated_dir(SIMULATED_DIR * dir) { if (dir != NULL) { if (dir->lock != NULL) { UnLock(dir->lock); } if (dir->info != NULL) { FreeDosObject(DOS_FIB, dir->info); } free(dir); } }
/* Free all resources allocated in ParseTemplate */ VOID FreeTemplate(APTR m) { ULONG *mem = (ULONG*)m; if(mem) { if(mem[2]) FreeArgs((struct RDArgs*)mem[2]); if(mem[1]) FreeVec((APTR)mem[1]); if(mem[0]) FreeDosObject(DOS_RDARGS,(APTR)mem[0]); } FreeVec(mem); }
int lib_dos_f_FreeArgs_3(emumsg_syscall_t *msg) { lib_dos_s_rdargs_t *rdargs; DEBUG(4) dprintf("dos.library: lib_dos_f_FreeArgs_3() called\n"); /* Recall rdargs structure */ rdargs = (lib_dos_s_rdargs_t *)msg->internalPtr; /* Free dos object */ FreeDosObject(DOS_RDARGS, rdargs->real); mmu_delEntry(rdargs->entry); return HOOK_DONE; }
// Build theme list Att_List *theme_build_list(char *path) { Att_List *list; // Create list if ((list=Att_NewList(LISTF_POOL))) { long err; char buf[280]; #ifdef __amigaos4__ struct AnchorPath *anchor; if (!(anchor = AllocDosObjectTags( DOS_ANCHORPATH, ADO_Strlen, 0, ADO_Flags, APF_DOWILD, ADO_Mask, 0, TAG_DONE))) { return NULL; } #else D_S(struct AnchorPath,anchor) anchor->ap_BreakBits=0; anchor->ap_Flags=APF_DOWILD; anchor->ap_Strlen=0; #endif strcpy(buf,path); AddPart(buf,"#?.theme",280); err=MatchFirst(buf,anchor); while (!err) { char *ptr; if (anchor->ap_Info.fib_DirEntryType>0) { anchor->ap_Flags&=~APF_DODIR; continue; } anchor->ap_Info.fib_FileName[strlen(anchor->ap_Info.fib_FileName)-6]=0; for (ptr=anchor->ap_Info.fib_FileName;*ptr;ptr++) if (*ptr=='_') *ptr=' '; Att_NewNode(list,anchor->ap_Info.fib_FileName,0,ADDNODE_SORT); err=MatchNext(anchor); } MatchEnd(anchor); #ifdef __amigaos4__ FreeDosObject(DOS_ANCHORPATH,anchor); #endif }
long Q_filesize (const char *path) { long size = -1; BPTR fh = Open((const STRPTR) path, MODE_OLDFILE); if (fh) { struct FileInfoBlock *fib = (struct FileInfoBlock*) AllocDosObject(DOS_FIB, NULL); if (fib != NULL) { if (ExamineFH(fh, fib)) size = fib->fib_Size; FreeDosObject(DOS_FIB, fib); } Close(fh); } return size; }
struct List *LoadBlankerEntries( STRPTR Path ) { struct FileInfoBlock *Blk; struct List *Entries = 0L; BlankerEntry *New; BPTR DirLock; if(!( Entries = AllocVec( sizeof( struct List ), MEMF_CLEAR ))) return 0L; else NewList( Entries ); NumBlankEntries = 0; if( DirLock = Lock( Path, ACCESS_READ )) { if(( Blk = AllocDosObject( DOS_FIB, 0L ))&&( Examine( DirLock, Blk ))) { while( ExNext( DirLock, Blk )) { if(( Blk->fib_FileName )&& ( FileIsModule( Path, Blk->fib_FileName ))) { if( New = NewBlankerEntry( Path, Blk->fib_FileName, Blk->fib_Comment )) { New->be_Node.ln_Pri = 128 - ( New->be_Name[0] - 'a' ); Enqueue( Entries, ( struct Node * )New ); NumBlankEntries++; } } } FreeDosObject( DOS_FIB, Blk ); } UnLock( DirLock ); } if( New = NewBlankerEntry( ":", "Random", "" )) AddTail( Entries, ( struct Node * )New ); return Entries; }
/************************************************************************** Returns the size of a file **************************************************************************/ LONG GetFileSize( BPTR fileh ) { struct FileInfoBlock *fib = (struct FileInfoBlock*)AllocDosObject( DOS_FIB, NULL ); LONG size = -1; if (fib) { if (ExamineFH( fileh, fib )) { if ((fib->fib_DirEntryType > 0) && (fib->fib_DirEntryType != ST_SOFTLINK)) { size = 0; } size = fib->fib_Size; } FreeDosObject( DOS_FIB, fib ); } return size; }
/* get file size */ ULONG file_size(BYTE *path) { BPTR file; struct FileInfoBlock *fib; struct Library *dosBase; dosBase = OpenLibrary("dos.library", 40L); if (!dosBase) { printf("Error opening dos.library!\n"); exit(20); } fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, TAG_END); if (!fib) { printf("Couldn't allocate dos object!\n"); CloseLibrary(dosBase); exit(20); } if (file = Lock(path, SHARED_LOCK)) { if (Examine(file, fib)) { #ifdef DEBUG printf("DEBUG: Examine() returns file size %lx\n", fib->fib_Size); #endif /* DEBUG */ } else { printf("Couldn't Examine() file!\n"); /* XXX */ } UnLock(file); } else { printf("Couldn't lock file!\n"); exit(20); } FreeDosObject(DOS_FIB, fib); CloseLibrary(dosBase); return fib->fib_Size; }
ULONG FileSize(char *filename) { struct FileInfoBlock *fib; BPTR lock; ULONG size = 0; if((lock = Lock((STRPTR)filename, ACCESS_READ))) { if((fib = AllocDosObject(DOS_FIB, NULL))) { if(Examine(lock, fib)) { size = fib->fib_Size; } FreeDosObject(DOS_FIB, fib); } UnLock(lock); } return size; }
int Q_FileType (const char *path) { int type = FS_ENT_NONE; BPTR fh = Open((const STRPTR) path, MODE_OLDFILE); if (fh) { struct FileInfoBlock *fib = (struct FileInfoBlock*) AllocDosObject(DOS_FIB, NULL); if (fib != NULL) { if (ExamineFH(fh, fib)) { if (fib->fib_DirEntryType >= 0) type = FS_ENT_DIRECTORY; else type = FS_ENT_FILE; } FreeDosObject(DOS_FIB, fib); } Close(fh); } return type; }
/****** SmartReadArgs/SmartFreeArgs ****************************************** * NAME * SmartFreeArgs -- Free all resources allocated by SmartReadArgs(). * SYNOPSIS * SmartFreeArgs(smart_args); * * void SmartFreeArgs(struct SmartArgs *); * FUNCTION * Free all resources allocated by a previous call to SmartReadArgs(). * INPUTS * smart_args - Same pointer as passed to SmartReadArgs() before * NOTES * Always call SmartFreeArgs(), even if SmartReadArgs() failed! Take a look * at the example for SmartReadArgs(). * SEE ALSO * SmartReadArgs() ****************************************************************************/ void SmartFreeArgs(struct SmartArgs *args) { /* FreeArgs() can handle a NULL pointer */ FreeArgs(args->sa_FreeArgs); if (args->sa_Flags & SAF_ALLOCRDARGS) if (args->sa_RDArgs) FreeDosObject(DOS_RDARGS, args->sa_RDArgs); if (args->sa_Flags & SAF_ALLOCBUFFER) FreeMem(args->sa_Buffer, args->sa_BufferSize); if (args->sa_WindowFH) { SelectOutput(args->sa_OldOutput); SelectInput(args->sa_OldInput); Close(args->sa_WindowFH); } if (args->sa_Flags & SAF_ALLOCWINDOW && args->sa_Window) FreeVec(args->sa_Window); }
/* TODO: 64bit sizes !? */ uae_s64 int my_fsize (struct my_openfile_s *mos) { struct FileInfoBlock * fib=NULL; BPTR lock=NULL; uae_s64 size; if(!(fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) || !Examine(lock, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine lock @ 0x%p [fib @ 0x%p]\n", __PRETTY_FUNCTION__, lock, fib); size=-1; goto EXIT; } /* test for 64 bit filesize */ if(fib->fib_Size >= 0x7FFFFFFF) { bug("[JUAE:A-FSDB] %s: WARNING: filesize >2GB detected. This has never been tested!\n", __PRETTY_FUNCTION__); UQUAD *size_ptr=(UQUAD *)DoPkt(((struct FileLock *)lock)->fl_Task, ACTION_GET_FILE_SIZE64, (IPTR)lock, 0, 0, 0, 0); if (size_ptr) { size=(uae_s64) *size_ptr; } else { bug("[JUAE:A-FSDB] %s: ERROR: DoPkt return NULL!\n"); size=-1; } goto EXIT; } /* extend 32-bit */ size=(uae_s64) fib->fib_Size; EXIT: DebOut("size: %d\n", size); FreeDosObject(DOS_FIB, fib); return size; }
FT_Stream_Open( FT_Stream stream, const char* filepathname ) { struct FileInfoBlock* fib; struct SysFile* sysfile; if ( !stream ) return FT_THROW( Invalid_Stream_Handle ); #ifdef __amigaos4__ sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_SHARED ); #else sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_PUBLIC ); #endif if ( !sysfile ) { FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_THROW( Cannot_Open_Resource ); } sysfile->file = Open( (STRPTR)filepathname, MODE_OLDFILE ); if ( !sysfile->file ) { FreeMem ( sysfile, sizeof ( struct SysFile )); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_THROW( Cannot_Open_Resource ); } fib = AllocDosObject( DOS_FIB, NULL ); if ( !fib ) { Close ( sysfile->file ); FreeMem ( sysfile, sizeof ( struct SysFile )); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_THROW( Cannot_Open_Resource ); } if ( !( ExamineFH( sysfile->file, fib ) ) ) { FreeDosObject( DOS_FIB, fib ); Close ( sysfile->file ); FreeMem ( sysfile, sizeof ( struct SysFile )); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not open `%s'\n", filepathname )); return FT_THROW( Cannot_Open_Resource ); } stream->size = fib->fib_Size; FreeDosObject( DOS_FIB, fib ); stream->descriptor.pointer = (void *)sysfile; stream->pathname.pointer = (char*)filepathname; sysfile->iobuf_start = 0; sysfile->iobuf_end = 0; stream->pos = 0; stream->read = ft_amiga_stream_io; stream->close = ft_amiga_stream_close; if ( !stream->size ) { ft_amiga_stream_close( stream ); FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " opened `%s' but zero-sized\n", filepathname )); return FT_THROW( Cannot_Open_Stream ); } FT_TRACE1(( "FT_Stream_Open:" )); FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n", filepathname, stream->size )); return FT_Err_Ok; }
bool my_stat (const TCHAR *name, struct mystat *statbuf) { struct FileInfoBlock *fib=NULL; BPTR lock=NULL; bool result=FALSE; D(bug("[JUAE:A-FSDB] %s('%s')\n", __PRETTY_FUNCTION__, name)); lock=Lock(name, SHARED_LOCK); if(!lock) { bug("[JUAE:A-FSDB] %s: failed to lock entry %s\n", __PRETTY_FUNCTION__, name); goto exit; } if(!(fib=(struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) || !Examine(lock, fib)) { bug("[JUAE:A-FSDB] %s: failed to examine lock @ 0x%p [fib @ 0x%p]\n", __PRETTY_FUNCTION__, lock, fib); goto exit; } statbuf->size=fib->fib_Size; statbuf->mode=0; if(fib->fib_DiskKey) { D(bug("[JUAE:A-FSDB] %s: %s FILEFLAG_DIR\n", __PRETTY_FUNCTION__, name)); statbuf->mode |= FILEFLAG_DIR; } #ifdef DEBUG { char flags[8]; flags[0] = fib->fib_Protection & FIBF_SCRIPT ? 's' : '-'; flags[1] = fib->fib_Protection & FIBF_PURE ? 'p' : '-'; flags[2] = fib->fib_Protection & FIBF_ARCHIVE ? 'a' : '-'; // Active when unset! flags[3] = fib->fib_Protection & FIBF_READ ? '-' : 'r'; flags[4] = fib->fib_Protection & FIBF_WRITE ? '-' : 'w'; flags[5] = fib->fib_Protection & FIBF_EXECUTE ? '-' : 'e'; flags[6] = fib->fib_Protection & FIBF_DELETE ? '-' : 'd'; flags[7] = 0x00; bug("[JUAE:A-FSDB] %s: %s protection: %s\n", __PRETTY_FUNCTION__, name, flags); } #endif /* fib_Protection: active-low, i.e. not set means active! (who invented this !??) */ if(!(fib->fib_Protection & FIBF_READ)) { statbuf->mode |= FILEFLAG_READ; } if(!(fib->fib_Protection & FIBF_WRITE)) { statbuf->mode |= FILEFLAG_WRITE; } if(!(fib->fib_Protection & FIBF_EXECUTE)) { statbuf->mode |= FILEFLAG_EXECUTE; } /* FIBF_ARCHIVE, FIBF_PURE and FIBF_SCRIPT are active when set */ if(fib->fib_Protection & FIBF_ARCHIVE) { statbuf->mode |= FILEFLAG_ARCHIVE; } if(fib->fib_Protection & FIBF_PURE) { statbuf->mode |= FILEFLAG_PURE; } if(fib->fib_Protection & FIBF_SCRIPT) { statbuf->mode |= FILEFLAG_SCRIPT; } amiga_to_timeval(&statbuf->mtime, fib->fib_Date.ds_Days, fib->fib_Date.ds_Minute, fib->fib_Date.ds_Tick); result=TRUE; exit: if(lock) UnLock(lock); if(fib) FreeDosObject(DOS_FIB, fib); return result; }