Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: on April 06, 2003, 10:48:59 AM

Title: /dev/null
Post by: on April 06, 2003, 10:48:59 AM
I guess there is no "/dev/null" on Amiga using libnix or ixemul so what do I use instead if I want to open a "null" file, that is no file at all with fopen("dev/null",method) ?
Title: Re: /dev/null
Post by: Kronos on April 06, 2003, 10:55:46 AM
"fopen("Nil:",method);" should have the same effect (untested).
Title: Re: /dev/null
Post by: xeron on April 06, 2003, 01:37:50 PM
why on earth would you want to do that?
Title: Re: /dev/null
Post by: Karlos on April 06, 2003, 01:47:46 PM
Redicection of stderr maybe?
Title: Re: /dev/null
Post by: xaccrocheur on April 06, 2003, 01:59:54 PM
W ? You mean creating an empty file, like "#touch file" ?
Title: Re: /dev/null
Post by: on April 06, 2003, 10:03:54 PM
This is why. I asked how to avoid fdopen() in another forum:

----
>> I need to replace some fdopen with something else or link with some library
>> that contains fdopen. I'm running a crosscompiler on Amiga for PPC and I
>> can't emulate fdopen.
>> Anyone have an idea how I can solve it?
MR> Try using fopen on another file and then replacing the fd in the structure
MR> before any I/O on the file. Not actually legal, but may work if you're
MR> desperate.
Another method: do fopen() of devnull, ask fileno() and call dup2().
It requires fileno() which isn't standard C function, but doesn't require
knowledge of struct FILE internals.
------



FILE* fdopen( int fd, const char* method ) {
  FILE* f = fopen( "/dev/null", method );
  int d, se;
  if( !f )  return NULL;
  d = fileno(f);
  if( dup2( fd, d ) < 0 ) { se = errno; fclose(f); errno = se; return NULL; }
  return f;
}




Title: Re: /dev/null
Post by: on April 06, 2003, 10:07:39 PM
>Redicection of stderr maybe?


Memory is short.. :)
Title: Re: /dev/null
Post by: Karlos on April 06, 2003, 11:30:38 PM
Quote

JoJo wrote:
>Redicection of stderr maybe?
Memory is short.. :)


Not half! Too much stuff competing for my immediate attention this weekend...

In the end I got next to nothing done anyway!

-edit-

You post this before or after you sent me the pmail with the fdopen() replacement?