lkml.org 
[lkml]   [1998]   [Aug]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Out of ptys

Alan,
This shows the problem I reported to the glibc folks about a year
go. Note that both functions, good() and bad(), are identical except
for the fds that I close.


#include <stdio.h>
#include <unistd.h>

void bad()
{
int i;
close(STDOUT_FILENO);
i = fprintf(stdout, "Hello world!\n");
if(i > 0)
fprintf(stderr, "Bad! %d bytes copied to (closed) stdout...\n", i);
else
fprintf(stderr, "Good! (%d)\n", i);
}

void good()
{
int i;
close(STDERR_FILENO);
i = fprintf(stderr, "Hello world!\n");
if(i > 0)
fprintf(stdout, "Bad! %d bytes copied to (closed) stderr...\n", i);
else
fprintf(stdout, "Good! (%d)\n", i);
}

int main(int argc, char *argv[])
{
int ch;

if(argc > 1)
{
ch = (int) *argv[1];
ch &=95;
switch(ch)
{
case 'G':
good();
break;
case 'B':
bad();
break;
default:
fprintf(stderr, "Huh (%c) ??\n", ch);
break;
}
}
else
fprintf(stderr, "Usage: %s [Good/Bad]\n", argv[0]);
return 0;
}


Cheers,
Dick Johnson
***** FILE SYSTEM WAS MODIFIED *****
Penguin : Linux version 2.1.115 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html

\
 
 \ /
  Last update: 2005-03-22 13:44    [W:0.278 / U:0.388 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site