Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8555035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:01:34+00:00 2026-06-11T15:01:34+00:00

I need a cross platform way of treating memory buffer as FILE* . I

  • 0

I need a cross platform way of treating memory buffer as FILE*. I have seen other questions which point out that there is no portable way to do this (fmemopen in linux is what I need but it fails on Windows platform).

I have tried using the setvbuf and it seems to work. Can anyone please point out the exact problem of using setvbuf function?

Also , I have seen the C standard draft WG14/N1256 and 7.19.5.6 says:

the contents of array at any time are indeterminate.

I don’t understand if I use my own buffer how can its contents be indeterminate?

EDIT: Thanks for all the answers. Not using this method anymore.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:01:35+00:00Added an answer on June 11, 2026 at 3:01 pm

    No really, there’s no portable way to do this.

    Using setvbuf may appear to work but you’re really invoking undefined behavior, and it will fail in unexpected ways at unexpected times. The GNU C library does have fmemopen(3) as an extension, as you mentioned, but it’s not portable to non-GNU systems.

    If you’re using some library that requires a FILE* pointer and you only have the required data in memory, you’ll just have to write it out to a temporary file and pass in a handle to that file. Ideally, your library should provide an alternative function that takes a memory pointer instead of a file pointer, but if not, you’re out of luck (and you should complain to the library writer about that deficiency).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me out, I need a cross platform way to detect if
I need a cross-platform library/algorithm that will convert between 32-bit and 16-bit floating point
I need a cross-platform solution for multi-thread to write to a same file concurrently
I need a cross-platform way to get the current working directory (yes, getcwd does
I need to build some cross platform cpp files in my android mk file.
we're building a cross-platform utility which must have a small footprint. We've been pulling
For a script I am making, I need a cross-platform way to check: If
I'm looking for a cross-platform way of making my Python script process a file's
I'm writing a cross-platform game (in C++) called Bombz and I need a way
I need a cross platform way to find a running process by name and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.