08-13-2008
I checked the fwrite both in Linux and UNIX, the number of items written is the same in both .
Regards
rkraj
10 More Discussions You Might Find Interesting
1. Programming
After my previous thread, I think I found out what causes the long delays.
I run this program on several Linux computers, and the sometimes (after the file with the arrays becomes big) the fwrite takes between 100 ms to 900 ms.
This is very bad for me, as I want a timer to halt each 30 ms.... ... (5 Replies)
Discussion started by: inna
5 Replies
2. Programming
Hi ,
I am running a C/C++ program on a solaris 5.8 machine. This parituclar application has a module which saves data to a file. The module uses fwrite() function to save data.
The fwrite function write about 500 MB of data to a file. The problem which I am facing is, the memory consumtion... (2 Replies)
Discussion started by: ajphaj
2 Replies
3. Programming
Code : function sSaveTFFile
.......................
iRetCode = link (caCurrentFilename, caBackupFilename);
if (iRetCode == -1)
{
ERR_MSG2(LOG_ALERT, "Can't move %s to %s", caCurrentFilename, caBackupFilename);
return(FAILURE);
}
iRetCode = unlink... (6 Replies)
Discussion started by: fermisoft
6 Replies
4. Programming
Hi,
my code is written in proC and it is in UNIX(AIX).I have written a small code for writing data into a binary file,but while writing my program is giving core dump.
Here Is my code----
fpWriteFile = fopen(WriteFileName,"wb+");
CHAR *recvgen;
recvgen = (char... (7 Replies)
Discussion started by: ajaysahoo
7 Replies
5. Programming
Hello,
I have a question about what happens when I copy the file which is being written by another process on Solaris 9/SPARC, UFS file system.
in particular, I want to know what happens while some process is reading the file using fread or mmap, another process try to write something on the... (4 Replies)
Discussion started by: wipe3out
4 Replies
6. Programming
The fwrite function call is not returning error, when the file it writes to is removed, please advise on how to find if the file already opened and being written by a program is removed manually or by some other process.
please see the code below,
#include<stdio.h>
#include<stdlib.h>
... (3 Replies)
Discussion started by: Kesavan
3 Replies
7. Fedora
I just started a new semester and I started my UNIX class yesterday. I've already decided to use python along with my learning process but what I really want to use with it is Kali as my UNIX/Linux platform to learn off of since I already wanted to learn Cyber Sec. anyways. I just wanted to know if... (12 Replies)
Discussion started by: ApacheOmega
12 Replies
8. UNIX for Dummies Questions & Answers
I have some matlab code that sends the serial port elements of an array using matlab's fwrite function, e.g.:
fwrite(s, , 'uchar');
What would be a unix shell equivalent? E.g., after successfully accessing the port using instructions here:
Simple terminal serial port program for Linux/MacOSX... (3 Replies)
Discussion started by: darwin_886
3 Replies
9. Post Here to Contact Site Administrators and Moderators
We work hard to make The UNIX and Linux Forums one of the best UNIX and Linux knowledge sources on the net. The site is certainly one of the top UNIX and Linux Q&A sites on the web. In order to provide certain members the best quality account services, you can now get some great extra features by... (2 Replies)
Discussion started by: Neo
2 Replies
10. What is on Your Mind?
Forum Moderation @UNIX.com | The UNIX and Linux Forums
https://youtu.be/WGwgibE4Rq0
Also note: In the video I mentioned removing legacy menu items in the ModCP which are unused. I have already "CSS'ed out" the unused menu items:
... (0 Replies)
Discussion started by: Neo
0 Replies
FWRITE(3) 1 FWRITE(3)
fwrite - Binary-safe file write
SYNOPSIS
int fwrite (resource $handle, string $string, [int $length])
DESCRIPTION
fwrite(3) writes the contents of $string to the file stream pointed to by $handle.
PARAMETERS
o $handle
-A file system pointer resource that is typically created using fopen(3).
o $string
- The string that is to be written.
o $length
- If the $length argument is given, writing will stop after $length bytes have been written or the end of $string is reached,
whichever comes first. Note that if the $length argument is given, then the magic_quotes_runtime configuration option will be
ignored and no slashes will be stripped from $string.
RETURN VALUES
fwrite(3) returns the number of bytes written, or FALSE on error.
NOTES
Note
Writing to a network stream may end before the whole string is written. Return value of fwrite(3) may be checked:
<?php
function fwrite_stream($fp, $string) {
for ($written = 0; $written < strlen($string); $written += $fwrite) {
$fwrite = fwrite($fp, substr($string, $written));
if ($fwrite === false) {
return $written;
}
}
return $written;
}
?>
Note
On systems which differentiate between binary and text files (i.e. Windows) the file must be opened with 'b' included in fopen(3)
mode parameter.
Note
If $handle was fopen(3)ed in append mode, fwrite(3)s are atomic (unless the size of $string exceeds the filesystem's block size, on
some platforms, and as long as the file is on a local filesystem). That is, there is no need to flock(3) a resource before calling
fwrite(3); all of the data will be written without interruption.
Note
If writing twice to the file pointer, then the data will be appended to the end of the file content:
<?php
$fp = fopen('data.txt', 'w');
fwrite($fp, '1');
fwrite($fp, '23');
fclose($fp);
// the content of 'data.txt' is now 123 and not 23!
?>
EXAMPLES
Example #1
A simple fwrite(3) example
<?php
$filename = 'test.txt';
$somecontent = "Add this to the file
";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
SEE ALSO
fread(3), fopen(3), fsockopen(3), popen(3), file_get_contents(3).
PHP Documentation Group FWRITE(3)