c++ - Map char pointer to in-memory file with file descriptor -


I try to map a four * with in-memory FILE * with fmemopen I just found out that Phamopen will not give me a file descriptor, is there any way to get an in-memory file with FD?

Four * Data = ... Data ...; FILE * fid = fmemopen (data, 172, "r"); Int fd = fileno (fid); If (FD & lt; 0) std :: cout & lt; & Lt; "BAD" & lt; & Lt; Std :: endl; Else std :: cout & lt; & Lt; "Good" & lt; & Lt; Std :: endl;

Take a look and see that in shm_open () What does the combination with fdopen ()

  #include & lt; Stdio.h & gt; # Include & lt; Sys / mman.h & gt; # Include & lt; Sys / stat.h & gt; # Include & lt; Fcntl.h & gt; Int main () {FILE * f = NULL; Int fd = 0, n = 0; Four buffer [6] = "hello"; Fd = shm_open ("myfile", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); If (FD & lt; 0) {printf ("failed in shm_open \ n"); Exit (1); } F = fdopen (fd, "w +"); If (! F) {printf ("Failed to do FDOpin \ n"); Exit (1); } N = fwrite (buffer, size), size (buffer), f); Printf ("write% d bytes", n); Fclose (f); }  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -