Dear developers,
For some reason in my program I need two file handlers of stdout stream.
When I close these handlers I obtain an error on the second close: "Bad
file descriptor"
Here is the simple testcase code:
#include <stdlib.h>
#include <stdio.h>
#include "apr.h"
#include "apr_pools.h"
#include "apr_file_io.h"
int main(int a, char** b)
{
apr_pool_t * pool;
apr_file_t *file1, *file2;
apr_status_t status;
char errbuf[100];
apr_initialize();
apr_pool_create(&pool, NULL);
apr_file_open_stdout(&file1, pool);
apr_file_open_stdout(&file2, pool);
apr_file_puts("Hello World (1)\n", file1);
apr_file_puts("Hello World (2)\n", file2);
status = apr_file_close(file1);
if(status!=APR_SUCCESS) {
apr_strerror(status, errbuf, sizeof(errbuf));
fprintf(stderr, "file1 close error: %s\n", errbuf);
}
status = apr_file_close(file2); // <--- returns non-APR_SUCCESS
if(status!=APR_SUCCESS) {
apr_strerror(status, errbuf, sizeof(errbuf));
fprintf(stderr, "file2 close error: %s\n", errbuf);
}
apr_terminate();
return(0);
}
Could anybody try to reproduce this problem?
If it really exists, should it be fixed in APR or it is my problem to
handle such things?
I use APR 1.3.8
My system is Linux Debian Squeeze, x86_64.
Regards,
Yura Vishnevskiy