I have this code with close(2) implemented, as many of you know(including myself) this closes the standard error, but what are the main repercussions of closing it?
And why is "main: Success" printed? Shouldn't every directory have the "." dir that can be opened?
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
int main() {
close(2);
if (fopen(".","r"))
{
printf("main: %s \n", strerror(errno));
}
return 0;
}
On the other hand
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int main() {
close(2);
if (fopen(".","r"))
{
perror("main");
}
return 0;
}
This doesn't print anything, any ideas why?