FTRUNCATE(3) 1 FTRUNCATE(3)ftruncate - Truncates a file to a given lengthSYNOPSIS
bool ftruncate (resource $handle, int $size)
DESCRIPTION
Takes the filepointer, $handle, and truncates the file to length, $size.
PARAMETERS
o $handle
- The file pointer.
Note
The $handle must be open for writing.
o $size
- The size to truncate to.
Note
If $size is larger than the file then the file is extended with null bytes.
If $size is smaller than the file then the file is truncated to that size.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
EXAMPLES
Example #1
File truncation example
<?php
$filename = 'lorem_ipsum.txt';
$handle = fopen($filename, 'r+');
ftruncate($handle, rand(1, filesize($filename)));
rewind($handle);
echo fread($handle, filesize($filename));
fclose($handle);
?>
NOTES
Note
The file pointer is not changed.
SEE ALSO fopen(3), fseek(3).
PHP Documentation Group FTRUNCATE(3)
Check Out this Related Man Page
REWIND(3) 1 REWIND(3)rewind - Rewind the position of a file pointerSYNOPSIS
bool rewind (resource $handle)
DESCRIPTION
Sets the file position indicator for $handle to the beginning of the file stream.
Note
If you have opened the file in append ("a" or "a+") mode, any data you write to the file will always be appended, regardless of the
file position.
PARAMETERS
o $handle
- The file pointer must be valid, and must point to a file successfully opened by fopen(3).
RETURN VALUES
Returns TRUE on success or FALSE on failure.
EXAMPLES
Example #1
rewind(3) overwriting example
<?php
$handle = fopen('output.txt', 'r+');
fwrite($handle, 'Really long sentence.');
rewind($handle);
fwrite($handle, 'Foo');
rewind($handle);
echo fread($handle, filesize('output.txt'));
fclose($handle);
?>
The above example will output something similar to:
Foolly long sentence.
SEE ALSO fread(3), fseek(3), ftell(3), fwrite(3).
PHP Documentation Group REWIND(3)
i need help..!!!!
i have one big text file estimate data file size 50 - 100GB with 70 Mega Rows.
on OS SUN Solaris version 8
How i can remove first line of the text file.
Please suggest me for solutions.
Thank you very much in advance:) (5 Replies)
Hi,
I want to delete the initial few lines (or even bytes) from a file.
I want to do this from a C function & this is in Linux platform.
The truncate & ftruncate is allowing me to delete bytes from the end only.
Any linux C function calls or ideas or any suggestions??
I'm in a dead... (2 Replies)
hi
I had to create a shared memory segment which allows the creation of 8 child processes each with 1024 bytes and contains a common buffer area of 2096bytes.
i was able to create the shared memory with shm_open() followed by ftruncate() and mmap() system calls.
but for the shared buffer, i... (3 Replies)
I have created and attached a shared memory segment. However I do not know how am I supposed to write and read data from it. I want to save various different data on this segment such as process IDs and other. Do you know how am I supposed to write these and be able to read such data in the correct... (1 Reply)
In my server code there is a thread per client...
The server call accept() and after that start the thread.
So there is a thread for client that save in RAM the client's message, that will be send to other clients.
Now in RAM I have created a shared memory in which thread read and write(save)... (2 Replies)
I can't find a guide or tutorial that explains it at all. Its there a better search term than Memory Mapping? What's the magic inbetween having the hard drive behave like the memory? (4 Replies)
Hi,
I have following doubts regarding page sharing in Linux (please also correct me if any of my assumptions are wrong),
1. In recent kernel KSM does the page sharing for user process' anonymous pages.
2. What about pages where the program text is stored ? are they shared between two... (4 Replies)
i have to shared a variable between two different c programs with shared memory and i do these:
int main() {
int a=5,b=7;
int buffer;
int *point;
int shmid;
shmid=shmget(IPC_PRIVATE , sizeof(buffer),0666);
point=(int *)shmat(shmid,NULL,0);
point=a;
... (21 Replies)
To understand SUID feature, I set SUID bit for a SHELL script.
Then I executed the program by a different user.
In order to understand how it works, I tried different ways like:
1) I didn't give execute permission for the other user (not an owner) and then he tried to execute it.
2) I... (15 Replies)
Hi guys
I am trying to log full_audit on my samba shares so I know who is creating, deleting, renaming, moving etc. files and directories in the samba/windows share.
In my etc/samba/smb.conf file, under I have:
# Audit settings
full_audit: prefix = %u|%I|%S
full_audit:failure =... (0 Replies)
Hi, i need cut a file.
i have a file lenght 100. i need cut it to 75 lenght.
when cut should not use any auxiliary file for space
how can i do it:confused:. thanks for help!:b: (4 Replies)
I want to remove from a file the trailing null characters (0x00) and stop doing so when a different byte is found (which should not be deleted), and either put the result to the same file or a different one.
Any ideas? (9 Replies)