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

  • Home
  • SEARCH
  • 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 7908251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:51:11+00:00 2026-06-03T11:51:11+00:00

I have a simple task to accomplish with this routine where, all it has

  • 0

I have a simple task to accomplish with this routine where, all it has to do is, open the file, append data from a buffer & close.
I am using ‘open’ & ‘write’ for that purpose on a linux machine. Although the return code after ‘write()’ is positive, the file size does not increase and it is always empty. I ma pulling my hair to figure out what the issue with the below code. Thought some fresh eyes can shed some light.

#define BIT_Q_FILE  ".\\bitq.dat"

int BQWrite(void *p)
{
int fd ;
int rc = -1 ;

fd = open(BIT_Q_FILE, O_RDWR | O_APPEND ) ;

if (fd < 0)
    return -1;


memset(&BITQBuff,0,sizeof(typeBITQFile));
memcpy(&BITQBuff.pBitQueue,p,sizeof(typeBITQueue));

rc = write(fd, &BITQBuff,sizeof(typeBITQFile)) ;

close(fd) ;

if(rc!=sizeof(typeBITQFile))
{
    return -1;
}

rc = sizeof(typeBITQueue);

return rc ;
}
  • 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-03T11:51:13+00:00Added an answer on June 3, 2026 at 11:51 am

    I got your problem right here:

    #define BIT_Q_FILE  ".\\bitq.dat"
    

    You’ve hit a trifecta of Windows-to-Unix porting gotchas:

    • The directory separator on Unix is /, not \.
    • But Unix is perfectly happy to let you put \ in the middle of a file name. (The only bytes — and I really mean bytes, not characters — that cannot appear in a pathname component are those with the values 0x2F and 0x00.)
    • Unix is also perfectly happy to let a file name begin with a dot; however, by default ls does not print any file names that begin with a dot.

    So you are expecting data to be written to a file named bitq.dat in the current directory, but it is actually being written to a file named .\bitq.dat, still in the current directory. That file is hidden by default, so it looks like the data is disappearing into thin air. ls -a will reveal the hidden file, and rm .\\bitq.dat will delete it. To fix your code, just change the define to

    #define BIT_Q_FILE "bitq.dat"
    

    It is not necessary to put a leading ./ on the path passed to open.

    This may not be the only problem with your code, but I don’t see anything else obviously wrong. If you need more help, please post a new question with a complete, minimal test program that people can compile and run for themselves.

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

Sidebar

Related Questions

I have a rather simple task, retrieving an image file from a virtual folder
I know zero javascript, and have one simple task: Find all text in the
I have no idea how to do this simple task. LightSwitch's Solution Explorer is
So my task may sound simple, but it has me boggled. I have looked
I have a simple task to accomplish, but I am not sure what is
I have a simple rake task which consumes pretty much data via ActiveRecord. (contacts
I have a simple task. I have an existing project with a web service
I have a simple task that I can't find a solution for, and I'm
I have simple WPF layout task and looking to avoid code-behind if possible. I
I have a very simple task: add the contents of a textField to an

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.