Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <unistd.h>
- int main(int argc, char const *argv[])
- {
- if (argc != 3 && argc != 4) {
- fprintf(stderr, "%s\n", "wrong arguments");
- return 1;
- }
- if (argc == 3) {
- fprintf(stderr, "%s\n", "with append");
- int fd = open(argv[1], O_WRONLY | O_CREAT | O_APPEND);
- if (fd == -1) {
- fprintf(stderr, "%s\n", "error while opening");
- return 1;
- }
- int num_bytes = atoi(argv[2]);
- for (int i = 0; i < num_bytes; ++i) {
- write(fd, "0", 1);
- }
- close(fd);
- } else {
- fprintf(stderr, "%s\n", "without append");
- int fd = open(argv[1], O_WRONLY | O_CREAT);
- int num_bytes = atoi(argv[2]);
- if (fd == -1) {
- fprintf(stderr, "%s\n", "error while opening");
- return 1;
- }
- for (int i = 0; i < num_bytes; ++i) {
- lseek(fd, 0, SEEK_END);
- write(fd, "0", 1);
- }
- close(fd);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement