Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Stwórz plik tekstowy wielkości 512 bajtów, z „dziurą” w środku.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #define PATHNAME "02_file"
- #define FILESIZE 512
- int main(void)
- {
- int fd;
- struct stat stat_buffer;
- if((fd = open(PATHNAME, O_CREAT | O_TRUNC | O_WRONLY, 0600)) == -1) {
- perror("open");
- return EXIT_FAILURE;
- }
- if(lseek(fd, FILESIZE-1, SEEK_SET) == -1) {
- perror("lseek");
- return EXIT_FAILURE;
- }
- if(write(fd, "", 1) == -1) {
- perror("write");
- return EXIT_FAILURE;
- }
- if(stat(PATHNAME, &stat_buffer) == -1) {
- perror("stat");
- return EXIT_FAILURE;
- }
- printf("Utworzono plik o: %ld B, zajmuje %ld sektorow\n", (long)stat_buffer.st_size, (long)stat_buffer.st_blocks);
- if(close(fd) == -1) {
- perror("close");
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment