This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "apue.h" | |
| #include <fcntl.h> | |
| #include <string.h> | |
| char buf1[] = "abcdefghij"; | |
| char buf2[] = "ABCDEFGHIJ"; | |
| int main() | |
| { | |
| int fd = open("file.hole", O_WRONLY | O_CREAT | O_TRUNC, FILE_MODE); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "apue.h" | |
| #define BUFFSIZE 4096 | |
| int main() | |
| { | |
| int n; | |
| char buf[BUFFSIZE]; | |
| while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "apue.h" | |
| #include <fcntl.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| int val; | |
| if(argc != 2) | |
| { | |
| err_quit("usage: %s <filedescriptor>", argv[0]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Write your own dup2 function that performs the same service as the dup2 function described in Section 3.12, | |
| * without calling the fcntl function. Be sure to handle errors correctly. | |
| */ | |
| /* TODO */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "apue.h" | |
| int main(int argc, char *argv[]) | |
| { | |
| int i; | |
| struct stat buf; | |
| char *ptr; | |
| for (i = 1; i < argc; i++) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "apue.h" | |
| #include <fcntl.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| if (argc != 2) | |
| { | |
| err_quit("usage: %s <pathname>", argv[0]); | |
| } | |
| if (access(argv[1], R_OK) < 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <fcntl.h> | |
| #define RWXRWXRWX (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH) | |
| int main(void) | |
| { | |
| int old_umask = umask(0); | |
| printf("old_umask %o\n", old_umask); | |
| if (creat("foo", RWXRWXRWX) < 0) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "apue.h" | |
| int main() | |
| { | |
| struct stat statbuf; | |
| if (stat("foo", &statbuf) < 0) | |
| { | |
| err_sys("stat err for foo"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "apue.h" | |
| #include <fcntl.h> | |
| int main(void) | |
| { | |
| if (open("tmpfile", O_RDWR) < 0) | |
| { | |
| err_sys("open error"); | |
| } | |
| if (unlink("tmpfile") < 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "apue.h" | |
| #include <fcntl.h> | |
| #include <utime.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| int i; | |
| int fd; | |
| struct stat statbuf; | |
| struct utimbuf timebuf; |