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
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
1. Create/acquire a shared memory#include #include / * for Mode constants */#include / * for O_* Constants */int Shm_open (const char *name, int oflag, mode_t mode);Parameters:Name: Shared memory names; Oflag: With the Open
I wrote a few notes about the blind spots in my C language. I only thought that I had experienced and had errors.
1. implict declartion of function indicates that there is no function declaration during preprocessing, but this function is compiled
The previous section introduced the knowledge about System V shared memory. Now let's take a look at POSIX shared memory and functions.
Shared Memory is simply a real physical memory area. Some functions can be used to map this area to the address
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.