fwrite

End of FILE* pointer is not equal to size of written data.

Very simply put, I have the following code snippet: FILE* test = fopen("C:\\core.u", "w"); printf("Filepointer at: %d\n", ftell(test)); fwrite(data, size, 1, test); printf("Written: %d bytes.\n", size); fseek(test, 0, SEEK_END); printf("Filepointer is now at %d.\n", ftell(test)); fclose(test); and it outputs: Filepointer at: 0 Writte...

Overwite Line in File with PHP

What is the best way to overwrite a specific line in a file? I basically want to search a file for the string '@parsethis' and overwrite the rest of that line with something else. ...

How to make php open a html-file, go two lines up, then write there and close?

I am making a litte php-file to log some ip addresses. It is going to write the ips and date/time into a html-file. The html-file is going to be a table. So I want to mak it like this: <table cellpadding="6" rules="groups" frame="no"> <thead> <tr><th>IP</th><th>Date</th><th>Time</th></tr> </thead> <tbody> <tr><td>192.168.0.1</td><td>3...

C/C++ best way to send a number of bytes to stdout

Profiling my program and the function print is taking a lot of time to perform. How can I send "raw" byte output directly to stdout instead of using fwrite, and making it faster (need to send all 9bytes in the print() at the same time to the stdout) ? void print(){ unsigned char temp[9]; temp[0] = matrix[0][0]; temp[1] = ma...

Writing BMP data getting garbage

I'm working on understanding and drawing my own DLL for PDF417 (2d barcodes). Anyhow, the actual drawing of the file is perfect, and in correct boundaries of 32 bits (as monochrome result). At the time of writing the data, the following is a memory dump as copied from C++ Visual Studio memory dump of the pointer to the bmp buffer. Eac...

2GB limit on file size when using fwrite in C?

Hi, I have a short C program that writes into a file until there is no more space on disk: #include <stdio.h> int main(void) { char c[] = "abcdefghij"; size_t rez; FILE *f = fopen("filldisk.dat", "wb"); while (1) { rez = fwrite(c, 1, sizeof(c), f); if (!rez) break; } fclose(f); return 0; } When I run the progra...

MATLAB FREAD/FWRITE

I want to change the value of a couple of bytes in a large binary file using matlab's fwrite command. What I am trying to do is open the file using fopen(filename,'r+',precision) then read down the file using fread(fid,NUM,'int32') (this all works). Once I get to the file position where I want to write (overwrite) the values of the nex...

PHP - failed write

I am stuck and in need of a hand. Hope someone can help? Anyone have any idea why I am getting "failed write" in this code? $write_file = "/usr/home/public_html/php/users_v2.sql"; $write_handle = fopen($write_file, "w") || die("Couln't open users_v2!"); if (is_writeable($write_file)) { if ($write_handle === FALSE) echo 'Failed ha...

Make cURL write data as it receives it

Hello everybody, I have the following php code which I found here: function download_xml() { $url = 'http://tv.sygko.net/tv.xml'; $ch = curl_init($url); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $data...

Why is fwrite writing more than I tell it to?

FILE *out=fopen64("text.txt","w+"); unsigned int write; char *outbuf=new char[write]; //fill outbuf printf("%i\n",ftello64(out)); fwrite(outbuf,sizeof(char),write,out); printf("%i\n",write); printf("%i\n",ftello64(out)); output: 0 25755 25868 what is going on? write is set to 25755, and I tell fwrite to write that many bytes to a fi...

Add Word document to another Word document with PHP

How can I add a Word document to another Word document with PHP (fwrite)? $filename = "./1.doc"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); $filename2 = "./2.doc"; $handle2 = fopen($filename2, "r"); $contents2 = fread($handle2, filesize($filename2)); $contents3 =$contents2.$contents; $fp = fop...

PHP4 problems with include() within a file created by fwrite()

I have a file called generator.php that uses fwrite() to create a result.php on the server (Apache, PHP4). One of the lines in result.php is a PHP include() statement. So, in generator.php: if (!is_file($fname)){ $resultfile = fopen($current_path . "/" . $fname, "w+"); } fwrite($resultfile, '<?php include($_SERVER["DOCUMENT_ROOT"]...

C++: copying bmp using loop of fread and fwrite, casues output bmp is filled with color of the fisrt one in input bmp

I dunno why, but first pixel (left bottom) is loaded correctly, but the others won't load and the first color is used for whole picture... I have this in cycle fread(&pix,sizeof(pix),1,pictureIn); fwrite(&pix,sizeof(pix),1,pictureOut); edit: pix is struct of three unsigned chars (rgb), loading file and info header seems to be ok ...

Security vulnerabilities in php fwrite?

Hi All, I recently transitioned my companies website over to our in-house servers (Apache) from a hosting companies (IIS). The group that originally built the site did a piss poor job and the entire thing was a mess to migrate. While the move went fairly smoothly, looking at the error_log there are still some missing pages. Rather ...

C program stuck on uninterruptible wait while performing disk I/O on Mac OS X Snow Leopard

Hello all, One line of background: I'm the developer of Redis, a NoSQL database (http://code.google.com/p/redis). One of the new features I'm implementing is Virtual Memory, because Redis takes all the data in memory. Thanks to VM Redis is able to transfer rarely used objects from memory to disk, there are a number of reasons why this w...

writing to log file causes error 704

Hello, Does anyone know what this error means FATAL: Autorisation no longer valid.704 It happens when I try to write to this file, but the permissions are set to 755 and 0644 The temp folder is in the rootfolder of this subdomain. if ($handle = fopen( 'temp/mylog.log'"a+") ) { if( !fwrite( $handle, $json ) ) {...

is_writable() return false

Hi, I'm expecting an issue with the PHP function fwrite() $filename = 'rss.xml'; if (file_exists($filename)) { echo "The file $filename exists"; } if (is_writable($filename)) { $fp = fopen($filename, 'w'); fwrite($fp, $feed); fclose($fp); } else{ echo '<br />not writable..'; if(!is_readable($filename)){ ...

Are files dumped with fwrite portable across different systems?

Can I assume a file generated with fwrite and read using fread is portable across different systems. 32bit/64bit windows,osx,linux. //dumping FILE *of =fopen("dumped.bin","w"); double *var=new double[10]; fwrite(var, sizeof(double), 10,FILE); //reading file *fo=fopen() double *var=new double[10]; fread(var,sizeof(double),10,of); And w...

fwrite with structs containing an array

How do I fwrite a struct containing an array #include <iostream> #include <cstdio> typedef struct { int ref; double* ary; } refAry; void fillit(double *a,int len){ for (int i=0;i<len;i++) a[i]=i; } int main(){ refAry a; a.ref =10; a.ary = new double[10]; fillit(a.ary,10); FILE *of; if(NULL==(of=fopen("test.bin","w"...

Fwrite - is this executed?

Hello all, I have a bunch of fwrites that write to a text file. However, its seem that the new line ("\n") that I want after each row never gets put in since the next set of data is stuck to the last line that this code inserts into the text file: while(odbc_fetch_row($result)){ if($counter==0){ $counter3 = 1; ...