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 8715131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:46:32+00:00 2026-06-13T05:46:32+00:00

Possible Duplicate: C write in the middle of a binary file without overwriting any

  • 0

Possible Duplicate:
C write in the middle of a binary file without overwriting any existing content

I am writing a program that occasionally needs to insert 1-64k of data at the beginning of a binary file. The POSIX API / Linux ABI does not have an insert(fd,buf,len) function call. What’s the most efficient way to do this?

  • 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-13T05:46:33+00:00Added an answer on June 13, 2026 at 5:46 am

    Your choices are:

    1. Create a new file, write the new data and copy the old data to the new file, then replace (the contents of) the old file with the new file.
    2. Read a block from the end of the file, write the block to its new position, repeatedly, working your way backwards through the file.

    The advantage of (2) is that it doesn’t break symlinks or multiple links to the original file. The disadvantage (as noted by Keith Thompson) is that if it is interrupted, you’ve lost your original file.

    The disadvantage of (1) is that if you need to preserve numbers of links and work through symlinks, you have to copy the new file back over the old file, so there’s more copying. The advantage is that the copying is simpler and the original file is not destroyed until the end.

    There’s another question with code for option (2) — Write in the middle of a binary file without overwriting any existing content. Inserting at the start of a (binary) file is just a specific (not even special) case of inserting in the middle of a file.

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

Sidebar

Related Questions

Possible Duplicate: Writing C# Plugin System Is it possible to write a program that
Possible Duplicate: Best Way to Write Bytes in the Middle of a File in
Possible Duplicate: How to write content on a text file using java? Is it
Possible Duplicate: Is it possible to write good and understandable code without any comments?
Possible Duplicate: using bash: write bit representation of integer to file I need to
Possible Duplicate: Why split the <script> tag when writing it with document.write()? Browsing through
Possible Duplicate: Write a function that returns the longest palindrome in a given string
Possible Duplicate: How can I write a Java application that can update itself at
Possible Duplicate: Allow access permission to write in Program Files of Windows 7 okay,
Possible Duplicate: Java \ Pattern - how to write a pattern that verifies the

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.