[BusyBox] More on bb_xfopen vs bb_wfopen

Tito farmatito at tiscali.it
Mon Sep 29 13:09:12 UTC 2003


Hi  to all,

FILE *bb_xfopen(const char *path, const char *mode)
{
	FILE *fp;
	if ((fp = fopen(path, mode)) == NULL)
		bb_perror_msg_and_die("%s", path);
	return fp;
}

FILE *bb_wfopen(const char *path, const char *mode)
{
	FILE *fp;
	if ((fp = fopen(path, mode)) == NULL) {
		bb_perror_msg("%s", path);
		errno = 0;
	}
	return fp;
}

seems to me the major diff is in the bb_error_msg_and_die call.
Maybe they could be unified as:

FILE *bb_xwfopen(int die, const char *path, const char *mode)
{
	FILE *fp;
	if ((fp = fopen(path, mode)) == NULL)
	{
		bb_perror_msg("%s", path);
		errno = 0;
		if(die==1)
			exit(EXIT_FAILURE)	
	}
	return fp;
}


BTW: the same patch could be applied to most of the bb_x* functions
(think about  how to write a port scanner with  xconnect etc.)
as they would be useful also in situations when you want the 
program to issue a warning but no to die.


........I know this would make necessary a major rewrote of all bb applets. :-P
........was just an idea.

Ciao
Tito




More information about the busybox mailing list