Can an fdopen() cause a memory leak?

I use fdopen to associate a stream with an open file. When I close() the file, is the stream automatically disassociated as well, and all stream memory returned to the OS, or do I need to be aware...

C fopen vs open

Is there any reason (other than syntactic ones) that you'd want to use FILE *fdopen(int fd, const char *mode); or FILE *fopen(const char *path, const char *mode); instead of int open(const...

How do I insert and delete some characters in the middle of a file?

I want to insert and delete some chars in the middle of a file. fopen() and fdopen() just allow to append at the end. Is there any simple method or existing library that allow these actions?

Program run in child process doesn't loop

I have a specific question regarding the parent process reading the stdout from child. My problem is that when I run the program, the child program should execute a new program multiple times in a...

Is there a Windows equivalent to fdopen for HANDLEs?

In Unix, if you have a file descriptor (e.g. from a socket, pipe, or inherited from your parent process), you can open a buffered I/O FILE* stream on it with fdopen(3). Is there an equivalent on...

Simple http server in C, multiple process not work properly

Solved by adding fseek(file, 0, 0) once finished a repsonse. I am programming a very simple http server, which will reply any GET request with a HTTP response. The response content will be passed...

bind: Address family not supported by protocol

This code works on my other vps, but with linode it doesn't. #include <sys/types.h> #include <sys/socket.h> #include <sys/wait.h> #include <netinet/in.h> #include <stdio.h> #include...

How to properly pass an asset FileDescriptor to FFmpeg using JNI in Android

I'm trying to retrieve metadata in Android using FFmpeg, JNI and a Java FileDescriptor and it isn't' working. I know FFmpeg supports the pipe protocol so I'm trying to emmulate: "cat test.mp3 |...

Cannot mimic the action of `echo` command in C code

I have written a couple of bash script files that communicate via two serial ports. One script can be thought of as a receiver and the other as a transmitter. The receiving script reads and...

What does this nefarious program do?

My server got hacked, and ps aux shows that it's running this program now: perl -MIO -e $p=fork;exit,if($p);$c=new IO::Socket::INET...

How to use C++ for transmitting data using xbee?

For a project i need to establish 2 way xbee communication. But I have a problem sending data from my pc. I use cpp with termios to transmitt a char array but on the xbee tx pin I do only get a...

'str' object is not callable error while trying to create threads and set up a pipe between them

I am trying to create two threads and set up a pipe to communicate between the threads. It is giving an error: 'TypeError: 'str' object is not callable' I saw that the most common problem was that...

stdio fatal error : '_ctermid.h' file not found

include<stdio.h> and when i used gcc to complie , this came out : /usr/local/include/stdio.h:205:10: fatal error: '_ctermid.h' file not found Something went wrong today . It used to complie a...

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...

Use pipe() and fdopen() to pass data from Python script to C++ application in Windows

We have some Linux/macOS application, which can communicate with outer world by passing file descriptor and reading data from it. Usually this is done to pass stdin/stdout descriptors, however we...

Why the child process won't execute in this code?

The child process is skiped, idk why... I used debugger and it doesn't give any clues why...only runs trhough the code ending with the printf of the parent process... Thanks in advance. Don't know...

Android - accessing files in native C/C++ code with Google Scoped Storage API

I need to open files by file name in Android apps within native C/C++ code. The native code are 3rd party libraries that I would prefer not to modify, but they often require file name as an...

Double echo when running commands under a pty

I'm writing a program to create a pty, then fork and execute an ssh command with the slave side of the pty as its stdin. The full source code is here. using namespace std; #include...

STDIN, STDOUT redirection with printf scanf hangs

Can anyone find out why this code hang at fgets() for parent and scanf() for child? If I turn child process's printf/scanf into write/read it doesn't hang. Can any one give a reason to this...

Creating dynamically a file name in C

I'm working on a client, server project. I receive a response from the server where I have to create two files. The first file is a .html file and the second file is .png file. I parse the...

How to interrupt getchar in second thread with SIGINT

I need to handle SIGINT in my console application, I found many examples about sa_flags = 0; of sigaction structure - and it's mean getchar will be aborted and return -1. But this is not working...

Python: how to write to fd 3?

in C, I can write to file descriptor 3 like this: $ cat write.c #include <unistd.h> int main(void) { write(3, "written in fd 3\n", 16); } Then I can call the program and redirect fd 3 to fd 1...

Correct way of using fdopen

I mean to associate a file descriptor with a file pointer and use that for writing. I put together program io.cc below: int main() { ssize_t nbytes; const int fd = 3; char c[100] =...

Is there any way to safely and successfully write to a hand-picked file descriptor number, other than FD=0,1,2?

My overall objective (motivation for the question): To provide an executable ìo, from C/C++ compilation/linking, so that a user can execute it alternatively as: io 3> myout.txt. In this case...

How to get the mode of a file descriptor?

I mean to use fdopen FILE *fdopen(int fd, const char *mode); In man pages, it is stated that "The mode of the stream (one of the values "r", "r+", "w", "w+", "a", "a+") must be compatible with...

Can't read from a pipe after dup2() and fork. C

I'm writing a code that echo a string and sed it two times. My output is correct, but when I try to place that string on an array it blocks on read and goes on with the other calls. Here's the...

Can't include googletest inside cmake script

i try to create some small project on windows, but when i try to build this with cmake there are many errors occured. On linux this build up successfully. When i create dummy project with CMake...

Partially overwriting the contents of a file descriptor

I am trying to create a file, and later partially overwrite the contents. The following program captures the gist of what I am trying to do #include <sys/stat.h> #include <fcntl.h> #include...

How to delete a file in C using a file-descriptor?

In my code, I create a file with a random name using mkstemp() function (Im on Linux). What this function returns is an int being a file descriptor. int fd; char temp[] = "tempXXXXXX"; fd =...

What can you do with a pty?

Having read various resources including http://www.linusakesson.net/programming/tty/ I am still confused and curious about the structure and use of pseudo-terminals In a linux terminal (bash not...

Relevant tags