Before there was a need to empty open files and then re-write the requirements, but using ftruncate (FD, 0), and did not achieve the effect, but the file head has ' "", the length is larger than expected. The reason is that I did not use Lseek to
truncate ftruncate functionBoth truncate () and ftruncate () can be used to modify the file size, but there are some differences between the two.one, truncate () functionHeader file:#include function definition:int truncate (const char *path, off_t
ftruncate(change file size) define function intftruncate(int fd,off_t length); function descriptionftruncate() changes the file size specified by the parameter fd to the size specified by parameter length. The parameter fd is an open file descriptor
Reprint: http://blog.csdn.net/a_ran/article/details/43562429int truncate (const char *path, off_t length);int ftruncate (int fd, off_t length);Change the file size to the size specified by the parameter length, if the original file size is larger
Today, ftruncate is used to truncate the file, but it cannot achieve the expected results. After the file is truncated, the content is complex and the file size remains unchanged.
After adding fflush () and rewind (), OK.
The following is the test
C language Truncate () function: Change file sizeheader file:
#include
To define a function:
int truncate (const char * path, off_t length);
Function Description: Truncate () changes the file size specified by the
Today with
ftruncateTruncation of the file, but how can not achieve the expected effect, truncated after the contents of the file is miscellaneous, and the file size is kept original.
add fflush () and Rewind () after OK.
Here is the test code:
C code
int ftruncate(int fd, off_t length) int msync(void *addr, size_t len, int flags)
First of all, the man manual inside Ftruncate said that when length is larger than the size of the file itself, will enlarge the file and make up the "", but
Linux inter-process communication (IPC) programming practices (8) use of shared memory-POSIX shared memory (API)
1. Posix provides two methods to share memory areas between unrelated processes:
(1) memory ing file: open the function first, and then
**************************************************************************************************The POSIX semaphore semaphore is a primitive that is used to provide synchronization between different threads of different processes or a given
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.