Questions tagged [fdopen]

28 questions
61
votes
6 answers

Python - How do I convert "an OS-level handle to an open file" to a file object?

tempfile.mkstemp() returns: a tuple containing an OS-level handle to an open file (as would be returned by os.open()) and the absolute pathname of that file, in that order. How do I convert that OS-level handle to a file object? The documentation…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
6
votes
1 answer

Python get file path from a file descriptor int (as returned from os.open)

I am using fusepy and I need to convert a file descriptor back in to a file object so that I can obtain the original file path From the fusepy examples, when a file is created, a file descriptor is returned - for example: def open(self, path,…
dryliketoast
  • 153
  • 1
  • 7
6
votes
1 answer

Capturing data being written to open file descriptor

Is it possible to write a program that's able to take another application's open file descriptors and just pass along their contents without any conversion? Let's say App A has an open FD to some file on disk that it's writing data to. I'd like to…
user1610950
  • 1,837
  • 5
  • 33
  • 49
6
votes
3 answers

How to fdopen as open with the same mode and flags?

I would like to have a FILE* type to use fprintf. I need to use fdopen to get a FILE* instead of open that returns an int. But can we do the same with fdopen and open? (I never used fdopen) I would like to do a fdopen that does the same as…
Elfayer
  • 4,411
  • 9
  • 46
  • 76
6
votes
4 answers

"Illegal seek" error when working with socket streams with non-empty read buffers

I'm currently writing a server application on Linux x86_64 using . After accepting a connection via accept(), I use fdopen() to wrap the retrieved socket into a FILE* stream. Writing to, and reading from, that FILE* stream usually…
mic_e
  • 5,594
  • 4
  • 34
  • 49
5
votes
2 answers

Python: how to write to fd 3?

in C, I can write to file descriptor 3 like this: $ cat write.c #include int main(void) { write(3, "written in fd 3\n", 16); } Then I can call the program and redirect fd 3 to fd 1 (stdin) like this: $ ./write 3>&1 written in fd…
Adriano_Pinaffo
  • 1,429
  • 4
  • 23
  • 46
5
votes
2 answers

Create a file descriptor

I want to create a file descriptor in C whose value i will specify in code. I have a integer variable which specifies the value of file descriptor to be created. For example i may need a file descriptor whose value is 5 and later associate that with…
mukesh
  • 726
  • 1
  • 11
  • 27
5
votes
2 answers

calling fdopen: Bad file descriptor

I'm getting the following error when trying to compile my program: calling fdopen: Bad file descriptor I've read this might be a problem related to including a precompiled header in one of my header files. The file which is causing the error…
LandonSchropp
  • 10,084
  • 22
  • 86
  • 149
4
votes
2 answers

How to open file object from 'os' using 'with'?

I'm trying to open file using 'os.open()' as below >>> filePath 'C:\\Shashidhar\\text.csv' >>> fd = os.open(filePath,os.O_CREAT) >>> with os.fdopen(fd, 'w') as myfile: ... myfile.write("hello") IOError: [Errno 9] Bad file descriptor >>> Any…
Shashi
  • 199
  • 1
  • 6
  • 19
3
votes
1 answer

How to close a socket() if I used fdopen() on the socket descriptor

If I create a socket sockfd = socket(...); and then I associate it to a FILE stream by calling FILE* f=fdopen(sockfd,"r+"); Should I call both close(sockfd); and fclose(f); or only close(sockfd);? What happens to the FILE structure if I call or…
kanito73
  • 87
  • 4
3
votes
0 answers

Closing a C++ FILE pointer which uses a file descriptor from Java

When using a file descriptor in native code, which has been obtained from a ParcelFileDescriptor, should the native side use fclose after an fdopen? The documentation states that the ParcelaleFileDescriptor instance owns the file descriptor, and it…
PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
3
votes
2 answers

Android lollipop write to sdcard from native code c++

I have android application which uses a lot of c++ native code. Application needs to work with files located on sdcard(read, create, append). But Kitkat+ denied writing to sdcard for 3rd party applications. Android 5 introduced new API which allows…
user1063364
  • 791
  • 6
  • 21
2
votes
1 answer

Bad file descriptor when using fdopen?

I have the folowing C code. The child is used to run test3, whose code will be below. The parent is used to pass the data to the child which will be redirected to STDIN of test3. #include #include #include #include…
Wolfat
  • 85
  • 1
  • 9
2
votes
1 answer

C: close FILE* - not filedescriptor

I wondered if it was possible to release a FILE wrapper, without closing the underlying file descriptor: void stream_function( int fd ) { FILE * stream = fdopen( fd, "r"); // Read from stream with fread / fscanf // then close the…
user422005
  • 1,989
  • 16
  • 34
2
votes
1 answer

Is the fread function blocking?

I have the following code: int buffer_max_size = 1024; char* buffer = new char[buffer_max_size] FILE* cout_file = fdopen(cout_pipe[0], "r"); while (fread( &buffer[0], sizeof(char),sizeof(char)*buffer_max_size, cout_file) != 0 ) {...} cout_file is…
Kam
  • 5,878
  • 10
  • 53
  • 97
1
2