mIRC Home    About    Download    Register    News    Help

Print Thread
#191481 09/12/07 06:01 PM
Joined: Dec 2002
Posts: 2,031
R
RoCk Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

I can't help but wonder about the -n switch, the help file says that The -n switch creates the file if it doesn't already exist, fails if it does exist. So if the file doesn't already exist, the -n switch creates the file and the file is opened, why couldn't the file just be opened if it already exists, as if the -n switch weren't used? It makes sense to me.

RoCk #191482 09/12/07 06:58 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Because that behaviour might not be desired? If the scripter wants that then the -o switch exists. The two switches and the lack of a switch cover all the possible behaviours that might be wanted.

Code:
		| Exists	| Doesn't Exist
------------------------------------------------
no switch	| opens		| fails
-o		| opens		| opens
-n		| fails		| opens


OK that table sucks but you get the idea.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
starbucks_mafia #191484 09/12/07 07:26 PM
Joined: Dec 2002
Posts: 2,031
R
RoCk Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

Originally Posted By: starbucks_mafia

Because that behaviour might not be desired?


Desired by whom?


Originally Posted By: starbucks_mafia

If the scripter wants that then the -o switch exists.


Well that's no alternative, because then the file would be overwritten if it exists. I'm just saying the two should be consistent, the -o switch opens the file whether or not the file exists (overwriting IF it does exist), the -n switch behavior should be the same, open the file whether or not the file exists (creating a new file IF it doesn't exist). The only time it should fail is if no switch is used and the file doesn't exist.

If the -o switch behavior were consistent with the -n switch behavior, then it would create the file (overwriting IF it exists) and then fail, like the -n switch creates the file (IF it doesn't exist) and then fails.

Last edited by RoCk; 09/12/07 07:42 PM.
RoCk #191485 09/12/07 07:42 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Quote:
Desired by whom?

By the scripter.

Quote:
Well no that's no alternative, because then the file would be overwritten if it exists. I'm just saying the two should be consistent, the -o switch opens the file whether or not the file exists (overwriting IF it does exist), the -n switch behavior should be the same, open the file whether or not it exists (creating a new file IF it doesn't exist).

If the -o switch behavior were consistent with the -n switch behavior, then it would create the file (overwriting IF it exists) and then fail, like the -n switch creates the file (IF it doesn't exist) and then fails.

I didn't realise that -o actually clears the file on opening. I assumed by "overwriting" it was just making clear that it wasn't in append-mode.

To be honest I'd rather /fopen had (or at least supported as alternative switches) the standard -r[+] -w[+] -a[+] switches available to the C fopen() function.


Spelling mistakes, grammatical errors, and stupid comments are intentional.

Link Copied to Clipboard