• Welcome to PlanetSquires Forums.
 

Wrong function return for file procedures?

Started by Bumblebee, January 19, 2020, 11:29:05 AM

Previous topic - Next topic

Bumblebee

If my understanding is correct, the Afx file procedures listed below should return true upon each successful file operation.
As it stands, variable y only returns true for AfxMakeDir and AfxKill. The other functions return false even though their disk operations were successful.
What am I doing wrong?

Relevant code excerpt:

dim shared as CWSTR c,d,rm(),m
dim shared y as Boolean
dim shared g as Integer

select case g
  case 1 : y = AfxMakeDir (d)
  case 2 : y = AfxFileCopy (c,d)
  case 3 : y = AfxName (c,d)
  case 4 : y = AfxKill (c)
  case 5 : y = AfxRemoveDir (d)
end select
if y = false then print "Error ^"


Edit: I forgot to test AfxRemoveDir... it also returns true.
Here is the output from a test of all five functions:

;
  Mirror backup  01-19-2020  12:20:57
  --------------------------------------------------
  C:\Decoy > E:\Decoy
  --------------------------------------------------
  Create folder  E:\Decoy\hello [true]
         Update  E:\Decoy\Software\fb\backup.bas [false]
         Update  E:\Decoy\Software\fb\backup.exe [false]
   Empty folder  E:\Decoy\download
  File moved to  E:\Decoy\hello\Aquarius.jpg [false]
           Copy  C:\Decoy\hello\Athena.jpg [false]
  File moved to  E:\Decoy\hello\bartlett.jpg [false]
  File moved to  E:\Decoy\hello\crow.jpg [false]
  File moved to  E:\Decoy\hello\crows in cemetary.jpg [false]
  File moved to  E:\Decoy\hello\current.alm [false]
  File moved to  E:\Decoy\hello\kayla-maurais-Vsllwfgk4yw-unsplash.jpg [false]
  File moved to  E:\Decoy\hello\misc.txt [false]
           Copy  C:\Decoy\hello\abc.gif [false]
           Copy  C:\Decoy\Software\fb\crow.exe [false]
         Delete  E:\Decoy\download\abc.gif [true]
   Erase folder  E:\Decoy\download [true]
¯\(º_º)/¯                   Â¯\(º_º)/¯

13998 files processed. Backup complete.
Failed pollinator.

José Roca

Both AfxFileCopy, AfxKill and AfxName are unicode replacements for FreeBasic FileCopy and Name functions, and return the same values that the functions that they replace.

For functions that return true instead of false, use AfxCopyFile, AfxDeleteFile and AfxRenameFile.

As stated in the documentation:

AfxMkDir is an unicode replacement for Free Basic's MkDir and returns 0 on success, or -1 on failure.
AfxKill is an unicode replacement for Free Basic's Kill and returns 0 on success, or -1 on failure.
AfxName is an unicode replacement for Free Basic's Name and returns 0 on success, or non-zero on failure.
AfxRmDir is an unicode replacement for Free Basic's RmDir and returns 0 on success, or -1 on failure.



Bumblebee

#2
dim shared y as integer

;
  Mirror backup  01-19-2020  15:17:18
  --------------------------------------------------
  C:\Decoy > E:\Decoy
  --------------------------------------------------
  Create folder  E:\Decoy\download [-1]
         Update  E:\Decoy\Software\fb\backup.bas [ 0 ]
         Update  E:\Decoy\Software\fb\backup.exe [ 0 ]
   Empty folder  E:\Decoy\hello
  File moved to  E:\Decoy\download\Aquarius.jpg [ 0 ]
  File moved to  E:\Decoy\download\Athena.jpg [ 0 ]
  File moved to  E:\Decoy\download\bartlett.jpg [ 0 ]
  File moved to  E:\Decoy\download\crow.jpg [ 0 ]
  File moved to  E:\Decoy\download\crows in cemetary.jpg [ 0 ]
  File moved to  E:\Decoy\download\current.alm [ 0 ]
  File moved to  E:\Decoy\download\fantasy map.map [ 0 ]
  File moved to  E:\Decoy\download\Fool's Proof.jpg [ 0 ]
  File moved to  E:\Decoy\download\Gwhendolyn.gif [ 0 ]
  File moved to  E:\Decoy\download\Helena.png [ 0 ]
  File moved to  E:\Decoy\download\kayla-maurais-Vsllwfgk4yw-unsplash.jpg [ 0 ]
  File moved to  E:\Decoy\download\misc.txt [ 0 ]
  File moved to  E:\Decoy\download\Stereo Songweaver.jpg [ 0 ]
  File moved to  E:\Decoy\download\Summer Of The Fire Ship.jpg [ 0 ]
  File moved to  E:\Decoy\download\tcovrc.jpg [ 0 ]
  File moved to  E:\Decoy\download\abc.gif [ 0 ]
   Erase folder  E:\Decoy\hello [-1]

¯\(º_º)/¯                   Â¯\(º_º)/¯

13982 files processed. Backup complete.


AfxName returns 0 on success
AfxMakeDir/AfxMkDir returns -1 on success
AfxRemoveDir/AfxRmDir returns -1 on success

Whether I use a boolean or integer variable, the returned value for some of the functions is incorrect.
As it stands now, the documentation is partially incorrect.

I can work around this, but why aren't the return codes consistent?
Failed pollinator.

José Roca

They don't return incorrect results. There are some functions, named like the FB ansi functions but with the Afx prefix,  that return 0 on success for compatibility with the intrinsic FB functions, and there are others with different names that return True on success.

AfxName returns 0 on success for compatibility with FB's NAME function, but AfxRenameFile returns a boolean True or False.

Bumblebee

Ideally, I would select unicode replacements that return boolean True.
Do all these functions support unicode?
Failed pollinator.

José Roca

> Do all these functions support unicode?

Indeed. Everything in my framework is unicode aware.

Bumblebee

Quote from: José Roca on January 19, 2020, 09:33:40 PM
> Do all these functions support unicode?

Indeed. Everything in my framework is unicode aware.
Excellent. Thanks for your help.

To reiterate, AfxMkDir returns -1 on success and AfxRmDir returns -1 on success, contrary to what the documentation says. Their return codes are boolean.
Failed pollinator.

José Roca

Thanks. I'm going to revise them. The problem was that I wrote them before the boolean data type was implemented in FreeBsic. Previously, the current functions that return a boolean returned a long and a value of 0 or 1. After changing the return value from long to boolean, it returns 0 or -1, and NOT -1 returns -2 instead of 0.

José Roca

Modified AfxChDir, AfxMkDir, AfxRmDir and AfxName to return 0 on success or -1 on failure.

Bumblebee

To confirm, are the following functions identical, other than the way they are spelled?
AfxMakeDir / AfxCreateDirectory
AfxRenameFile / AfxMoveFile
AfxRemoveDir / AfxRemoveDirectory
Failed pollinator.