Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

ftruncate(3) [php man page]

FTRUNCATE(3)								 1							      FTRUNCATE(3)

ftruncate - Truncates a file to a given length

SYNOPSIS
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 pointer

SYNOPSIS
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)
Man Page

14 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to remove FIRST Line of huge text file on Solaris

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)
Discussion started by: madoatz
5 Replies

2. Programming

How to delete N bytes from the starting of the file from a C function???

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)
Discussion started by: jockey007
2 Replies

3. UNIX for Advanced & Expert Users

Shared Memory (Posix)

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)
Discussion started by: pretty
3 Replies

4. UNIX for Dummies Questions & Answers

Write/Read in Shared memory

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)
Discussion started by: tyron
1 Replies

5. Programming

Semaphore

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)
Discussion started by: italian_boy
2 Replies

6. UNIX for Dummies Questions & Answers

mmap()

how to use mmap() to map a file to memory space. Do you have any simple program???? Because I have to implement lot of concepts into it. (3 Replies)
Discussion started by: gokult
3 Replies

7. Filesystems, Disks and Memory

How does memory mapping work?

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)
Discussion started by: theKbStockpiler
4 Replies

8. UNIX for Advanced & Expert Users

Linux Page Sharing

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)
Discussion started by: kumaran_5555
4 Replies

9. Programming

Shared memory between two c program

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)
Discussion started by: tafazzi87
21 Replies

10. Shell Programming and Scripting

Create a program illustrating SUID

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)
Discussion started by: ravisingh
15 Replies

11. Red Hat

File system is full ..even though file is deleted

file system is full ..even though file is deleted? (11 Replies)
Discussion started by: rajeshz
11 Replies

12. Ubuntu

Logging samba share in Ubuntu 12.04 LTS

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)
Discussion started by: Akshay Hegde
0 Replies

13. UNIX for Dummies Questions & Answers

Cut a File

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)
Discussion started by: kuTgo
4 Replies

14. UNIX for Beginners Questions & Answers

Remove or truncate trailing nulls from file

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)
Discussion started by: Tribe
9 Replies